Building project with standardized structure could save much our time. We could focus on business process without considering too much on project structure. On the other hand, a good project structure should be clean, nice refactored, and easy to maintain.
- Your time should be focused on creating something amazing. A project that solves a problem and helps others.
- You shouldn't be doing the same tasks over and over like structuring project
- You should implement dry principles to the rest of your life
This time, I created complete project template for API written in Typescript which is available in this github. Of course, no one template will serve all projects since your needs may be different.
This project structure is built using
- Everything is modular and unit testable
- Typescript everything
- Express API with dependency injected routes, controllers, repositories, middleware, and services
- Centralized configuration loading and validation
- API Documentation using swagger
├── .husky/ # Pre-commit config for lint staged ├── src/ # All application source ├──── @types/ # Type definition | ├──── api/ ├────── controllers/ # Define all controllers ├────── helpers/ # Define all helpers ├────── lib/ ├──────── logger.ts # Define logger ├────── middlewares/ ├──────── authorization.ts # Define authorization using JWT ├──────── morgan.ts # Define morgan ├────── models/ # Define all schema models ├────── repositories/ # Define all repositories ├────── routes/ ├──────── v1/ # Define all v1 routes ├────── services/ # Define all services ├────── validations/ # Define all controller validations | ├──── config/ ├────── swagger/ # Define swagger configuration ├────── database.ts # Define postgres database connection ├────── express.ts # Define express configuration | ├──── constants/ # Define all constants ├──── server.ts # Create express config ├──── index.ts # ENTRYPOINT - Start server | ├── test/ # End-to-end test | └── Lots of random build-related files
See full project here. Let me know if you have any suggestions😄.
Top comments (8)
Clean work. I checked all files one by one :) Thanks for sharing
Highly recommend you look into NestJS for Node/TypeScript API.
Thanks! I'll find it out
did a great job, thanks
(I hope whatever .env code for the JWT is ok to be public.)
Thanks for your suggestion
I think it's would be better if you make an example such as a blog app for it.That will help people understand more details about its applicability