Skip to content

abre0101/bus-reservation-system

Repository files navigation

🚌 EthioBus - Bus Booking & Management System

A comprehensive bus ticket booking and management platform designed for Ethiopian bus transportation services. Built with modern web technologies to streamline bus operations, ticket booking, and passenger management.

οΏ½ Table of Contents

✨ Features

For Customers

  • 🎫 Online Ticket Booking - Search and book bus tickets with real-time seat availability
  • πŸ”΄ Real-Time Seat Locking - See live seat availability with instant updates (NEW!)
  • πŸ’Ί Visual Seat Selection - Interactive seat map with 4 color-coded status indicators
  • ⚑ Instant Updates - WebSocket-powered real-time synchronization across all users (<100ms)
  • πŸ”’ Temporary Seat Reservation - Automatic 10-minute seat locks during booking process
  • οΏ½ *Persistent Selection - Your seat selection is saved even after page refresh
  • 🎨 Smart Visual Feedback - Green (available), Blue (your selection), Orange (locked by others), Red (booked)
  • οΏ½ *QR Code Tickets - Digital tickets with QR codes for easy check-in
  • πŸ’³ Multiple Payment Options - Support for TeleBirr, CBE Birr, HelloCash, and international cards
  • πŸ“Š Booking History - Track all your past and upcoming trips
  • 🎁 Loyalty Program - Earn rewards for frequent bookings

For Operators

  • 🚍 Bus Management - Add, edit, and manage bus fleet information
  • πŸ—ΊοΈ Route Management - Create and manage bus routes with multiple stops
  • ⏰ Schedule Management - Set up recurring and one-time schedules
  • πŸ‘¨β€βœˆοΈ Driver Assignment - Assign drivers to specific schedules
  • πŸ“Š Analytics Dashboard - View booking statistics and revenue reports
  • 🎟️ Ticketer System - Dedicated interface for ticket verification and check-in
  • πŸ“‹ Bus Reports Management - View, filter, and manage all driver-submitted bus reports
  • πŸ”„ Report Status Updates - Update report status (pending β†’ in progress β†’ resolved)
  • πŸ“ Operator Notes - Add notes and actions taken for each report
  • πŸ“€ Export Reports - Export filtered reports to CSV or Excel for analysis

For Drivers

  • πŸ“± Driver Mobile App - Dedicated interface for drivers
  • βœ… Passenger Check-in - Scan QR codes to verify tickets
  • πŸ—ΊοΈ Route Information - View assigned routes and schedules
  • πŸ“Š Trip Reports - Track completed trips and passenger counts
  • πŸ“‹ Bus Reporting System - Submit maintenance, fuel, and issue reports with severity levels
  • πŸ”§ Quick Report Templates - Pre-configured templates for common bus issues
  • πŸ“ˆ Report History - View status of submitted reports and operator responses

For Admins

  • πŸ‘€ User Management - Manage all system users and roles
  • πŸ’° Payment Tracking - Monitor all transactions and refunds
  • 🚨 Emergency Controls - Cancel schedules and handle emergencies
  • βš™οΈ System Settings - Configure tariffs, fees, and system parameters
  • πŸ“Š Comprehensive Reports - Generate detailed analytics and reports

οΏ½ Tec h Stack

Frontend

  • React 18 - Modern UI library
  • Vite - Fast build tool and dev server
  • Socket.io-client 4.7 - WebSocket client for real-time updates (NEW!)
  • React Router - Client-side routing
  • Tailwind CSS - Utility-first CSS framework
  • Axios - HTTP client
  • Chart.js & Recharts - Data visualization
  • React Hook Form - Form management
  • QRCode.react - QR code generation
  • React Toastify - Toast notifications
  • Lucide React - Icon library

Backend

  • Flask 2.3 - Python web framework
  • Flask-SocketIO 5.3 - WebSocket support for real-time features (NEW!)
  • MongoDB - NoSQL database
  • PyMongo - MongoDB driver
  • Flask-JWT-Extended - JWT authentication
  • Flask-Bcrypt - Password hashing
  • Flask-CORS - Cross-origin resource sharing
  • Stripe - Payment processing (international)

Payment Gateways

  • Chapa (TeleBirr, CBE Birr, HelloCash)
  • Stripe (International cards)
  • Cash payments

πŸ“ Project Structure

ethiobus/
β”œβ”€β”€ backend/                    # Flask backend application
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ routes/            # API route handlers
β”‚   β”‚   β”œβ”€β”€ utils/             # Utility functions
β”‚   β”‚   β”‚   β”œβ”€β”€ seat_lock.py   # Seat locking logic (NEW!)
β”‚   β”‚   β”‚   └── cleanup_locks.py # Lock cleanup task (NEW!)
β”‚   β”‚   β”œβ”€β”€ models.py          # Data models and enums
β”‚   β”‚   β”œβ”€β”€ socket_events.py   # WebSocket event handlers (NEW!)
β”‚   β”‚   └── __init__.py        # App factory
β”‚   β”œβ”€β”€ config/                # Configuration files
β”‚   β”œβ”€β”€ middleware/            # Custom middleware
β”‚   β”œβ”€β”€ .env                   # Environment variables
β”‚   β”œβ”€β”€ requirements.txt       # Python dependencies
β”‚   β”œβ”€β”€ test_seat_locking.py   # Seat locking tests (NEW!)
β”‚   └── run.py                 # Application entry point
β”‚
β”œβ”€β”€ frontend/                  # React frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/        # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ pages/             # Page components
β”‚   β”‚   β”œβ”€β”€ contexts/          # React contexts
β”‚   β”‚   β”œβ”€β”€ hooks/             # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ services/          # API service layer
β”‚   β”‚   β”‚   └── socketService.js # WebSocket client (NEW!)
β”‚   β”‚   β”œβ”€β”€ utils/             # Utility functions
β”‚   β”‚   β”œβ”€β”€ styles/            # CSS and styling
β”‚   β”‚   β”œβ”€β”€ App.jsx            # Main app component
β”‚   β”‚   └── main.jsx           # Application entry point
β”‚   β”œβ”€β”€ public/                # Static assets
β”‚   β”œβ”€β”€ .env                   # Environment variables
β”‚   β”œβ”€β”€ package.json           # Node dependencies
β”‚   β”œβ”€β”€ vite.config.js         # Vite configuration
β”‚   └── tailwind.config.js     # Tailwind configuration
β”‚
└── README.md                  # Project documentation

πŸ“¦ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v16 or higher)
  • Python (v3.8 or higher)
  • MongoDB (v4.4 or higher)
  • npm or yarn
  • pip (Python package manager)

πŸš€ Installation

1. Clone the Repository

git clone https://github.com/yourusername/ethiobus.git
cd ethiobus

2. Backend Setup

# Navigate to backend directory
cd backend

# Create virtual environment
python -m venv venv

# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

3. Frontend Setup

# Navigate to frontend directory
cd frontend

# Install dependencies
npm install
# or
yarn install

βš™οΈ Configuration

Backend Configuration

Create a .env file in the backend directory:

# Flask Configuration
SECRET_KEY=your-secret-key-here
DEBUG=True
PORT=5000

# Database Configuration
MONGO_URI=mongodb://localhost:27017/ethiobusdb

# JWT Configuration
JWT_SECRET_KEY=your-jwt-secret-key-here

# Chapa Payment Configuration (Ethiopian Payment Gateway)
CHAPA_SECRET_KEY=your-chapa-secret-key
CHAPA_PUBLIC_KEY=your-chapa-public-key
CHAPA_BASE_URL=https://api.chapa.co/v1

# Stripe Configuration (International Payments)
STRIPE_SECRET_KEY=your-stripe-secret-key
STRIPE_PUBLIC_KEY=your-stripe-public-key

Frontend Configuration

Create a .env file in the frontend directory:

# API Configuration
VITE_API_URL=http://localhost:5000

# Payment Configuration
VITE_CHAPA_PUBLIC_KEY=your-chapa-public-key
VITE_STRIPE_PUBLIC_KEY=your-stripe-public-key

MongoDB Setup

  1. Install MongoDB on your system

  2. Start MongoDB service:

    # Windows
    net start MongoDB
    
    # macOS
    brew services start mongodb-community
    
    # Linux
    sudo systemctl start mongod
  3. The database ethiobusdb will be created automatically on first run

πŸƒ Running the Application

Start Backend Server (with WebSocket support)

cd backend
python run.py

The backend server will start on http://localhost:5000 with WebSocket support enabled.

Start Seat Lock Cleanup Task (Recommended)

Open a new terminal:

cd backend
python -m app.utils.cleanup_locks

This background task automatically removes expired seat locks every 60 seconds.

Start Frontend Development Server

cd frontend
npm run dev
# or
yarn dev

The frontend will start on http://localhost:5173

Access the Application

Open your browser and navigate to:

πŸ“š API Documentation

Base URL

http://localhost:5000

Main Endpoints

Authentication

  • POST /auth/register - Register new user
  • POST /auth/login - User login
  • POST /auth/logout - User logout
  • GET /auth/profile - Get user profile

Bookings

  • GET /bookings - Get all bookings
  • POST /bookings - Create new booking
  • GET /bookings/:id - Get booking details
  • PUT /bookings/:id - Update booking
  • DELETE /bookings/:id - Cancel booking

Schedules

  • GET /schedules - Get all schedules
  • POST /schedules - Create schedule (operator/admin)
  • GET /schedules/:id - Get schedule details
  • PUT /schedules/:id - Update schedule
  • DELETE /schedules/:id - Delete schedule

Routes

  • GET /routes - Get all routes
  • POST /routes - Create route (operator/admin)
  • GET /routes/:id - Get route details
  • PUT /routes/:id - Update route

Buses

  • GET /buses - Get all buses
  • POST /buses - Add new bus (operator/admin)
  • GET /buses/:id - Get bus details
  • PUT /buses/:id - Update bus

Payments

  • POST /payments/initialize - Initialize payment
  • POST /payments/verify - Verify payment
  • GET /payments/:id - Get payment details

Admin

  • GET /admin/users - Get all users
  • PUT /admin/users/:id - Update user
  • DELETE /admin/users/:id - Delete user
  • GET /admin/statistics - Get system statistics

Bus Reports

  • POST /driver/bus-reports - Submit bus report (driver)
  • GET /driver/bus-reports - Get driver's reports
  • GET /operator/bus-reports - Get all bus reports (operator)
  • PATCH /operator/bus-reports/:id - Update report status and notes
  • GET /operator/bus-reports/stats - Get report statistics

πŸ‘₯ User Roles

Customer

  • Book tickets
  • View booking history
  • Make payments
  • Receive notifications

Driver

  • View assigned schedules
  • Check-in passengers
  • Update trip status
  • View route information
  • Submit bus reports (maintenance, issues, fuel status)
  • Track report status and operator responses

Operator

  • Manage buses
  • Create routes and schedules
  • Assign drivers
  • View analytics
  • Manage bus reports from drivers
  • Update report status and add notes
  • Export reports for maintenance planning

Admin

  • Full system access
  • User management
  • System configuration
  • Emergency controls

πŸ’³ Payment Integration

Supported Payment Methods

  1. TeleBirr - Ethiopian mobile money
  2. CBE Birr - Commercial Bank of Ethiopia mobile banking
  3. HelloCash - Ethiopian mobile wallet
  4. Bank Transfer - Direct bank transfers
  5. Stripe - International credit/debit cards
  6. Cash - Pay at station

Payment Flow

  1. Customer selects seats and proceeds to payment
  2. System calculates total amount (base fare + fees)
  3. Customer chooses payment method
  4. Payment gateway processes transaction
  5. System verifies payment and confirms booking
  6. Customer receives ticket with QR code

πŸ§ͺ Testing

Backend Tests

cd backend
pytest

Frontend Tests

cd frontend
npm run test
# or
yarn test

πŸ”’ Security Features

  • JWT-based authentication
  • Password hashing with bcrypt
  • CORS protection
  • Input validation and sanitization
  • Secure payment processing
  • Role-based access control

🌐 Deployment

Backend Deployment (Example with Heroku)

# Login to Heroku
heroku login

# Create new app
heroku create ethiobus-api

# Set environment variables
heroku config:set SECRET_KEY=your-secret-key
heroku config:set MONGO_URI=your-mongodb-uri

# Deploy
git push heroku main

Frontend Deployment (Example with Vercel)

# Install Vercel CLI
npm install -g vercel

# Deploy
cd frontend
vercel

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a 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 Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Authors

  • Your Name - Initial work

πŸ™ Acknowledgments

  • Ethiopian bus transportation industry
  • Open source community
  • All contributors

πŸ“ž Support

For support, email support@ethiobus.com or join our Slack channel.

🎯 Real-Time Seat Locking Features

How It Works

  1. Instant Seat Locking - When you select a seat, it's immediately locked for 10 minutes

  2. Visual Indicators - 4 color-coded states:

    • 🟒 Green - Available (click to select)
    • πŸ”΅ Blue - Your selection (click to deselect)
    • 🟠 Orange - Locked by another user (wait or choose different seat)
    • πŸ”΄ Red - Booked (confirmed booking)
  3. Persistent Selection - Your seat selection is saved in the database and restored after page refresh

  4. Automatic Cleanup - Expired locks (10+ minutes old) are automatically removed

  5. Zero Race Conditions - Database-level validation prevents double bookings

  6. Real-Time Updates - All users see seat changes instantly (<100ms latency)

Testing Seat Locking

cd backend
python test_seat_locking.py

All 7 tests should pass:

  • βœ… Lock seats for User A
  • βœ… Prevent User B from locking same seats
  • βœ… Get locked seats for schedule
  • βœ… Unlock seats for User A
  • βœ… Confirm seat locks after booking
  • βœ… Test lock expiration
  • βœ… Lock seats for User B after expiration

Documentation

Comprehensive documentation available:

  • FINAL_SUMMARY.md - Complete overview
  • QUICK_REFERENCE.md - Quick commands and troubleshooting
  • SEAT_LOCK_BEHAVIOR.md - Detailed behavior explanation
  • START_WITH_WEBSOCKET.md - Getting started guide
  • README_WEBSOCKET_IMPLEMENTATION.md - Technical implementation details

πŸ—ΊοΈ Roadmap

  • Real-time seat locking with WebSocket (COMPLETED!)
  • Temporary seat reservations with auto-expiration (COMPLETED!)
  • Visual seat selection with 4 color states (COMPLETED!)
  • Persistent seat selection across page refresh (COMPLETED!)
  • Bus reporting system for drivers and operators
  • Export functionality for bus reports
  • Mobile app for iOS and Android
  • Real-time bus tracking with GPS
  • Multi-language support (Amharic, Oromo, Tigrinya)
  • Advanced analytics and reporting
  • Integration with more payment gateways
  • Customer review and rating system
  • Automated refund processing
  • SMS notifications
  • WhatsApp integration
  • Automated maintenance scheduling based on reports
  • Push notifications for critical bus issues

Made with ❀️ for Ethiopian bus transportation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published