You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+77-18Lines changed: 77 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,59 @@
1
1
# Generic Express Service
2
2
3
-
A generic Express.js back-end service designed to support multiple front-end apps that I am managing to build in parallel with this app. It includes RESTful API endpoints and user authentication and utilizes PostgreSQL for data persistence.
3
+
A generic Express.js back-end service designed to support multiple front-end apps that I am managing to build in parallel with this app. It includes RESTful API endpoints, user authentication, and uses PostgreSQL for data storage.
4
4
5
-
## Features
5
+
> Finding a hosting service with a free tier for dynamic deployment is difficult, so I combined the backend of multiple apps in this project to deploy and run it in production for free.
6
+
7
+
## Disclaimer
8
+
9
+
I'm building this project to practice what I am learning, and I don't plan to keep maintaining it in the future; _therefore, I have added a reset logic to periodically delete any non-admin data_.
10
+
11
+
## Apps Consumes This Service
6
12
7
-
- RESTful API with various endpoints serving different purposes
8
-
- User management and authentication endpoints
9
-
- Local PostgreSQL integration via Docker Compose
10
-
- TypeScript support with `tsx` for development
11
-
- Environment-based configuration
12
-
- Tested using Vitest and Supertest
13
-
- Ready for integration with front-end applications
13
+
-[Odin Shopping Cart](https://github.com/hussein-m-kandil/odin-shopping-cart) —_for the user management only_
14
+
-[Odin Blog Author](https://github.com/hussein-m-kandil/odin-blog-author)
15
+
-[Odin Blog Viewer](https://github.com/hussein-m-kandil/odin-blog-viewer/)
14
16
15
-
## Getting Started
17
+
## Features
18
+
19
+
-**User Management:** Full CRUD operations for users, including sign-up, sign-in, and a special guest sign-in route.
20
+
-**Authentication & Authorization:** Secure, JWT-based authentication using Passport.js, with support for partitioned cookies. It includes role-based access control, restricting certain actions to admins or resource owners.
21
+
-**Blog Engine:** Complete CRUD functionality for posts, comments, and votes. Posts can be classified using a flexible tagging system.
22
+
-**Image Handling:** Endpoints for uploading and managing images, including support for user avatars. Image metadata is processed using `Sharp`.
23
+
-**Advanced API Features:**
24
+
-**Pagination:** Efficient pagination is available for all major resources, including posts, comments, users, and images.
25
+
-**API Statistics:** An endpoint to track application statistics, such as visitor counts and other relevant metrics.
26
+
-**Robust Tech Stack:**
27
+
- Built with **TypeScript** and **Express.js v5**.
28
+
- Uses **Prisma ORM** for type-safe database access to a **PostgreSQL** database.
29
+
-**Zod** for schema validation, ensuring data integrity.
30
+
-**Winston** for structured, environment-based logging.
31
+
-**Development & Deployment:**
32
+
- Local PostgreSQL integration via Docker Compose.
33
+
- Tested using **Vitest** and **Supertest**.
34
+
- Continuous Integration (CI) setup with **GitHub Actions** to prepare for deployment on every push to the main branch.
-[Vitest](https://vitest.dev/) + [Supertest](https://www.npmjs.com/package/supertest) for testing
46
+
-[Docker Compose](https://docs.docker.com/compose/) for PostgreSQL
47
+
-[Sharp](https://sharp.pixelplumbing.com/) for image metadata and processing
48
+
49
+
## Local Development
16
50
17
51
### Prerequisites
18
52
19
53
-[Node.js](https://nodejs.org/) (tested on v22 but v20 should be fine too)
20
54
-[Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/)
21
55
22
-
## Installation
56
+
###Installation
23
57
24
58
1.**Clone the repository:**
25
59
@@ -53,21 +87,44 @@ A generic Express.js back-end service designed to support multiple front-end app
53
87
npx prisma db push
54
88
```
55
89
56
-
6.**Start the development server:**
90
+
6.**Seed the database (optional):**
91
+
92
+
```bash
93
+
npm run db:seed
94
+
```
95
+
96
+
7.**Start the development server:**
57
97
58
98
```bash
59
99
npm run dev
60
100
```
61
101
62
102
The API will be available at `http://localhost:8080`.
63
103
64
-
## Running Tests
104
+
###Running Tests
65
105
66
106
```bash
67
-
npm run test -- --run
107
+
# Prepare the test DB
108
+
npm run test:db:push
109
+
# Run all tests in watch mode. Append `-- --run` for single run
110
+
npm run test
68
111
```
69
112
70
-
## Manual Testing
113
+
### Scripts
114
+
115
+
-`npm run dev` — Start development server with hot reload.
116
+
-`npm run build` — Build TypeScript project.
117
+
-`npm start` — Run compiled server.
118
+
-`npm run lint` — Lint source files.
119
+
-`npm run type-check` — TypeScript type checks only.
120
+
-`npm run test` — Run tests with Vitest + Supertest.
121
+
-`npm run db:reset` — Reset Prisma migrations (skip seed).
122
+
-`npm run db:seed` — Seed database with sample data.
123
+
-`npm run pg:up` — Start PostgreSQL via Docker Compose.
124
+
-`npm run pg:stop` — Stop PostgreSQL container.
125
+
-`npm run pg:down` — Remove PostgreSQL container.
126
+
127
+
### Manual Testing
71
128
72
129
There are several HTTP request examples in `.rest` files located in the `/requests` directory. These can be used to manually test the API using the _[REST Client (VS Code extension)](https://marketplace.visualstudio.com/items?itemName=humao.rest-client)_, while the development server is running with the command `npm run dev`.
73
130
@@ -77,11 +134,13 @@ Every _push_ or _pull request (PR)_ on main branch, the app will be deployed to
77
134
78
135
## Notes
79
136
80
-
- This service is intended to support multiple front-end projects that I build.
81
137
- CORS is configured to allow only specific front-end origins under my control.
138
+
82
139
- JWT-based authentication is implemented and required by some endpoint.
83
-
- The `Bearer` schema is included in the authentication response, so _send your token as it is_ via an `Authorization` header.
84
-
- All error responses has the proper status code, but not all of them has a body. If an error response has a body it will have _at least_ the following:
140
+
141
+
- The `Bearer` schema is included in the authentication response, so the token should be sent _as is_ in an `Authorization` header.
142
+
143
+
- All error responses has the proper status code, but not all of them has a body (e.g. 401 Unauthorized). If an error response has a body it will have _at least_ the following:
0 commit comments