This is realisation of pet store api, that I took from Swagger. As I count it takes 762 lines of code in src folder.
I use the next architecture: Pet Store architecture.
As you can see, I have:
In this layer as I planned I can try to change my transfer protocol from http to webscoket, for example. (You never know what customer wants).
Quite simple layer without a lot of logic, just route our requests to controllers. I have separated it to enteties: pet, store, user.
Controller's task is to call service based on our request and answer something to client.
F.E. return data or return info that data was not found etc.
All buisness logic is placed here, here we can process our data, or call another external api service, count something, change our data. Validation is placed on this level.
Model task is not so hard, you just need to take data from storage. It is separated during to entities.
Yes, I have used some middlewares. They are used to mixin our request/responce context with our data. It is good to use for authentication, request parser, session id.
I used:
I remember that we have to store our user's data in secure, so I also hash passwords and store them. If I want to compare passwords, I can't just decrypt it, I can only compare hashed one.
It is good that we can have validation on our frontend part, but it is also cool (you just have to) validate it on out server. I check validation on service layer.
I have separate folder to my project configurations, f.e. Redis Session store, MongoDB configs, I can also place my .env here.
And as you see, I have used next dependencies: