Careeroza
NestJS Architecture
Inspired by Angular and Spring
NestJS borrows ideas from Angular (modules, decorators, dependency injection) and Spring Boot (controllers, services, layered architecture). If you know Spring, NestJS will feel familiar.
| NestJS | Spring Boot equivalent | Job |
|---|---|---|
@Module() | @Configuration / package | Group related code |
@Controller() | @RestController | Handle HTTP requests |
@Injectable() service | @Service | Business logic |
| Repository (TypeORM/Prisma) | JpaRepository | Database access |
| Guard | Spring Security filter | Allow or deny a request |
| Pipe | Bean Validation | Validate and convert input |
The Three Building Blocks
AppModule (root)
/ \
ProductsModule OrdersModule <- modules group features
| \ | \
ProductsController ProductsService ... <- controllers: HTTP layer
| providers: business logic
ProductsRepository <- data access
Request: client --> Controller --> Service --> Repository --> Database- Module: a box that groups a feature (products, orders, users).
- Controller: receives a request and returns a response. It should be thin.
- Provider (usually a service): does the real work. NestJS creates it and injects it wherever it is needed.