{"id":27431037,"url":"https://github.com/hussein-m-kandil/generic-express-service","last_synced_at":"2026-01-22T07:33:25.076Z","repository":{"id":287569364,"uuid":"965133951","full_name":"hussein-m-kandil/generic-express-service","owner":"hussein-m-kandil","description":"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.","archived":false,"fork":false,"pushed_at":"2026-01-03T15:31:04.000Z","size":10417,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-06T11:34:40.346Z","etag":null,"topics":["api","bcryptjs","cors","docker","docker-compose","express","jwt","multer","nodejs","passport","postgresql","prisma","rest-api","sharp","sql","supertest","typescript","vitest","winston","zod"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hussein-m-kandil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-04-12T13:42:27.000Z","updated_at":"2025-11-05T06:00:42.000Z","dependencies_parsed_at":"2025-05-04T10:23:55.380Z","dependency_job_id":"c7a22660-4f6d-4cf7-9688-cfbc3cea633f","html_url":"https://github.com/hussein-m-kandil/generic-express-service","commit_stats":null,"previous_names":["hussein-m-kandil/generic-express-service"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hussein-m-kandil/generic-express-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hussein-m-kandil%2Fgeneric-express-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hussein-m-kandil%2Fgeneric-express-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hussein-m-kandil%2Fgeneric-express-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hussein-m-kandil%2Fgeneric-express-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hussein-m-kandil","download_url":"https://codeload.github.com/hussein-m-kandil/generic-express-service/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hussein-m-kandil%2Fgeneric-express-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28658107,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","bcryptjs","cors","docker","docker-compose","express","jwt","multer","nodejs","passport","postgresql","prisma","rest-api","sharp","sql","supertest","typescript","vitest","winston","zod"],"created_at":"2025-04-14T15:28:26.060Z","updated_at":"2026-01-22T07:33:25.060Z","avatar_url":"https://github.com/hussein-m-kandil.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Generic Express Service\n\nA 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.\n\n\u003e 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.\n\n## Disclaimer\n\nI built this project to showcase what I am learning in web development, and I do not plan to keep maintaining it; therefore, _I added a reset feature to periodically delete any non-admin data_.\n\n## Apps Consumes This Service\n\n1. [Odin Shopping Cart](https://github.com/hussein-m-kandil/odin-shopping-cart) —_for the user management only_\n2. [Odin Blog Author](https://github.com/hussein-m-kandil/odin-blog-author)\n3. [Odin Blog Viewer](https://github.com/hussein-m-kandil/odin-blog-viewer)\n4. [Odin Where's Waldo](https://github.com/hussein-m-kandil/odin-where-is-waldo)\n\n## Features\n\n- **User Management:** Full CRUD operations for users, including sign-up, sign-in, and a special guest sign-in route.\n- **Authentication \u0026 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.\n- **Blog Engine:** Complete CRUD functionality for posts, comments, and votes. Posts can be classified using a flexible tagging system.\n- **Image Handling:** Endpoints for uploading and managing images, including support for user avatars. Image metadata is processed using `Sharp`.\n- **Advanced API Features:**\n  - **Pagination:** Efficient pagination is available for all major resources, including posts, comments, users, and images.\n  - **API Statistics:** An endpoint to track application statistics, such as visitor counts and other relevant metrics.\n- **Robust Tech Stack:**\n  - Built with **TypeScript** and **Express.js v5**.\n  - Uses **Prisma ORM** for type-safe database access to a **PostgreSQL** database.\n  - **Zod** for schema validation, ensuring data integrity.\n  - **Winston** for structured, environment-based logging.\n- **Development \u0026 Deployment:**\n  - Local PostgreSQL integration via Docker Compose.\n  - Tested using **Vitest** and **Supertest**.\n  - Continuous Integration (CI) setup with **GitHub Actions** to prepare for deployment on every push to the main branch.\n\n## Tech Stack\n\n- [Node.js](https://nodejs.org/) / [Express 5](https://expressjs.com/)\n- [TypeScript](https://www.typescriptlang.org/)\n- [Zod](https://zod.dev) for validation\n- [Winston](https://github.com/winstonjs/winston) for logging\n- [Multer](https://github.com/expressjs/multer) for file uploads\n- [JWT](https://jwt.io/) for authentication\n- [Prisma](https://www.prisma.io/) ORM + PostgreSQL\n- [Vitest](https://vitest.dev/) + [Supertest](https://www.npmjs.com/package/supertest) for testing\n- [Docker Compose](https://docs.docker.com/compose/) for PostgreSQL\n- [Sharp](https://sharp.pixelplumbing.com/) for image metadata and processing\n\n## Local Development\n\n### Prerequisites\n\n- [Node.js](https://nodejs.org/) (tested on v22 but v20 should be fine too)\n- [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/)\n\n### Installation\n\n1. **Clone the repository:**\n\n   ```bash\n   git clone https://github.com/hussein-m-kandil/generic-express-service.git\n   cd generic-express-service\n   ```\n\n2. **Install dependencies:**\n\n   ```bash\n   npm install\n   ```\n\n3. **Set up the environment variables:**\n\n   ```bash\n   cp .env.test .env\n   # Then edit `.env` to fit your local setup\n   ```\n\n4. **Start the PostgreSQL service:**\n\n   ```bash\n   npm run pg:up\n   ```\n\n5. **Push the Prisma schema to the database:**\n\n   ```bash\n   npx prisma db push\n   ```\n\n6. **Seed the database (optional):**\n\n   ```bash\n   npm run db:seed\n   ```\n\n7. **Start the development server:**\n\n   ```bash\n   npm run dev\n   ```\n\n   The API will be available at `http://localhost:8080`.\n\n### Running Tests\n\n```bash\n# Prepare the test DB\nnpm run test:db:push\n# Run all tests in watch mode. Append `-- --run` for single run\nnpm run test\n```\n\n### Scripts\n\n- `npm run dev` — Start development server with hot reload.\n- `npm run build` — Build TypeScript project.\n- `npm start` — Run compiled server.\n- `npm run lint` — Lint source files.\n- `npm run type-check` — TypeScript type checks only.\n- `npm run test` — Run tests with Vitest + Supertest.\n- `npm run db:reset` — Reset Prisma migrations (skip seed).\n- `npm run db:seed` — Seed database with sample data.\n- `npm run pg:up` — Start PostgreSQL via Docker Compose.\n- `npm run pg:stop` — Stop PostgreSQL container.\n- `npm run pg:down` — Remove PostgreSQL container.\n\n### Manual Testing\n\nThere 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`.\n\n## Deployment\n\nEvery _push_ or _pull request (PR)_ on main branch, the app will be deployed to production automatically _if it passes all tests and checks performed by [a GitHub action for deployment preparation](./.github/workflows/deployment-prep.yml)_.\n\n## Notes\n\n- CORS is configured to allow only specific front-end origins under my control.\n\n- JWT-based authentication is implemented and required by some endpoint.\n\n- The `Bearer` schema is included in the authentication response, so the token should be sent _as is_ in an `Authorization` header.\n\n- 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:\n\n  ```json\n  {\n    \"error\": {\n      \"message\": \"An example error\"\n    }\n  }\n  ```\n\n- A validation error response body will have the form of _[ZodError.issues](https://zod.dev/?id=error-handling)._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhussein-m-kandil%2Fgeneric-express-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhussein-m-kandil%2Fgeneric-express-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhussein-m-kandil%2Fgeneric-express-service/lists"}