Hey, thanks for reading this article. First, let me introduce myself. You can call me fiamon. I’m a full-stack developer. You can find me on GitHub or LinkedIn.
Motivations
This week, I’ve been thinking about how to structure my NestJS project. After doing a lot of research and asking around, I’ve gathered some valuable insights that I’m eager to share with you. Let’s get started!
Folder structure
Lets go line by line:
+-- src
| +-- @types // here you will put all types you need
| +-- auth // Authentications
| +-- config // Environment Configuration
| +-- common // Global Nest Module
| | +-- constants // Constant value and Enum
| | +-- decorators // Nest Decorators
| | +-- filters // Nest Filters
| | +-- guards // Nest Guards
| | +-- interceptors // Nest Interceptors
| | +-- interfaces // TypeScript Interfaces
| | +-- middleware // Nest Middleware
| | +-- pipes // Nest Pipes
| | +-- providers // Nest Providers
| +-- core // Here you will put all related things with an entity
| | +-- user
| | | +-- dto // User DTO
| | | | +-- user.dto.ts
| | | +-- repository // User repository
| | | +-- user.repository.ts
| | | +-- user.module.ts
| | | +-- user.entity.ts
| | | +-- user.controller.ts
| | | +-- user.service.ts
If you have any doubts, feel free to comment or take a look at this repo for reference
NestJS, much like React or Angular, encourages breaking down your application into modules. This modular approach helps organize your codebase effectively and promotes maintainability and scalability.