An open API service indexing awesome lists of open source software.

https://github.com/deadislove/nestjs-modular-monolith-architecture-template

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.
https://github.com/deadislove/nestjs-modular-monolith-architecture-template

env modular-monolith-architecture mysql nestjs nodejs postgresql sqlite typeorm typescript

Last synced: 23 days ago
JSON representation

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.

Awesome Lists containing this project

README

        


Nest Logo

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

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](https://img.shields.io/badge/visitors-205_total-brightgreen)
![Clones](https://img.shields.io/badge/clones-36_total_30_unique-blue)

## πŸ“Œ 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

```bash
git clone https://github.com/your-username/modular-monolith-architecture.git
cd modular-monolith-architecture
```

2. Install Dependencies

```bash
npm install
```

3. Set Up Environment Variables

Copy the sample environment file and customize it if needed:

```bash
cp sample.env .env
```

4. Run the Application (Development Mode)

```bash
# 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

5. Run tests

```bash
# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
```

6. Use Docker (Optional)

- Run with SQLite (default)

```bash
docker-compose -f docker-compose.sqlite.yml up
```

- Run with PostgreSQL

```bash
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](https://docs.nestjs.com/deployment) for more information.

If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:

```bash
$ 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](https://docs.nestjs.com) to learn more about the framework.
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).

## 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](https://docs.nestjs.com/support).

## Stay in touch

- Author - [Da-Wei Lin](https://www.linkedin.com/in/da-wei-lin-689a35107/)
- Website - [David Weblog](https://davidskyspace.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)

## License

Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).