create-nest-arch
v1.2.0
Published
CLI to scaffold NestJS projects with hexagonal, layered or microservice architecture
Maintainers
Readme
create-nest-arch
CLI to scaffold NestJS projects with Hexagonal Architecture, Microservices (TCP) or an API Gateway.
Fork of a thesis-driven tool, published for everyone: keep it generic, add your own domain.
Features
- 3 project types with battle-tested defaults:
hexagonal— Hexagonal / Clean Architecture monolith (application, domain, infrastructure).microservice— Pure TCP microservice with full CRUD + soft delete.gateway— HTTP API Gateway ready to forward messages to your microservices (Redis + rate limiting included).
- Prisma + PostgreSQL wired out of the box (
db:generate,db:migrate). - Correct naming out of the box:
ms-rooms→ entityRoom, message patternsrooms.*. - Class validation, common filters/interceptors, e2e tests, Docker & docker-compose.
- Zero config: answer 3 prompts and you're done.
Quick Start
# pnpm (recommended)
pnpm dlx create-nest-arch
# npm
npx create-nest-arch
# global install
npm install -g create-nest-arch
create-nest-archYou can also pass the project name as the first argument:
npx create-nest-arch ms-roomsThe CLI asks:
- Project name — e.g.
ms-rooms. - Project type — Hexagonal | Microservice Module | API Gateway.
- Add Docker support? — yes/no.
Generated projects
Microservice Module (microservice)
A pure TCP microservice (no HTTP routes). Only other services can talk to it.
ms-rooms/
├── prisma/schema.prisma # Room model + @@map("rooms")
├── src/
│ ├── main.ts # TCP transport, port 3001
│ ├── app.module.ts
│ └── room/ # entity derived from the project name
│ ├── dto/create-room.dto.ts
│ ├── dto/update-room.dto.ts
│ ├── entities/room.entity.ts
│ └── main/
│ ├── room.controller.ts # @MessagePattern({ cmd: 'rooms.*' })
│ ├── room.service.ts # CRUD + soft delete (isActive)
│ └── room.module.tsMessage patterns exposed:
| Pattern | Payload | Description |
| --- | --- | --- |
| rooms.create | CreateRoomDto | Create a room |
| rooms.findAll | — | List active rooms |
| rooms.findOne | { id } | Find one active room |
| rooms.update | { id, ...UpdateRoomDto } | Update a room |
| rooms.remove | { id } | Soft delete (isActive = false) |
Naming convention:
ms-rooms,users-service→ entityRoom,Userand patternsrooms.*,users.*.
Hexagonal Monolith (hexagonal)
Clean architecture layering: application/, domain/, infrastructure/.
src/modules/my-app/
├── application/
│ ├── dtos/{requests,responses}
│ └── use-cases/{commands,queries}
├── domain/
│ ├── entities/
│ ├── factories/
│ ├── interfaces/
│ └── services/{commands,queries}
└── infrastructure/
├── adapters/{ports,implements}
├── config/
└── controllers/API Gateway (gateway)
HTTP entry point ready to forward messages to microservices over TCP.
src/
├── app.controller.ts # GET /health
├── app.module.ts
├── common/ # filters, guards, interceptors, decorators
├── config/app.config.ts
├── modules/
├── redis/ # Redis module + service
├── throttle/ # rate limiting (ThrottlerModule)
├── types/ # shared response types
└── utils/Running a generated project
cd ms-rooms
cp .env.example .env
pnpm install
pnpm db:generate
pnpm db:migrate
pnpm start:devWith Docker:
cp .env.example .env
docker-compose up -dTech stack
- NestJS 10
- Prisma + PostgreSQL
- TCP transport via
@nestjs/microservices class-validator/class-transformer- Redis (gateway), Throttler (rate limiting)
License
MIT
