A complete microservice-based ride-sharing application with Docker containerization.
- Docker (v20.10 or higher)
- Docker Compose (v2.0 or higher)
-
Clone the repository
git clone <repository-url> cd Ride-Sharing-System
-
Run the Docker setup script
npm run docker:setup
Or manually:
chmod +x docker-setup.sh ./docker-setup.sh
-
Access the application
- Frontend: http://localhost:3000
- User Service: http://localhost:3001
- Ride Service: http://localhost:3002
- Payment Service: http://localhost:3003
- Admin Service: http://localhost:3004
The application runs in 6 containers:
| Service | Port | Description |
|---|---|---|
| MongoDB | 27017 | Database with authentication |
| User Service | 3001 | Authentication & user management |
| Ride Service | 3002 | Ride requests & applications |
| Payment Service | 3003 | Payment processing |
| Admin Service | 3004 | Admin dashboard |
| Frontend | 3000 | React application |
# Start all services
npm run docker:up
# Stop all services
npm run docker:down
# Build and start (force rebuild)
npm run docker:build
# View logs
npm run docker:logs
# Clean up everything (including volumes)
npm run docker:clean# Start services in background
docker-compose up -d
# Start services with logs
docker-compose up
# Stop services
docker-compose down
# Rebuild and start
docker-compose up --build -d
# View service status
docker-compose ps
# View logs for specific service
docker-compose logs -f user-service
# Execute commands in container
docker-compose exec user-service shMongoDB is automatically initialized with:
- Authentication:
admin/password123 - Databases:
ride-sharing-usersride-sharing-ridesride-sharing-paymentsride-sharing-admin
- Collections: Automatically created with proper indexes
- Test Admin User:
admin@ridesystem.com/admin123
All environment variables are configured in docker-compose.yml:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password123MONGODB_URI: mongodb://admin:password123@mongodb:27017/ride-sharing-users?authSource=admin
JWT_SECRET: your-super-secret-jwt-key-change-in-productionMONGODB_URI: mongodb://admin:password123@mongodb:27017/ride-sharing-rides?authSource=admin
USER_SERVICE_URL: http://user-service:3001MONGODB_URI: mongodb://admin:password123@mongodb:27017/ride-sharing-payments?authSource=admin
RIDE_SERVICE_URL: http://ride-service:3002
USER_SERVICE_URL: http://user-service:3001MONGODB_URI: mongodb://admin:password123@mongodb:27017/ride-sharing-admin?authSource=admin
USER_SERVICE_URL: http://user-service:3001
RIDE_SERVICE_URL: http://ride-service:3002{
"_id": ObjectId,
"email": String,
"password": String,
"name": String,
"role": String,
"phone": String,
"isActive": Boolean,
"createdAt": Date
}{
"_id": ObjectId,
"passengerId": ObjectId,
"pickupLocation": String,
"dropoffLocation": String,
"targetTime": Date,
"desiredFare": Number,
"status": String,
"driverId": ObjectId,
"createdAt": Date
}{
"_id": ObjectId,
"rideRequestId": ObjectId,
"driverId": ObjectId,
"appliedAt": Date
}{
"_id": ObjectId,
"rideRequestId": ObjectId,
"amount": Number,
"paymentMethod": String,
"status": String,
"receiptSentAt": Date,
"createdAt": Date
}-
Port already in use
# Check what's using the port lsof -i :3000 # Stop conflicting services docker-compose down
-
MongoDB connection issues
# Check MongoDB logs docker-compose logs mongodb # Restart MongoDB docker-compose restart mongodb
-
Service not starting
# Check all logs docker-compose logs # Rebuild specific service docker-compose up --build user-service
-
Permission issues (Linux/Mac)
# Make setup script executable chmod +x docker-setup.sh
Each service includes health checks. Check status with:
docker-compose ps# All services
docker-compose logs -f
# Specific service
docker-compose logs -f user-service
# Last 100 lines
docker-compose logs --tail=100Test the services using curl:
# Health check
curl http://localhost:3001/health
# Register user
curl -X POST http://localhost:3001/api/users/register \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"password123","name":"Test User","role":"passenger"}'
# Login
curl -X POST http://localhost:3001/api/users/login \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"password123"}'# Connect to MongoDB
docker-compose exec mongodb mongosh -u admin -p password123
# List databases
show dbs
# Use specific database
use ride-sharing-users
# Show collections
show collectionsFor production deployment:
- Update environment variables in
docker-compose.yml - Use production MongoDB (MongoDB Atlas recommended)
- Set proper JWT secrets
- Configure reverse proxy (nginx/traefik)
- Set up monitoring (Prometheus/Grafana)
- Use Docker secrets for sensitive data
version: '3.8'
services:
mongodb:
image: mongo:6.0
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD}
volumes:
- mongodb_data:/data/db
networks:
- app-network
user-service:
build: ./backend/user-service
environment:
MONGODB_URI: ${MONGODB_URI}
JWT_SECRET: ${JWT_SECRET}
networks:
- app-network
depends_on:
- mongodb- Create service directory in
backend/ - Add Dockerfile
- Update
docker-compose.yml - Add service to npm scripts
# Rebuild specific service
docker-compose up --build user-service
# View service logs
docker-compose logs -f user-service
# Execute commands in service
docker-compose exec user-service sh- Add Redis for caching
- Implement message queues (RabbitMQ)
- Add monitoring and logging
- Set up CI/CD pipeline
- Add automated testing
- Implement rate limiting
- Add API documentation (Swagger)
For issues and questions:
- Check the troubleshooting section
- Review service logs
- Open an issue in the repository