Built with passion, designed for scale
Velocia is a production-ready, scalable backend API for modern ride-sharing platforms. Built with cutting-edge technologies and best practices, it provides a robust foundation for transportation applications with real-time capabilities, secure authentication, and comprehensive administrative controls.
|
|
graph TB
subgraph "Client Layer"
A[Mobile Application]
B[Web Application]
C[Admin Dashboard]
end
subgraph "API Gateway"
D[Load Balancer]
F[API Router]
end
subgraph "Service Layer"
G[Auth Service]
H[User Service]
I[Ride Service]
J[Driver Service]
K[Payment Service]
end
subgraph "Data Layer"
L[(MongoDB)]
M[(Redis Cache)]
N[Message Queue]
end
A & B & C --> D
D --> F
F --> G & H & I & J & K
G & H & I & J & K --> L
G & H & I & J & K --> M
I & J --> N
| Design Principle | Description |
|---|---|
| π― Microservice-Ready | Modular architecture that can be easily decomposed into microservices |
| π Horizontal Scalability | Built to scale out with increased load |
| π Security-First | Security considerations at every architectural layer |
| π Event-Driven | Asynchronous communication patterns for better performance |
| π Observable | Comprehensive logging, monitoring, and tracing capabilities |
|
TypeScript |
Node.js |
Express |
MongoDB |
Redis |
Vercel |
| Category | Technologies | Purpose |
|---|---|---|
| π Security | JWT Passport.js Bcrypt |
Authentication & protection |
| β Validation | Zod Mongoose |
Validation & object modeling |
| π§ Communication | Nodemailer Socket.io |
Email & real-time |
| π§ͺ Testing | Postman |
Endpoint tests |
| π Deployment | Vercel |
Cloud deployment |
# 1. Clone the repository
git clone https://github.com/zahid-official/milestone-17-velociaServer.git
cd milestone-17-velociaServer
# 2. Install dependencies
npm install
# 3. Set up environment variables (Windows)
copy .env.example .env
# Edit .env with your configuration
# 4. Start development server
npm run dev
# 5. Access the API
# http://localhost:5000/api/v1For easier setup without local MongoDB installation:
-
Create free account at MongoDB Atlas
-
Create a cluster and get connection string
-
Update
.envwith your connection string:MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/velociaDB
Click to view essential .env variables
# Server Configuration
NODE_ENV=development | production
PORT=5000
# Database Configuration
DB_URL=mongodb+srv://username:password@cluster.mongodb.net/velociaDB?retryWrites=true&w=majority&appName=Cluster1
# OR Local MongoDB
# DB_URL=mongodb://localhost:27017/velociaDB
# JWT Configuration
JWT_ACCESS_SECRET=your-jwt-access-secret-change-this
JWT_ACCESS_EXPIRESIN=24h
JWT_REFRESH_SECRET=your-jwt-refresh-secret-change-this
JWT_REFRESH_EXPIRESIN=90d
# Express Session Configuration
EXPRESS_SESSION_SECRET=your-express-session-secret-change-this
# Bcrypt Configuration
BCRYPT_SALT_ROUNDS=10
# Frontend Configuration
FRONTEND_URL=http://localhost:5173
# Default Admin Credentials
DEFAULT_ADMIN_EMAIL=primary@email.com
DEFAULT_ADMIN_PASSWORD=primary@Admin01
# Redis Configuration
RADIS_HOST=your-redis-host
RADIS_PORT=your-redis-port
RADIS_USERNAME=default
RADIS_PASSWORD=your-redis-password
# SMTP Configuration
SMTP_PORT=465
SMTP_HOST=smtp.gmail.com
SMTP_FROM=your-email@gmail.com
SMTP_USERNAME=your-email@gmail.com
SMTP_PASSWORD=your-app-passwordDevelopment: http://localhost:5000/api/v1
Production: https://velocia-api.vercel.app/api/v1π Click to view Authentication Routes
| HTTP Method | Endpoint | Description | Authentication Required |
|---|---|---|---|
GET |
/auth/regenerate-token |
Generate new access token using refresh token | No |
POST |
/auth/login |
Authenticate user with credentials | No |
POST |
/auth/logout |
Invalidate current user session | No |
POST |
/auth/sendOTP |
Send OTP for verification purposes | No |
POST |
/auth/verifyOTP |
Verify OTP code for authentication | No |
PATCH |
/auth/forgot-password |
Initiate password reset process | No |
PATCH |
/auth/reset-password |
Complete password reset with verification | Yes (Any Role) |
PATCH |
/auth/change-password |
Update user password | Yes (Any Role) |
π€ Click to view User Management Routes
| HTTP Method | Endpoint | Description | Authentication Required |
|---|---|---|---|
GET |
/user/ |
Retrieve all registered users | Yes (Admin Only) |
GET |
/user/singleUser/:id |
Retrieve specific user by ID | Yes (Admin Only) |
GET |
/user/profile |
Retrieve current user profile information | Yes (Any Role) |
POST |
/user/register |
Create new user account | No |
PATCH |
/user/update/:id |
Update user account information | Yes (Owner/Admin) |
PATCH |
/user/block/:id |
Block user account | Yes (Admin Only) |
PATCH |
/user/unblock/:id |
Unblock user account | Yes (Admin Only) |
π Click to view Driver Management Routes
| HTTP Method | Endpoint | Description | Authentication Required |
|---|---|---|---|
GET |
/driver/ |
Retrieve all driver applications | Yes (Admin Only) |
GET |
/driver/singleDriver/:driverId |
Retrieve specific driver information | Yes (Admin Only) |
GET |
/driver/earnings |
View driver earnings history | Yes (Driver Only) |
POST |
/driver/apply |
Submit driver application | Yes (Any Role) |
PATCH |
/driver/updateDetails/:driverId |
Update driver account details | Yes (Owner/Admin) |
PATCH |
/driver/approve/:driverId |
Approve driver application | Yes (Admin Only) |
PATCH |
/driver/reject/:driverId |
Reject driver application | Yes (Admin Only) |
PATCH |
/driver/suspend/:driverId |
Suspend driver account | Yes (Admin Only) |
PATCH |
/driver/unsuspend/:driverId |
Reactivate suspended driver account | Yes (Admin Only) |
PATCH |
/driver/availability/:driverId |
Update driver availability status | Yes (Driver Only) |
ποΈ Click to view Ride Management Routes
| HTTP Method | Endpoint | Description | Authentication Required |
|---|---|---|---|
GET |
/ride/ |
Retrieve all platform rides | Yes (Admin Only) |
GET |
/ride/singleRide/:rideId |
Retrieve specific ride details | Yes (Admin Only) |
GET |
/ride/requestedRides |
View available ride requests | Yes (Driver/Admin) |
GET |
/ride/history |
Retrieve rider's complete ride history | Yes (Rider Only) |
POST |
/ride/request |
Request a new ride | Yes (Rider Only) |
PATCH |
/ride/cancel/:rideId |
Cancel pending ride request | Yes (Rider Only) |
PATCH |
/ride/accept/:rideId |
Accept ride request | Yes (Driver Only) |
PATCH |
/ride/reject/:rideId |
Reject ride request | Yes (Driver Only) |
PATCH |
/ride/pickUp/:rideId |
Confirm rider pickup | Yes (Driver Only) |
PATCH |
/ride/inTransit/:rideId |
Update ride status to in transit | Yes (Driver Only) |
PATCH |
/ride/complete/:rideId |
Mark ride as completed | Yes (Driver Only) |
All API responses follow this consistent structure:
{
"success": true,
"statusCode": 200,
"message": "Operation completed successfully",
"data": {
"Response payload"
},
"meta": {
"page": 2,
"limit": 10,
"totalPage": 25,
"totalDoc": 245
}
}{
"success": false,
"statusCode": 400,
"message": "Validation error",
"error": {
"code": "VALIDATION_ERROR",
"details": [
{
"field": "email",
"message": "Invalid email format"
}
]
}
}graph TD
A[Administrator] --> B[Full System Access]
C[Driver] --> D[Ride Operations]
E[Rider] --> F[Ride Booking]
B --> G[User Management]
B --> H[Driver Management]
B --> I[Platform Analytics]
D --> J[Accept/Reject Rides]
D --> K[Manage Availability]
D --> L[View Earnings]
F --> M[Request Rides]
F --> N[View History]
F --> O[Rate Drivers]
Administrators have comprehensive platform oversight with full system access. Key responsibilities include:
- User Management: Complete control over user accounts, including creation, modification, and deactivation
- Driver Operations: Review and process driver applications, manage driver status and permissions
- Platform Oversight: Access to all rides, transactions, and system analytics
- System Administration: Configuration management and platform maintenance capabilities
- Dispute Resolution: Handle customer service issues and ride disputes
Riders represent the customer base with access to core ride-booking functionality:
- Account Management: Personal profile creation, modification, and maintenance
- Ride Services: Request rides with specified pickup locations and destinations
- Ride Management: Cancel rides within allowed timeframes and track ride progress
- History Access: View complete ride history with detailed trip information
- Service Interaction: Rate drivers and provide feedback on completed rides
Drivers are service providers with specialized tools for ride fulfillment:
- Application Process: Submit applications for platform approval with required documentation
- Ride Operations: Accept or reject ride requests based on availability and preferences
- Service Delivery: Manage complete ride lifecycle from pickup to completion
- Financial Tracking: Access earnings history and payment information
- Availability Control: Set online/offline status and manage working hours
JWT Implementation
- Stateless authentication using JSON Web Tokens
- Dual-token system with access and refresh tokens
- Automatic token refresh for seamless user experience
- Secure token storage and transmission practices
Password Security
- bcrypt hashing with configurable salt rounds
- Password complexity requirements and validation
- Secure password reset process with OTP verification
- Protection against common password attacks
Role-Based Access Control
- Granular permission system based on user roles
- Resource-level access control for sensitive operations
- Dynamic permission validation for all protected endpoints
- Inheritance-based permission structure for scalability
Encryption Standards
- Data encryption at rest and in transit
- Secure communication protocols (HTTPS)
- Database connection encryption
- API endpoint security headers
Privacy Controls
- Personal data protection compliance
- User consent management
- Data retention policies
- Secure data deletion procedures
project/
βββ π src/
β βββ π app/
β β βββ π config/ # Application configuration
β β β βββ π env.ts # Environment variable management
β β β βββ π env.interface.ts # Environment type definitions
β β β βββ π passport.ts # Authentication strategy configuration
β β β βββ π redis.ts # Redis connection setup
β β β
β β βββ π errors/ # Error handling
β β β βββ π AppError.ts # Custom application error class
β β β
β β βββ π interfaces/ # Global type definitions
β β β βββ π index.d.ts # Shared interface declarations
β β β
β β βββ π middlewares/ # Express middleware functions
β β β βββ π globalErrorHandler.ts # Centralized error handling
β β β βββ π notFoundHandler.ts # 404 error handling
β β β βββ π validateSchema.ts # Request validation middleware
β β β βββ π validateToken.ts # Authentication middleware
β β β
β β βββ π modules/ # Feature-based modules
β β β βββ π auth/ # Authentication services
β β β β βββ π auth.controller.ts
β β β β βββ π auth.routes.ts
β β β β βββ π auth.service.ts
β β β β βββ π auth.validation.ts
β β β β
β β β βββ π user/ # User management
β β β β βββ π user.controller.ts
β β β β βββ π user.interface.ts
β β β β βββ π user.model.ts
β β β β βββ π user.routes.ts
β β β β βββ π user.service.ts
β β β β βββ π user.validation.ts
β β β β
β β β βββ π driver/ # Driver operations
β β β β βββ π driver.controller.ts
β β β β βββ π driver.interface.ts
β β β β βββ π driver.model.ts
β β β β βββ π driver.routes.ts
β β β β βββ π driver.service.ts
β β β β βββ π driver.validation.ts
β β β β
β β β βββ π ride/ # Ride management
β β β βββ π ride.controller.ts
β β β βββ π ride.interface.ts
β β β βββ π ride.model.ts
β β β βββ π ride.routes.ts
β β β βββ π ride.service.ts
β β β βββ π ride.validation.ts
β β β
β β βββ π routes/ # Route aggregation
β β β βββ π index.ts # Main route configuration
β β β
β β βββ π utils/ # Utility functions
β β βββ π catchAsync.ts # Async error handling
β β βββ π constants.ts # Application constants
β β βββ π JWT.ts # JWT utility functions
β β βββ π sendResponse.ts # Standardized response formatting
β β βββ π templates/ # Email templates
β β βββ π forgotPassword.ejs
β β βββ π sendOtp.ejs
β β
β βββ π app.ts # Express application setup
β βββ π server.ts # Server bootstrap and initialization
β
βββ π .env.example # Environment example
βββ π .gitignore # Git ignore rules
βββ π package.json # Dependencies
βββ π tsconfig.json # TypeScript config
βββ π eslint.config.mjs # Eslint config
βββ π README.md # This file
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel
# Set environment variables
vercel env add MONGODB_URI
vercel env add JWT_ACCESS_SECRET
# Deploy to production
vercel --prod{
"version": 2,
"builds": [
{
"src": "dist/server.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "dist/server.js"
}
]
}Contributions make the open source community amazing! Any contributions you make are greatly appreciated.
1. Fork the Project
2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
3. Commit your Changes (git commit -m 'Add some AmazingFeature')
4. Push to the Branch (git push origin feature/AmazingFeature)
5. Open a Pull RequestVelocia - A modern transportation backend solution.
