Skip to content

Commit 3c54899

Browse files
authored
Merge pull request #8 from frckbrice/chore/update_dockerfile
chore: update Dockerfile, README, and index.js
2 parents f1f81e4 + 208b88c commit 3c54899

3 files changed

Lines changed: 9 additions & 38 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ EXPOSE 5000
2727
USER appuser
2828

2929
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
30-
CMD node -e "require('http').get('http://localhost:5000/', (r) => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))"
30+
CMD node -e "require('http').get('http://localhost:5000/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))"
3131

3232
CMD ["node", "index.js"]

README.md

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
2-
3-
# Clean code Architecture pattern applied to Node.js REST API Example
4-
1+
# Clean code Architecture pattern applied to Node.js REST API Example
52

63
<div style="width:100%; text-align:center">
74
<img src="public/images/clean-code_arch.jpeg" width="600">
@@ -11,7 +8,6 @@
118

129
> This project demonstrates how to apply Uncle Bob's Clean Architecture principles in a Node.js REST API. It is designed as an educational resource to help developers structure their projects for maximum testability, maintainability, and scalability. The codebase shows how to keep business logic independent from frameworks, databases, and delivery mechanisms.
1310
14-
1511
## Stack
1612

1713
- **Node.js** (Express.js) for the REST API
@@ -39,36 +35,6 @@
3935
- The product use case receives a `createProductDbHandler` as a parameter. In production, this is the real DB handler; in tests, it's a mock function.
4036
- Lower layers (domain, use cases) never import or reference Express, MongoDB, or any framework code.
4137

42-
=======
43-
44-
## Stack
45-
46-
- **Node.js** (Express.js) for the REST API
47-
- **MongoDB** (MongoClient) for persistence
48-
- **Jest** & **Supertest** for unit and integration testing
49-
- **ESLint** & **Prettier** for linting and formatting
50-
- **Docker** & **Docker Compose** for containerization
51-
- **GitHub Actions** for CI/CD
52-
53-
## Why Clean Architecture?
54-
55-
- **Separation of Concerns:** Each layer has a single responsibility and is independent from others.
56-
- **Dependency Rule:** Data and control flow from outer layers (e.g., routes/controllers) to inner layers (use cases, domain), never the reverse. Lower layers are unaware of upper layers.
57-
- **Testability:** Business logic can be tested in isolation by injecting dependencies (e.g., mock DB handlers) from above. No real database is needed for unit tests.
58-
- **Security & Flexibility:** Infrastructure (DB, frameworks) can be swapped without touching business logic.
59-
60-
> **✨ Ultimate Flexibility:**
61-
> This project demonstrates that your core business logic is never tied to any specific framework, ORM, or database. You can switch from Express to Fastify, MongoDB to PostgreSQL, or even move to a serverless environment—without rewriting your business rules. The architecture ensures your codebase adapts easily to new technologies, making future migrations and upgrades painless. This is true Clean Architecture in action: your app’s heart beats independently of any tool or vendor.
62-
63-
## How Testing Works
64-
65-
- **Unit tests** inject mocks for all dependencies (DB, loggers, etc.) into use cases and controllers. This means you can test all business logic without a real database or server.
66-
- **Integration tests** can use a real or in-memory database, but the architecture allows you to swap these easily.
67-
- **Example:**
68-
- The product use case receives a `createProductDbHandler` as a parameter. In production, this is the real DB handler; in tests, it's a mock function.
69-
- Lower layers (domain, use cases) never import or reference Express, MongoDB, or any framework code.
70-
71-
7238
## Project Structure
7339

7440
```
@@ -86,7 +52,6 @@ routes/ # Express route definitions
8652
public/ # Static files and HTML views
8753
```
8854

89-
9055
## Features
9156

9257
- User registration and authentication (JWT)
@@ -97,6 +62,7 @@ public/ # Static files and HTML views
9762
- Modular, testable codebase
9863

9964
## Stack
65+
10066
- Express.js
10167
- Javascript
10268
- MongoDB doker image
@@ -121,7 +87,7 @@ public/ # Static files and HTML views
12187
```bash
12288
yarn install
12389
```
124-
3. Copy `.env.example` to `.env` and set your environment variables. For production, set `NODE_ENV=production`
90+
3. Copy `.env.example` to `.env` and set your environment variables. For production, set `NODE_ENV=production`
12591
4. Start the server:
12692
```bash
12793
yarn dev

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ app.use(express.json());
117117
app.use(cookieParser());
118118
app.use(express.urlencoded({ extended: false }));
119119

120+
// Health check route (for load balancers, Docker, k8s)
121+
app.get('/health', (_, res) => {
122+
res.status(200).json({ status: 'ok', timestamp: new Date().toISOString() });
123+
});
124+
120125
// Register Swagger UI BEFORE any static or catch-all routes
121126
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
122127

0 commit comments

Comments
 (0)