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.
Top comments (2)
Great I will try it in my next project, by the way, which projects most commonly using nestjs right now? I am starting to get into it
NestJS is a good framework, im sure you'll like it. Here is a link to a discussion about who is using nestjs in prod: github.com/nestjs/nest/issues/1006.
Thanks for the comment!