NestJS is a progressive Node.js framework for creating efficient, reliable, and scalable server-side applications.
This project demonstrates a modular monolith architecture incorporating event-driven communication patterns. It is designed to serve as a scalable, maintainable backend foundation for complex applications. Leveraging NestJS, the app implements factory patterns for database and event bus providers, supporting PostgreSQL, MySQL, SQLite, Redis, Kafka, and in-memory solutions. The system is containerized using Docker and supports deployment on orchestration platforms such as Docker Cloud or Kubernetes.
βββ Dockerfile
βββ docker-compose.*.yml
βββ src
β βββ common
β βββ config
β βββ core
β βββ infra
β βββ modules
β β βββ auth
β β βββ notifications
β β βββ product
β β βββ user
β βββ main.ts
βββ test
- Interface Layer: REST controllers for each module.
- Application Layer: DTOs, Services, and Facades.
- Domain Layer: Entities, Value Objects, and Interfaces.
- Infrastructure Layer: TypeORM entities, repositories, event buses, and database factories.
- Manages authentication using JWT.
- Handles user registration, login, and profile updates.
- Implements product creation, update, and management.
- Listens to domain events and sends notifications.
- Supports email providers with a provider factory.
- β Modular Monolith Architecture
- β Event-Driven Communication
- β Factory Pattern for Database and Event Bus
- β Kafka and Redis Support
- β Handler Registry & Decorators for Auto Event Binding
- β Containerized for Docker and Kubernetes
- Single Responsibility & Separation of Concerns: Each module and layer handles a specific responsibility.
- Scalability: Can be easily split into microservices if needed.
- Testability: Well-structured layers for unit and e2e testing.
- Flexibility: Easily swap out database and message bus technologies.
This project is suitable for:
- Proof of Concept (PoC): Rapid validation of ideas with SQLite & in-memory bus.
- Production Minimum Configuration (PMC): Use PostgreSQL + Kafka with Docker Compose.
- Clone the repository:
git clone https://github.com/deadislove/nestJS-modular-monolith-event-driven-architecture-template.git
cd nestJS-modular-monolith-event-driven-architecture-template
- Install dependencies:
$ npm install
- Install dependencies:
cp .env.example .env
- Compile and run the project
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
- Run tests:
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
- Run the application:
Navigate to http://localhost:3000 in your browser.
For Docker-based setup, refer to the docker-compose.sqlite.yml or docker-compose.postgresql.yml files.
- Run with SQLite (default)
docker-compose -f docker-compose.sqlite.redis.yml up
# or
docker-compose -f docker-compose.sqlite.redis.yml up --build
- Run with PostgreSQL
docker-compose -f docker-compose.postgresql.redis.yml up
# or
docker-compose -f docker-compose.postgresql.redis.yml up --build
Application logs are automatically saved to the logs/ directory with daily log rotation (e.g., application-2025-04-27.log).
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the deployment documentation for more information.
If you are looking for a cloud-based platform to deploy your NestJS application, check out Mau, our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
$ npm install -g mau
$ mau deploy
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
Check out a few resources that may come in handy when working with NestJS:
- Visit the NestJS Documentation to learn more about the framework.
- For questions and support, please visit our Discord channel.
- To dive deeper and get more hands-on experience, check out our official video courses.
- Deploy your application to AWS with the help of NestJS Mau in just a few clicks.
- Visualize your application graph and interact with the NestJS application in real-time using NestJS Devtools.
- Need help with your project (part-time to full-time)? Check out our official enterprise support.
- To stay in the loop and get updates, follow us on X and LinkedIn.
- Looking for a job, or have a job to offer? Check out our official Jobs board.
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
- Author - Da-Wei Lin
- Website - David Weblog
- Twitter - @nestframework
Nest is MIT licensed.