Skip to content

Commit 88e334e

Browse files
committed
first commit
0 parents  commit 88e334e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+15828
-0
lines changed

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# .dockerignore
2+
node_modules
3+
dist
4+
.git
5+
Dockerfile
6+
npm-debug.log
7+
.env
8+
logs/
9+
*.log

.gitignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
/build
5+
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
pnpm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
lerna-debug.log*
14+
15+
# OS
16+
.DS_Store
17+
18+
# Tests
19+
/coverage
20+
/.nyc_output
21+
22+
# IDEs and editors
23+
/.idea
24+
.project
25+
.classpath
26+
.c9/
27+
*.launch
28+
.settings/
29+
*.sublime-workspace
30+
31+
# IDE - VSCode
32+
.vscode/*
33+
!.vscode/settings.json
34+
!.vscode/tasks.json
35+
!.vscode/launch.json
36+
!.vscode/extensions.json
37+
38+
# dotenv environment variable files
39+
.env
40+
.env.development.local
41+
.env.test.local
42+
.env.production.local
43+
.env.local
44+
45+
# temp directory
46+
.temp
47+
.tmp
48+
49+
# Runtime data
50+
pids
51+
*.pid
52+
*.seed
53+
*.pid.lock
54+
55+
# Diagnostic reports (https://nodejs.org/api/report.html)
56+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}

Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -------- Stage 1: Build environment --------
2+
FROM node:22.14 AS builder
3+
4+
# Install build tools required for native modules (e.g., sqlite3, mysql, mysql2)
5+
RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/*
6+
7+
# Set working directory inside the container
8+
WORKDIR /usr/src/app
9+
10+
# Copy package.json and package-lock.json to install dependencies
11+
COPY package*.json ./
12+
13+
# Install all dependencies including native modules
14+
RUN npm install
15+
16+
# RUN npm install sqlite3 --save
17+
18+
# Copy the entire application code into the container
19+
COPY . .
20+
21+
# Build the application (e.g., NestJS -> dist folder)
22+
RUN npm run build
23+
24+
# -------- Stage 2: Clean production image --------
25+
FROM node:22.14
26+
27+
# Set working directory in the final production image
28+
WORKDIR /usr/src/app
29+
30+
# Copy built application and installed modules from the builder stage
31+
COPY --from=builder /usr/src/app .
32+
33+
# Set environment variables (can be overridden at runtime)
34+
ENV PORT=3000
35+
ENV DB_TYPE=sqlite
36+
ENV DB_HOST=localhost
37+
ENV DB_PORT=5432
38+
ENV DB_USERNAME=''
39+
ENV DB_PASSWORD=''
40+
ENV DB_NAME=''
41+
42+
# Expose the port your app runs on
43+
EXPOSE 3000
44+
45+
# Define the default command to run your application
46+
CMD ["npm", "run", "start:prod"]

README.md

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
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+
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
21+
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](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).

database.sqlite

16 KB
Binary file not shown.

docker-compose.postgresql.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
ports:
6+
- "3000:3000"
7+
depends_on:
8+
- postgres
9+
environment:
10+
DB_TYPE: postgres
11+
DB_HOST: postgres
12+
DB_PORT: 5432
13+
DB_USERNAME: postgres
14+
DB_PASSWORD: password
15+
DB_NAME: mydb
16+
17+
postgres:
18+
image: postgres:15
19+
restart: always
20+
environment:
21+
POSTGRES_DB: mydb
22+
POSTGRES_USER: postgres
23+
POSTGRES_PASSWORD: password
24+
ports:
25+
- "5432:5432"
26+
volumes:
27+
- pgdata:/var/lib/postgresql/data
28+
29+
volumes:
30+
pgdata:

docker-compose.sqlite.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
container_name: nestjs-app
9+
ports:
10+
- "3000:3000"
11+
volumes:
12+
- .:/usr/src/app
13+
environment:
14+
PORT: 3000
15+
DB_TYPE: sqlite
16+
DB_HOST: localhost
17+
DB_PORT: 5432
18+
DB_USERNAME:
19+
DB_PASSWORD:
20+
DB_NAME: database.sqlite
21+
restart: unless-stopped

0 commit comments

Comments
 (0)