DEV Community

Julio Fiamoncini
Julio Fiamoncini

Posted on

here it is - how do i structure my nestjs projects

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

Image description

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


Enter fullscreen mode Exit fullscreen mode

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 (1)

Collapse
 
krlz profile image
krlz

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