A robust, scalable backend API for a ride-sharing application built with Node.js, Express, PostgreSQL, Redis, and Prisma.
- Authentication & Authorization: Secure JWT-based authentication system
- Ride Management: Create, accept, track, and complete rides
- User Management: User profiles for both riders and drivers
- Data Persistence: PostgreSQL database with Prisma ORM
- Caching: Redis for enhanced performance and rate limiting
- API Protection: Rate limiting, CORS configuration, and security headers
- Containerization: Docker and Docker Compose for easy deployment
- Logging: Comprehensive logging system with Winston
- Runtime: Node.js (v18+)
- Framework: Express.js
- Database: PostgreSQL
- ORM: Prisma
- Caching: Redis
- Authentication: JWT (JSON Web Tokens)
- API Validation: Express Validator, Zod
- Logging: Winston
- Containerization: Docker, Docker Compose
- Security: Helmet, CORS, Rate Limiting
- Node.js 18.x or higher
- Docker and Docker Compose
- npm or yarn
-
Clone the repository:
git clone https://github.com/AmnaMubarak/Ride-Sharing-Web-App-Backend.git cd Ride-Sharing-Web-App-Backend -
Create a
.envfile in the root directory (see.env.examplefor required variables) -
Start the containerized services:
npm run docker:up -
Run database migrations:
npm run prisma:migrate -
The API will be available at
http://localhost:5000
-
Clone the repository
git clone https://github.com/AmnaMubarak/Ride-Sharing-Web-App-Backend.git cd Ride-Sharing-Web-App-Backend -
Install dependencies
npm install -
Start PostgreSQL and Redis with Docker Compose
npm run docker:up -
Set up environment variables (see
.env.example) -
Run database migrations
npm run prisma:migrate -
Start the development server
npm run dev
-
Authentication
POST /api/auth/register- Register a new userPOST /api/auth/login- Login and get JWT token
-
Users
GET /api/users/profile- Get current user profilePUT /api/users/profile- Update user profile
-
Rides
POST /api/rides- Create a new ride request (for riders)GET /api/rides- Get available rides (for drivers)GET /api/rides/history- Get ride historyPATCH /api/rides/:id/accept- Accept a ride (for drivers)PATCH /api/rides/:id/complete- Complete a ridePATCH /api/rides/:id/cancel- Cancel a ride
The application uses two main entities:
- User: Stores user information with roles (RIDER/DRIVER)
- Ride: Manages ride information, status, and relationships
npm start- Start the server in production modenpm run dev- Start the server in development mode with hot reloadnpm test- Run testsnpm run prisma:generate- Generate Prisma clientnpm run prisma:migrate- Run database migrationsnpm run prisma:studio- Open Prisma Studio to inspect databasenpm run docker:up- Start Docker containersnpm run docker:down- Stop Docker containersnpm run db:reset- Reset the database (drops and recreates)
Create a .env file with the following variables:
# App
PORT=5000
NODE_ENV=development
# Database
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/ride_sharing_db
# Redis
REDIS_URL=redis://localhost:6379
# JWT
JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=30d
# Logging
LOG_LEVEL=info