|
| 1 | +<p align="center"> |
| 2 | + <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a> |
| 3 | +</p> |
| 4 | + |
| 5 | +[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 |
| 6 | +[circleci-url]: https://circleci.com/gh/nestjs/nest |
| 7 | + |
| 8 | +<p align="center">A modular and scalable <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient, enterprise-ready backend architectures with NestJS.</p> |
| 9 | +<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a> |
| 10 | +<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a> |
| 11 | +<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a> |
| 12 | +<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a> |
| 13 | +<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a> |
| 14 | +<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a> |
| 15 | +<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a> |
| 16 | + <a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a> |
| 17 | + <a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a> |
| 18 | + <a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a> |
| 19 | +</p> |
| 20 | + <!--[](https://opencollective.com/nest#backer) |
| 21 | + [](https://opencollective.com/nest#sponsor)--> |
| 22 | + |
| 23 | +## 📌 Project Overview |
| 24 | +A modular, scalable, and enterprise-ready backend architecture built with NestJS. |
| 25 | + |
| 26 | +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. |
| 27 | + |
| 28 | +Ideal for enterprises and startups, this template helps teams progress from PoC to Product-Market Fit (PMC) by offering: |
| 29 | + |
| 30 | +- A structured yet flexible modular architecture |
| 31 | +- Integrated logger mechanism for operational insight |
| 32 | +- A database factory pattern supporting multiple databases (MySQL, PostgreSQL, SQLite) |
| 33 | + |
| 34 | +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. |
| 35 | + |
| 36 | +<a href='https://ko-fi.com/F1F82YR41' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi6.png?v=6' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a> |
| 37 | + |
| 38 | +## 🏗 Project Structure & Architecture |
| 39 | +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. |
| 40 | + |
| 41 | +``` |
| 42 | +modular-monolith-architecture |
| 43 | +├── Dockerfile |
| 44 | +├── docker-compose.*.yml # Support PostgreSQL & SQLite |
| 45 | +├── logs/ # Daily log files |
| 46 | +├── src/ |
| 47 | +│ ├── main.ts # Entry point |
| 48 | +│ ├── app.module.ts # Root module |
| 49 | +│ ├── common/ # Shared logic (e.g., logger, interceptors) |
| 50 | +│ ├── config/ # Multi-database configuration (MySQL, PostgreSQL, SQLite) |
| 51 | +│ └── modules/ |
| 52 | +│ ├── product/ # Product feature module |
| 53 | +│ └── user/ # User feature module |
| 54 | +├── test/ # e2e testing |
| 55 | +├── sample.env # Environment config template |
| 56 | +└── README.md |
| 57 | +``` |
| 58 | + |
| 59 | +## 🧩 Modular Breakdown |
| 60 | + |
| 61 | +- common/: Cross-cutting concerns such as custom exception filters, response interceptors, and centralized logging. |
| 62 | +- config/: Modular database configuration with support for SQLite, PostgreSQL, and MySQL, using a database factory pattern. |
| 63 | +- modules/: Business logic split into independently maintainable feature modules (e.g., user, product), each with: |
| 64 | + |
| 65 | + - controllers/: Handle HTTP requests |
| 66 | + - services/: Core business logic |
| 67 | + - repositories/: Database access logic |
| 68 | + - dto/, entities/, facades/: Well-structured data handling |
| 69 | + |
| 70 | +## ✨ Key Features |
| 71 | + |
| 72 | +- ✅ Modular Monolith Structure – Clear, maintainable boundaries between features while remaining deployable as a single unit. |
| 73 | +- 🧪 Built-in e2e Testing – Includes Jest test setup to validate end-to-end functionality. |
| 74 | +- 📦 Multi-Database Support – Easily switch between SQLite, PostgreSQL, and MySQL via plug-and-play configuration. |
| 75 | +- 🪵 Advanced Logging – Centralized file-based logging system with daily rotation (e.g., logs/application-YYYY-MM-DD.log). |
| 76 | +- 📁 Feature-Based Modular Design – Each domain (e.g., user/product) is fully encapsulated with its own logic. |
| 77 | +- ⚙️ Docker & Compose Ready – Start instantly with docker-compose setups for PostgreSQL and SQLite. |
| 78 | + |
| 79 | +## 💡 Design Principles and Benefits |
| 80 | + |
| 81 | +### 🔄 Simplicity Over Complexity |
| 82 | +Avoids over-engineering by not enforcing Clean Architecture or full DDD. Ideal for fast-moving projects, PoCs, or early-stage product validation. |
| 83 | + |
| 84 | +### 📦 Modular Without Microservices |
| 85 | +All domain modules are logically isolated, enabling easier future migration to microservices when scale demands it—without premature complexity. |
| 86 | + |
| 87 | +### 🌱 Startup & Enterprise Friendly |
| 88 | +Whether you're a lean startup or an enterprise team, this template provides a solid base to: |
| 89 | + |
| 90 | +- Quickly prototype ideas with real APIs |
| 91 | +- Gradually scale into a production-grade product |
| 92 | +- Demo to stakeholders using different DB engines |
| 93 | + |
| 94 | +### ⚡ PoC to PMC Ready |
| 95 | +Designed to support the lifecycle from Proof-of-Concept (PoC) to Product-Market Fit (PMC), offering balance between agility and structure. |
| 96 | + |
| 97 | +## 🚀 Quick Start |
| 98 | + |
| 99 | +Follow these steps to get your modular monolith project up and running in minutes. |
| 100 | + |
| 101 | +1. Clone the Template |
| 102 | + |
| 103 | +```bash |
| 104 | +git clone https://github.com/your-username/modular-monolith-architecture.git |
| 105 | +cd modular-monolith-architecture |
| 106 | +``` |
| 107 | + |
| 108 | +2. Install Dependencies |
| 109 | + |
| 110 | +```bash |
| 111 | +npm install |
| 112 | +``` |
| 113 | + |
| 114 | +3. Set Up Environment Variables |
| 115 | + |
| 116 | +Copy the sample environment file and customize it if needed: |
| 117 | + |
| 118 | +```bash |
| 119 | +cp sample.env .env |
| 120 | +``` |
| 121 | + |
| 122 | +4. Run the Application (Development Mode) |
| 123 | + |
| 124 | +```bash |
| 125 | +# development |
| 126 | +$ npm run start |
| 127 | + |
| 128 | +# watch mode |
| 129 | +$ npm run start:dev |
| 130 | + |
| 131 | +# production mode |
| 132 | +$ npm run start:prod |
| 133 | +``` |
| 134 | + |
| 135 | +By default, the API will be available at: |
| 136 | +👉 http://localhost:3000 |
| 137 | + |
| 138 | +5. Run tests |
| 139 | + |
| 140 | +```bash |
| 141 | +# unit tests |
| 142 | +$ npm run test |
| 143 | + |
| 144 | +# e2e tests |
| 145 | +$ npm run test:e2e |
| 146 | + |
| 147 | +# test coverage |
| 148 | +$ npm run test:cov |
| 149 | +``` |
| 150 | + |
| 151 | +6. Use Docker (Optional) |
| 152 | + |
| 153 | +- Run with SQLite (default) |
| 154 | + |
| 155 | +```bash |
| 156 | +docker-compose -f docker-compose.sqlite.yml up |
| 157 | +``` |
| 158 | + |
| 159 | +- Run with PostgreSQL |
| 160 | + |
| 161 | +```bash |
| 162 | +docker-compose -f docker-compose.postgresql.yml up |
| 163 | +``` |
| 164 | + |
| 165 | +## Logging |
| 166 | + |
| 167 | +Application logs are automatically saved to the logs/ directory with daily log rotation (e.g., application-2025-04-27.log). |
| 168 | + |
| 169 | +## Deployment |
| 170 | + |
| 171 | +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. |
| 172 | + |
| 173 | +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: |
| 174 | + |
| 175 | +```bash |
| 176 | +$ npm install -g mau |
| 177 | +$ mau deploy |
| 178 | +``` |
| 179 | + |
| 180 | +With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure. |
| 181 | + |
| 182 | +## Resources |
| 183 | + |
| 184 | +Check out a few resources that may come in handy when working with NestJS: |
| 185 | + |
| 186 | +- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework. |
| 187 | +- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy). |
| 188 | +- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/). |
| 189 | +- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks. |
| 190 | +- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com). |
| 191 | +- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com). |
| 192 | +- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs). |
| 193 | +- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com). |
| 194 | + |
| 195 | +## Support |
| 196 | + |
| 197 | +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). |
| 198 | + |
| 199 | +## Stay in touch |
| 200 | + |
| 201 | +- Author - [Da-Wei Lin](https://www.linkedin.com/in/da-wei-lin-689a35107/) |
| 202 | +- Website - [David Weblog](https://davidskyspace.com/) |
| 203 | +- Twitter - [@nestframework](https://twitter.com/nestframework) |
| 204 | + |
| 205 | +## License |
| 206 | + |
| 207 | +Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE). |
0 commit comments