This repository implements a modular user authentication API built with Node.js, Express, and Prisma (PostgreSQL). It demonstrates a production-oriented architecture for authentication and user management, including database migrations, secure password handling, role support, and middleware for authorization and error handling.
prisma/schema.prisma:Usermodel defined (primaryidasInt) and migrations tracked inprisma/migrations(including a migration that addsrole).- Database connection initialized in
src/database/prisma.jsusing the Prisma client. - Authentication flow implemented across
src/modules/auth/*: registration, login (JWT issuance), and logout (token blacklist insrc/utils/tokenBlacklist.js). - User management endpoints in
src/modules/user/*andsrc/routes/user.routes.js: register, list, and remove users. - Passwords hashed with
bcrypt; tokens managed with JWT. - Middleware:
src/middleware/auth.jsfor protected routes,src/middleware/isAdmin.jsfor role-based access, andsrc/middleware/errorHandler.jsfor centralized error handling. - Project structure separates
controllers,services, andrepositoriesto enforce clear responsibilities and testability. - A compatibility adapter was added so Prisma v7.8 works correctly with the project setup.
- Node.js + Express
- Prisma ORM + PostgreSQL
- bcrypt for password hashing
- JSON Web Tokens (JWT) for authentication
- Create a
.envfile withDATABASE_URLpointing to your Postgres instance. - Install dependencies:
npm install- Start in development mode:
npm run dev- The
User.idis implemented asIntin the Prisma schema to match project requirements and existing migrations. - Role support was added via the migration
20260521012038_add_role. - The repository favors a clean modular layout to simplify maintenance and future extensions (e.g., OAuth providers, email verification).
- Decided to use a blacklist to revoke the tokens easier for now.