8
8
9
9
![ nodepost] ( https://github.com/user-attachments/assets/6f206c6e-dea0-4045-8baa-a04e74a5fbf8 )
10
10
11
+ ## ✨ Overview
11
12
This is a modern RESTful API built with ** Node.js** and ** Express** , designed to interact with a ** PostgreSQL** database. The API provides various endpoints for managing user data, with additional features like authentication, JWT protection, soft deletion, and automated testing. We've also integrated ** Swagger** for auto-generated API documentation.
12
13
13
14
![ Express.js] ( https://img.shields.io/badge/express.js-%23404d59.svg?style=for-the-badge&logo=express&logoColor=%2361DAFB )
14
15
![ NodeJS] ( https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge&logo=node.js&logoColor=white )
15
16
![ Postgres] ( https://img.shields.io/badge/postgres-%23316192.svg?style=for-the-badge&logo=postgresql&logoColor=white )
16
17
![ NPM] ( https://img.shields.io/badge/NPM-%23CB3837.svg?style=for-the-badge&logo=npm&logoColor=white )
17
18
18
- ## Features 🚀
19
+ ## 🏗️ Architecture
20
+
21
+ ``` mermaid
22
+ flowchart TB
23
+ %% Clients
24
+ Clients["Clients (Web/Mobile/CLI)"]:::client
25
+
26
+ %% Docker Container Boundary
27
+ subgraph "Docker Container"
28
+ direction TB
29
+ index["index.js\n(Express App Init)"]:::server
30
+ click index "https://github.com/jawherkl/node-api-postgres/blob/main/index.js"
31
+
32
+ %% Configuration Layer
33
+ subgraph "Configuration Layer"
34
+ direction TB
35
+ dbConfig["config/db.js"]:::config
36
+ click dbConfig "https://github.com/jawherkl/node-api-postgres/blob/main/config/db.js"
37
+ swaggerSetup["config/swagger.js"]:::config
38
+ click swaggerSetup "https://github.com/jawherkl/node-api-postgres/blob/main/config/swagger.js"
39
+ swaggerSpec["config/swagger.json"]:::config
40
+ click swaggerSpec "https://github.com/jawherkl/node-api-postgres/blob/main/config/swagger.json"
41
+ end
42
+
43
+ %% Routing Layer
44
+ subgraph "Routing Layer"
45
+ direction TB
46
+ loginRoutes["routes/loginRoutes.js"]:::routes
47
+ click loginRoutes "https://github.com/jawherkl/node-api-postgres/blob/main/routes/loginRoutes.js"
48
+ userRoutes["routes/userRoutes.js"]:::routes
49
+ click userRoutes "https://github.com/jawherkl/node-api-postgres/blob/main/routes/userRoutes.js"
50
+ metricsRoutes["routes/metricsRoutes.js"]:::routes
51
+ click metricsRoutes "https://github.com/jawherkl/node-api-postgres/blob/main/routes/metricsRoutes.js"
52
+ end
53
+
54
+ %% Controller Layer
55
+ subgraph "Controller Layer"
56
+ direction TB
57
+ authController["controllers/authController.js"]:::controller
58
+ click authController "https://github.com/jawherkl/node-api-postgres/blob/main/controllers/authController.js"
59
+ userController["controllers/userController.js"]:::controller
60
+ click userController "https://github.com/jawherkl/node-api-postgres/blob/main/controllers/userController.js"
61
+ metricsController["controllers/metricsController.js"]:::controller
62
+ click metricsController "https://github.com/jawherkl/node-api-postgres/blob/main/controllers/metricsController.js"
63
+ end
64
+
65
+ %% Middleware Pipeline
66
+ subgraph "Middleware Pipeline"
67
+ direction TB
68
+ jwtAuth["middleware/auth.js"]:::middleware
69
+ click jwtAuth "https://github.com/jawherkl/node-api-postgres/blob/main/middleware/auth.js"
70
+ rbacAuth["middleware/authorize.js"]:::middleware
71
+ click rbacAuth "https://github.com/jawherkl/node-api-postgres/blob/main/middleware/authorize.js"
72
+ upload["middleware/upload.js"]:::middleware
73
+ click upload "https://github.com/jawherkl/node-api-postgres/blob/main/middleware/upload.js"
74
+ errorHandler["middleware/errorHandler.js"]:::middleware
75
+ click errorHandler "https://github.com/jawherkl/node-api-postgres/blob/main/middleware/errorHandler.js"
76
+ end
77
+
78
+ %% Data Access Layer
79
+ subgraph "Data Access Layer"
80
+ direction TB
81
+ userModel["models/user.js"]:::model
82
+ click userModel "https://github.com/jawherkl/node-api-postgres/blob/main/models/user.js"
83
+ metricsModel["models/metrics.js"]:::model
84
+ click metricsModel "https://github.com/jawherkl/node-api-postgres/blob/main/models/metrics.js"
85
+ end
86
+
87
+ %% Utility Services
88
+ subgraph "Utility Services"
89
+ direction TB
90
+ mailer["utils/mailer.js"]:::util
91
+ click mailer "https://github.com/jawherkl/node-api-postgres/blob/main/utils/mailer.js"
92
+ logger["utils/logger.js"]:::util
93
+ click logger "https://github.com/jawherkl/node-api-postgres/blob/main/utils/logger.js"
94
+ end
95
+
96
+ %% Static Assets & Storage
97
+ subgraph "Static & Storage"
98
+ direction TB
99
+ resetPage["public/reset-password.html"]:::static
100
+ click resetPage "https://github.com/jawherkl/node-api-postgres/blob/main/public/reset-password.html"
101
+ uploadsDir["uploads/"]:::infra
102
+ click uploadsDir "https://github.com/jawherkl/node-api-postgres/tree/main/uploads/"
103
+ end
104
+
105
+ %% Exposed Swagger UI
106
+ swaggerUI["Swagger UI\n(/api-docs)"]:::server
107
+ end
108
+
109
+ %% External Services & Infrastructure
110
+ postgres[(PostgreSQL Database 5432)]:::external
111
+ sendgrid[(SendGrid Email Service)]:::external
112
+ prometheus[(Prometheus)]:::external
113
+ dockerfile["Dockerfile"]:::infra
114
+ click dockerfile "https://github.com/jawherkl/node-api-postgres/tree/main/Dockerfile"
115
+ compose["docker-compose.yml"]:::infra
116
+ click compose "https://github.com/jawherkl/node-api-postgres/blob/main/docker-compose.yml"
117
+ promConfig["prometheus.yml"]:::infra
118
+ click promConfig "https://github.com/jawherkl/node-api-postgres/blob/main/prometheus.yml"
119
+
120
+ %% Connections
121
+ Clients -->|"HTTP|JSON"| index
122
+ index -->|"load"| dbConfig
123
+ index -->|"load"| swaggerSetup
124
+ swaggerSetup -->|"uses"| swaggerSpec
125
+ index -->|"mount"| loginRoutes
126
+ index -->|"mount"| userRoutes
127
+ index -->|"mount"| metricsRoutes
128
+ loginRoutes -->|"calls"| authController
129
+ userRoutes -->|"calls"| userController
130
+ metricsRoutes -->|"calls"| metricsController
131
+ index -->|"use"| jwtAuth
132
+ index -->|"use"| rbacAuth
133
+ index -->|"use"| upload
134
+ index -->|"use"| errorHandler
135
+ authController -->|"DB ops"| userModel
136
+ userController -->|"DB ops"| userModel
137
+ metricsController -->|"DB ops"| metricsModel
138
+ authController -->|"send email"| mailer
139
+ metricsController -->|"log metrics"| logger
140
+ metricsController -->|"expose /metrics"| prometheus
141
+ index -->|"serve UI"| swaggerUI
142
+ index -->|"serve file"| resetPage
143
+ index -->|"write/read"| uploadsDir
144
+ userModel -->|"SQL"| postgres
145
+ metricsModel -->|"SQL"| postgres
146
+ index -->|"HTTP"| postgres
147
+ index -->|"SMTP/HTTP"| sendgrid
148
+ prometheus -->|"scrape /metrics"| index
149
+
150
+ %% Styles
151
+ classDef client fill:#f9f,stroke:#333
152
+ classDef server fill:#bbf,stroke:#333
153
+ classDef config fill:#dfd,stroke:#333
154
+ classDef routes fill:#ffd,stroke:#333
155
+ classDef controller fill:#fdc,stroke:#333
156
+ classDef middleware fill:#ffc,stroke:#333
157
+ classDef model fill:#cdf,stroke:#333
158
+ classDef util fill:#ddf,stroke:#333
159
+ classDef static fill:#fcf,stroke:#333
160
+ classDef external fill:#bfb,stroke:#333
161
+ classDef infra fill:#fbf,stroke:#333
162
+ ```
163
+
164
+ ## 🚀 Features
19
165
- ** User Management** :
20
166
- ** Get All Users** : Retrieve a list of all users.
21
167
- ** Get User by ID** : Retrieve a specific user by their ID.
@@ -49,7 +195,7 @@ This is a modern RESTful API built with **Node.js** and **Express**, designed to
49
195
- ** Mocha** (Testing framework)
50
196
- ** Chai** (Assertion library)
51
197
52
- ## Installation 🛠️
198
+ ## 🛠️ Installation
53
199
### Step 1: Clone the Repository
54
200
``` bash
55
201
git clone https://github.com/JawherKl/node-api-postgres.git
@@ -110,7 +256,7 @@ CREATE TABLE metrics (
110
256
- ` updated_at ` : Timestamp for last update (auto-updates on modification).
111
257
- ` deleted_at ` : Nullable timestamp for soft deletion.
112
258
113
- ## Usage 🏃♂️
259
+ ## 🏃♂️ Usage
114
260
115
261
### Start the Server
116
262
``` bash
@@ -135,7 +281,7 @@ Once the server is running, you can access the auto-generated API documentation
135
281
136
282
[ <img src =" https://run.pstmn.io/button.svg " alt =" Run In Postman " style =" width : 128px ; height : 32px ;" >] ( https://app.getpostman.com/run-collection/31522917-54350f46-dd5e-4a62-9dc2-4346a7879692?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D31522917-54350f46-dd5e-4a62-9dc2-4346a7879692%26entityType%3Dcollection%26workspaceId%3D212c8589-8dd4-4f19-9a53-e77403c6c7d9 )
137
283
138
- ## Example Requests 📝
284
+ ## 📝 Example Requests
139
285
140
286
### Get All Users
141
287
``` bash
@@ -177,7 +323,7 @@ curl -X POST http://localhost:3000/reset-password/your_reset_token -H "Content-T
177
323
curl -X GET http://localhost:3000/users -H " Authorization: Bearer your_jwt_token"
178
324
```
179
325
180
- ## Unit Testing 🧪
326
+ ## 🧪 Unit Testing
181
327
Unit tests are implemented using ** Mocha** and ** Chai** . To run tests:
182
328
183
329
1 . Install ** test dependencies** (if not installed):
@@ -192,13 +338,13 @@ Unit tests are implemented using **Mocha** and **Chai**. To run tests:
192
338
193
339
This will run all tests and output the results to the console. You can find the test cases for different routes and operations in the ` test ` folder.
194
340
195
- ## Contributing 🤝
341
+ ## 🤝 Contributing
196
342
Contributions are welcome! If you have suggestions, improvements, or bug fixes, please open an issue or submit a pull request.
197
343
198
344
## License 📝
199
345
This project is licensed under the ** MIT License** . See the [ LICENSE] ( ./LICENSE ) file for details.
200
346
201
- ## Acknowledgments 🙏
347
+ ## 🙏 Acknowledgments
202
348
- Special thanks to all contributors and the open-source community.
203
349
- Gratitude to the maintainers of the libraries used in this project.
204
350
0 commit comments