Skip to content

A flexible and scalable backend solution using NestJS, designed for quick development and easy future adaptability. With support for multiple databases and built-in testing and Docker configurations, this template enables efficient deployment and long-term stability.

License

Notifications You must be signed in to change notification settings

deadislove/nestJS-modular-monolith-architecture

Repository files navigation

Nest Logo

A modular and scalable Node.js framework for building efficient, enterprise-ready backend architectures with NestJS.

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

A modular, scalable, and enterprise-ready backend architecture built with NestJS.

This project is designed to accelerate backend development, especially for rapid Proof-of-Concept (PoC) efforts, new system bootstrapping, or as a clean foundation for evolving from a monolith to microservices. It embraces the modular monolith patternβ€”intentionally excluding Clean Architecture and Domain-Driven Design (DDD) to reduce complexity and promote faster iteration.

Ideal for enterprises and startups, this template helps teams progress from PoC to Product-Market Fit (PMC) by offering:

  • A structured yet flexible modular architecture
  • Integrated logger mechanism for operational insight
  • A database factory pattern supporting multiple databases (MySQL, PostgreSQL, SQLite)

If you're looking for a reliable and pragmatic backend starterβ€”whether for demos, PoC trials, or real-world product foundationsβ€”this project can help you move fast with confidence.

Buy Me a Coffee at ko-fi.com

πŸ— Project Structure & Architecture

This project follows a modular monolith architecture, emphasizing clear separation of concerns while maintaining the simplicity of a monolithic deployment. The folder layout encourages scalable, testable, and maintainable codebases.

modular-monolith-architecture
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.*.yml         # Support PostgreSQL & SQLite
β”œβ”€β”€ logs/                        # Daily log files
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.ts                  # Entry point
β”‚   β”œβ”€β”€ app.module.ts            # Root module
β”‚   β”œβ”€β”€ common/                  # Shared logic (e.g., logger, interceptors)
β”‚   β”œβ”€β”€ config/                  # Multi-database configuration (MySQL, PostgreSQL, SQLite)
β”‚   └── modules/
β”‚       β”œβ”€β”€ product/             # Product feature module
β”‚       └── user/                # User feature module
β”œβ”€β”€ test/                        # e2e testing
β”œβ”€β”€ sample.env                   # Environment config template
└── README.md

🧩 Modular Breakdown

  • common/: Cross-cutting concerns such as custom exception filters, response interceptors, and centralized logging.

  • config/: Modular database configuration with support for SQLite, PostgreSQL, and MySQL, using a database factory pattern.

  • modules/: Business logic split into independently maintainable feature modules (e.g., user, product), each with:

    • controllers/: Handle HTTP requests
    • services/: Core business logic
    • repositories/: Database access logic
    • dto/, entities/, facades/: Well-structured data handling

✨ Key Features

  • βœ… Modular Monolith Structure – Clear, maintainable boundaries between features while remaining deployable as a single unit.
  • πŸ§ͺ Built-in e2e Testing – Includes Jest test setup to validate end-to-end functionality.
  • πŸ“¦ Multi-Database Support – Easily switch between SQLite, PostgreSQL, and MySQL via plug-and-play configuration.
  • πŸͺ΅ Advanced Logging – Centralized file-based logging system with daily rotation (e.g., logs/application-YYYY-MM-DD.log).
  • πŸ“ Feature-Based Modular Design – Each domain (e.g., user/product) is fully encapsulated with its own logic.
  • βš™οΈ Docker & Compose Ready – Start instantly with docker-compose setups for PostgreSQL and SQLite.

πŸ’‘ Design Principles and Benefits

πŸ”„ Simplicity Over Complexity

Avoids over-engineering by not enforcing Clean Architecture or full DDD. Ideal for fast-moving projects, PoCs, or early-stage product validation.

πŸ“¦ Modular Without Microservices

All domain modules are logically isolated, enabling easier future migration to microservices when scale demands itβ€”without premature complexity.

🌱 Startup & Enterprise Friendly

Whether you're a lean startup or an enterprise team, this template provides a solid base to:

  • Quickly prototype ideas with real APIs
  • Gradually scale into a production-grade product
  • Demo to stakeholders using different DB engines

⚑ PoC to PMC Ready

Designed to support the lifecycle from Proof-of-Concept (PoC) to Product-Market Fit (PMC), offering balance between agility and structure.

πŸš€ Quick Start

Follow these steps to get your modular monolith project up and running in minutes.

  1. Clone the Template
git clone https://github.com/your-username/modular-monolith-architecture.git
cd modular-monolith-architecture
  1. Install Dependencies
npm install
  1. Set Up Environment Variables

Copy the sample environment file and customize it if needed:

cp sample.env .env
  1. Run the Application (Development Mode)
# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

By default, the API will be available at: πŸ‘‰ http://localhost:3000

  1. Run tests
# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
  1. Use Docker (Optional)
  • Run with SQLite (default)
docker-compose -f docker-compose.sqlite.yml up
  • Run with PostgreSQL
docker-compose -f docker-compose.postgresql.yml up

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 flexible and scalable backend solution using NestJS, designed for quick development and easy future adaptability. With support for multiple databases and built-in testing and Docker configurations, this template enables efficient deployment and long-term stability.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published