Skip to content

Commit 731c5d8

Browse files
Update README.md
1 parent d9fe002 commit 731c5d8

1 file changed

Lines changed: 77 additions & 18 deletions

File tree

README.md

Lines changed: 77 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,59 @@
11
# Generic Express Service
22

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.
44

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
612

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/)
1416

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.
35+
36+
## Tech Stack
37+
38+
- [Node.js](https://nodejs.org/) / [Express 5](https://expressjs.com/)
39+
- [TypeScript](https://www.typescriptlang.org/)
40+
- [Zod](https://zod.dev) for validation
41+
- [Winston](https://github.com/winstonjs/winston) for logging
42+
- [Multer](https://github.com/expressjs/multer) for file uploads
43+
- [JWT](https://jwt.io/) for authentication
44+
- [Prisma](https://www.prisma.io/) ORM + PostgreSQL
45+
- [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
1650

1751
### Prerequisites
1852

1953
- [Node.js](https://nodejs.org/) (tested on v22 but v20 should be fine too)
2054
- [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/)
2155

22-
## Installation
56+
### Installation
2357

2458
1. **Clone the repository:**
2559

@@ -53,21 +87,44 @@ A generic Express.js back-end service designed to support multiple front-end app
5387
npx prisma db push
5488
```
5589

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:**
5797

5898
```bash
5999
npm run dev
60100
```
61101

62102
The API will be available at `http://localhost:8080`.
63103

64-
## Running Tests
104+
### Running Tests
65105

66106
```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
68111
```
69112

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
71128

72129
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`.
73130

@@ -77,11 +134,13 @@ Every _push_ or _pull request (PR)_ on main branch, the app will be deployed to
77134

78135
## Notes
79136

80-
- This service is intended to support multiple front-end projects that I build.
81137
- CORS is configured to allow only specific front-end origins under my control.
138+
82139
- 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:
85144

86145
```json
87146
{

0 commit comments

Comments
 (0)