Skip to content

🧱 A modular monolith Node.js project using NestJS with event-driven architecture, pluggable DB and event bus support (SQLite, PostgreSQL, Kafka, Redis, etc.).

License

Notifications You must be signed in to change notification settings

deadislove/nestJS-modular-monolith-event-driven-architecture-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Nest Logo

NestJS is a progressive Node.js framework for creating efficient, reliable, and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Discord Backers on Open Collective Sponsors on Open Collective Donate us Support us Follow us on Twitter

Visitors Clones

🌍 Project Overview

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.

Buy Me a Coffee at ko-fi.com

πŸ”Ή Project Structure & Architecture

β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.*.yml
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ common
β”‚   β”œβ”€β”€ config
β”‚   β”œβ”€β”€ core
β”‚   β”œβ”€β”€ infra
β”‚   β”œβ”€β”€ modules
β”‚   β”‚   β”œβ”€β”€ auth
β”‚   β”‚   β”œβ”€β”€ notifications
β”‚   β”‚   β”œβ”€β”€ product
β”‚   β”‚   └── user
β”‚   └── main.ts
└── test

Key Architectural Layers:

  • 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.

πŸ“š Modular Breakdown

Auth Module

  • Manages authentication using JWT.

User Module

  • Handles user registration, login, and profile updates.

Product Module

  • Implements product creation, update, and management.

Notifications Module

  • Listens to domain events and sends notifications.
  • Supports email providers with a provider factory.

✨ Key Features

  • βœ… 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

βš–οΈ Design Principles and Benefits

  • 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.

✨ PoC to PMC Ready

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.

⚑ Quick Start

  1. 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
  1. Install dependencies:
$ npm install
  1. Install dependencies:
cp .env.example .env
  1. Compile and run the project
# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod
  1. Run tests:
# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
  1. 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

Logging

Application logs are automatically saved to the logs/ directory with daily log rotation (e.g., application-2025-04-27.log).

Deployment

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.

Resources

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.

Support

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.

Stay in touch

License

Nest is MIT licensed.

About

🧱 A modular monolith Node.js project using NestJS with event-driven architecture, pluggable DB and event bus support (SQLite, PostgreSQL, Kafka, Redis, etc.).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published