here it is - how do i structure my nestjs projects

fiamon

Julio Fiamoncini

Posted on March 14, 2024

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.

💖 💪 🙅 🚩
fiamon
Julio Fiamoncini

Posted on March 14, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related