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.
- Host: GitHub
- URL: https://github.com/deadislove/nestjs-modular-monolith-architecture-template
- Owner: deadislove
- License: mit
- Created: 2025-05-03T02:16:07.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2025-05-12T01:51:43.000Z (24 days ago)
- Last Synced: 2025-05-12T02:41:32.426Z (24 days ago)
- Topics: env, modular-monolith-architecture, mysql, nestjs, nodejs, postgresql, sqlite, typeorm, typescript
- Language: TypeScript
- Homepage:
- Size: 150 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nestA modular and scalable Node.js framework for building efficient, enterprise-ready backend architectures with NestJS.
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()

## π 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.
## π 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:30005. 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).