A GraphQL API backend built with Node.js, Express, Prisma, and PostgreSQL.
- GraphQL API with comprehensive schema
- Authentication with JWT tokens
- Role-based permissions (Root and Admin users)
- Database integration with Prisma ORM
- Input validation with custom scalars
- Security with bcrypt password hashing
- CORS support for frontend integration
- Node.js (v18 or higher)
- PostgreSQL database
- npm or yarn
- Clone the repository:
git clone <repository-url>
cd qmr-backend- Install dependencies:
npm install- Set up environment variables:
Create a
.envfile in the root directory with the following variables:
# Server Configuration
PORT=4000
NODE_ENV=development
# Database Configuration
DATABASE_URL="postgresql://username:password@localhost:5432/qmr_database"
# JWT Configuration
JWT_SECRET="your-super-secret-jwt-key-here"
JWT_EXPIRES_IN="10d"
# CORS Configuration
CORS_ORIGIN="http://localhost:5173"
# Security
BCRYPT_ROUNDS=10- Set up the database:
# Generate Prisma client
npm run db:generate
# Run database migrations
npm run db:migratenpm run devnpm start# Generate Prisma client
npm run db:generate
# Push schema changes
npm run db:push
# Run migrations
npm run db:migrate
# Open Prisma Studio
npm run db:studio- GraphQL:
http://localhost:4000/graphql - Health Check:
http://localhost:4000/health
me: Get current user informationgetAdmins: Get all admin users (Admin/Root only)getAdmin(id): Get specific admin by ID (Admin/Root only)
login(username, password, userType): User authenticationaddAdmin(...): Create new admin user (Root only)
Root: Root user typeAdmin: Admin user typeUser: Union of Root and AdminLoginResponse: Login response with token and user info
- JWT-based authentication
- Role-based access control
- Password hashing with bcrypt
- Input validation and sanitization
- CORS protection
- SQL injection prevention (Prisma ORM)
The project uses ES modules and includes:
- Comprehensive error handling
- Database connection pooling
- Graceful shutdown handling
- Development vs production configurations
- Detailed logging
ISC