What is best folder structure for a project that includes:
It all depends on the personal preferences. Make your folder structure the way you are most comfortable working with.
For example, I love my code to be split in submodules or simply said to be in different directories, accordingly to the job the code is used for.
I'd personally go with a couple of folders:
.{src}
├── controllers # All controller operations according the routes are stored here
│ ├── authController.ts # Handles authentication requests
│ ├── usersController.ts # Handles users route requests
│ └── ...
│
├── database # All database connections are stored here. For example you have two databases
│ ├── db.ts # Initialize DB connection
│ └── ...
│
├── middleware
│ ├── authenticated.ts # Decode and verify JWT token
│ ├── error.ts # Common Error Handler
│ ├── logger.ts # Control logging levels
│ └── ...
│
├── models # Simple descriptor of the database tables
│ ├── usersModel.ts # DB model for users
│ └── ...
│
├── schema # Schemas that are used for CRUD operations with the models
│ ├── users.ts # DB Schema for users
│ └── ...
│
├── listeners
│ ├── socketsManager.ts # Socket listeners/emitters handle
│ └── ...
│
├── app.ts # Entry file for the project
├── .env # Store environment variables
├── routes.ts # All routes initializer
└── ...
Although, you might not like the naming or the order I've put on, you can create your own one you feel comfortable with. Another thing you might do is take a look at some conventions that are up on the internet or some of the most popular projects like frameworks.
It's all depending on your needs and what you feel comfortable working with, after all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With