Skip to content

Torikul-048/Railway-Management-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš‚ Railway Management System

A comprehensive web-based railway ticket booking system built with Laravel 12, featuring class-based pricing, real-time seat selection, automated booking management, and admin analytics.

Laravel PHP MySQL TailwindCSS Bootstrap

πŸ“‹ Table of Contents

✨ Features

🎫 Customer Features

Train Search & Booking

  • Advanced Search: Search trains by source, destination, journey date, train number, route, and departure time
  • Real-time Availability: View live seat availability across all coach types
  • Visual Seat Selection: Interactive seat map with color-coded availability
  • Class-based Pricing: Dynamic pricing based on coach type:
    • Sleeper: 1.0x base fare
    • Second Class: 1.3x base fare
    • First Class: 1.8x base fare
    • AC Chair: 2.0x base fare
    • AC First Class: 2.5x base fare
  • Single Passenger Booking: Simplified booking with one passenger per reservation

Booking Management

  • My Bookings Dashboard: View all bookings with status filtering
  • Status Tracking: Real-time booking status (Pending, Confirmed, Cancelled, Completed)
  • Booking Details: Comprehensive view of journey, passenger, and payment information
  • Ticket Download: Generate and download PDF tickets for confirmed bookings
  • Flexible Cancellation: Cancel bookings anytime before departure with time-based refunds:
    • More than 48 hours: 90% refund
    • 24-48 hours: 75% refund
    • 12-24 hours: 50% refund
    • 6-12 hours: 20% refund
    • Less than 6 hours: 10% refund
    • After departure: No cancellation allowed

Payment System

  • Multiple Payment Methods:
    • bKash
    • Nagad
    • Rocket
    • Credit/Debit Card
    • Bank Transfer
  • 5-Minute Payment Window: Countdown timer with automatic expiration
  • Auto-Cancellation: Unpaid bookings automatically cancelled after 5 minutes
  • Seat Release: Seats automatically released back to available pool
  • Instant Confirmation: Immediate booking confirmation upon payment

User Profile

  • Profile Management: Update personal information (name, email, phone, address)
  • Password Security: Change password with validation
  • Account Status: View account status and membership details
  • Booking History: Access complete booking history

πŸ‘¨β€πŸ’Ό Admin Features

Dashboard

  • Real-time Statistics:
    • Total Revenue (confirmed bookings)
    • Active Bookings count
    • Total Registered Users
    • Available Trains
  • Recent Bookings: Quick view of latest 10 bookings with details
  • Visual Analytics: Overview of system activity

Train Management

  • CRUD Operations: Create, Read, Update, Delete trains
  • Train Details:
    • Train name and number
    • Route (source and destination)
    • Departure and arrival times
    • Train type (Express, Mail, Local, Intercity)
    • Facilities (AC, WiFi, Food, etc.)
    • Base fare per seat
  • Search & Filter: Filter trains by type, route, status
  • Validation: Comprehensive input validation

Booking Management

  • Complete Overview: View all bookings across the system
  • Advanced Filters:
    • Filter by booking status
    • Filter by train
    • Search by booking reference or passenger name
    • Date range filtering
  • Booking Actions:
    • View detailed booking information
    • Update booking status
    • Cancel bookings with refund calculation
    • View passenger details
    • Track payment information
  • Refund Processing: Automatic refund calculation based on cancellation time

User Management

  • User CRUD: Complete user management system
  • Role Assignment: Assign roles (Admin, Staff, Customer)
  • User Search: Search by name, email, or role
  • Account Status: Activate/deactivate user accounts
  • User Details: View user profile and booking history

Reports & Analytics

  • Revenue Dashboard with Chart.js visualizations:
    • Monthly Revenue Chart: Bar chart showing revenue trends
    • Booking Status Distribution: Pie chart of booking statuses
    • Popular Routes Chart: Horizontal bar chart of top routes
  • Booking Statistics:
    • Total bookings and confirmed bookings count
    • Total and average revenue
    • Cancellation rate
  • Recent Bookings Table: Detailed list with passenger info
  • Export Functionality: Generate reports for specific date ranges

Route Management

  • Popular Routes: Track and manage frequently booked routes
  • Route Statistics: View booking counts per route
  • Route Analysis: Identify profitable routes

System Settings

  • Application Settings: Configure system-wide settings
  • Email Configuration: Set up email notifications
  • Payment Gateway: Configure payment methods
  • System Maintenance: Manage system maintenance mode

πŸ› οΈ Tech Stack

Backend

  • Framework: Laravel 12.32.5
  • PHP: 8.4.0
  • Database: MySQL 8.0
  • Authentication: Laravel Breeze
  • Queue: Laravel Queue for background jobs

Frontend

  • CSS Frameworks:
    • Tailwind CSS 3.4 (Customer interface)
    • Bootstrap 5.3 (Admin panel)
  • JavaScript: Alpine.js for interactive components
  • Charts: Chart.js 4.4.0 for analytics
  • Build Tool: Vite 5.x

Design Patterns Implemented

  • Adapter Pattern: Payment gateway integration
  • Factory Pattern: Payment gateway factory
  • Flyweight Pattern: Seat type optimization
  • Proxy Pattern: Train availability caching

Additional Tools

  • PDF Generation: DomPDF for ticket generation
  • Task Scheduling: Laravel Scheduler for automated tasks
  • Validation: Comprehensive form validation
  • Middleware: Custom authentication and authorization

πŸ“₯ Installation

Prerequisites

  • PHP >= 8.4.0
  • Composer
  • Node.js & NPM
  • MySQL >= 8.0

Step-by-Step Installation

Step 1: Clone Repository

git clone https://github.com/Torikul-048/Railway-Management-System.git
cd Railway-Management-System

Step 2: Install PHP Dependencies

composer install

Step 3: Install Node Dependencies

npm install

Step 4: Environment Configuration

# Copy environment file
copy .env.example .env

# Generate application key
php artisan key:generate

Step 5: Configure Database

Edit .env file with your database credentials:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=railway_management
DB_USERNAME=root
DB_PASSWORD=your_password

Step 6: Configure Application

Update .env with your settings:

APP_NAME="Railway Management System"
APP_ENV=local
APP_DEBUG=true
APP_TIMEZONE=Asia/Dhaka
APP_URL=http://localhost:8000

# Email Configuration (Optional)
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@railway.com
MAIL_FROM_NAME="${APP_NAME}"

Step 7: Database Migration & Seeding

# Run migrations
php artisan migrate

# Seed database with sample data
php artisan db:seed

This will create:

  • 4 users (1 admin, 2 customers)
  • 6 trains with different routes
  • 20 train coaches (varied types)
  • 950 seats across all coaches
  • 3 sample bookings

Step 8: Build Frontend Assets

npm run build

Step 9: Start Development Server

php artisan serve

Step 10: Start Task Scheduler (Important!)

The scheduler automatically cancels unpaid bookings after 5 minutes.

Open a new terminal and run:

# Windows
start-scheduler.bat

# Or manually
php artisan schedule:work

⚠️ Important: Keep this terminal running! Without the scheduler:

  • Pending bookings won't auto-expire after 5 minutes
  • Seats won't be released automatically
  • Payment timer will show but won't enforce cancellation

Visit http://localhost:8000 in your browser.

πŸ’Ύ Database Setup

Default Users

After seeding, you'll have the following accounts:

Admin Account:

  • Email: admin@railway.com
  • Password: password
  • Role: Admin

Customer Accounts:

  • Email: customer@railway.com

  • Password: password

  • Role: Customer

  • Email: john@example.com

  • Password: password

  • Role: Customer

Database Schema Overview

Users Table:

  • id, name, email, password
  • phone, date_of_birth, gender
  • national_id, address
  • role (admin/staff/customer)
  • timestamps

Trains Table:

  • id, train_number, name
  • source_station, destination_station
  • departure_time, arrival_time
  • route, train_type
  • total_seats, available_seats
  • fare_per_seat, facilities
  • status (active/inactive)
  • timestamps

Train Coaches Table:

  • id, train_id, coach_number
  • coach_type (sleeper/second_class/first_class/ac_chair/ac_first)
  • total_seats, price_per_seat
  • timestamps

Seats Table:

  • id, train_coach_id, seat_number
  • is_available, is_reserved
  • reserved_until
  • timestamps

Bookings Table:

  • id, user_id, train_id, booking_reference
  • booking_date, journey_date
  • seat_numbers (JSON)
  • passenger_details (JSON)
  • total_fare
  • booking_status (pending/confirmed/cancelled/completed)
  • payment_status (pending/paid/refunded)
  • payment_method, payment_reference
  • refund_amount, refund_percentage
  • cancelled_at, cancellation_reason
  • timestamps

🎯 Usage

For Customers

  1. Register/Login: Create account or login
  2. Search Trains: Enter journey details
  3. Select Train: Choose from available trains
  4. Select Seats: Pick seats from visual seat map
  5. Enter Details: Provide passenger information
  6. Make Payment: Choose payment method and complete within 5 minutes
  7. Download Ticket: Get PDF ticket after confirmation
  8. Manage Bookings: View, cancel, or download tickets

For Admins

  1. Login: Access admin panel at /admin/login
  2. Dashboard: View system overview and statistics
  3. Manage Trains: Add, edit, or remove trains
  4. Manage Bookings: Monitor and manage all bookings
  5. User Management: Manage user accounts and roles
  6. View Reports: Analyze revenue and booking trends
  7. System Settings: Configure application settings

πŸ‘₯ User Roles

Customer

  • Search and book train tickets
  • View and manage own bookings
  • Cancel bookings with refunds
  • Update profile information
  • Download tickets

Admin

  • Full system access
  • User management (CRUD)
  • Train management (CRUD)
  • Booking management (CRUD)
  • Access to all reports and analytics
  • System settings configuration

πŸ”‘ Key Features Explained

1. 5-Minute Payment Window

When a customer creates a booking:

  1. Status: Pending (seats reserved)
  2. Timer starts: 5:00 countdown
  3. Two outcomes:
    • Paid within 5 minutes: Status β†’ Confirmed βœ…
    • Not paid: Automatic cancellation, seats released ❌

The bookings:expire-pending command runs every minute via Laravel Scheduler to check and cancel expired bookings.

2. Class-Based Pricing

Each coach type has a multiplier on the train's base fare:

Sleeper:      Base Fare Γ— 1.0
Second Class: Base Fare Γ— 1.3
First Class:  Base Fare Γ— 1.8
AC Chair:     Base Fare Γ— 2.0
AC First:     Base Fare Γ— 2.5

Example: Train base fare = ΰ§³500

  • Sleeper seat = ΰ§³500
  • AC First seat = ΰ§³1,250

3. Time-Based Refund System

Refund percentage calculated based on time before departure:

if (hours_before >= 48) β†’ 90% refund
else if (hours_before >= 24) β†’ 75% refund
else if (hours_before >= 12) β†’ 50% refund
else if (hours_before >= 6) β†’ 20% refund
else if (hours_before > 0) β†’ 10% refund
else β†’ 0% (departed)

The calculateRefundPercentage() method in Booking model handles this logic.

4. Visual Seat Selection

Interactive seat map with:

  • βœ… Green = Available
  • πŸ”΄ Red = Booked
  • 🟑 Yellow = Selected (by user)
  • Real-time price calculation
  • Coach type identification
  • Seat number display

5. Automated Cancellation

Laravel Scheduler runs bookings:expire-pending every minute:

  1. Finds bookings with status=pending and payment_status=pending
  2. Checks if booking_date <= 5 minutes ago
  3. Updates booking status to cancelled
  4. Releases all reserved seats
  5. Logs cancellation reason

6. Bangladesh Localization

  • Timezone: Asia/Dhaka (UTC+6)
  • Date pickers show Bangladesh dates
  • Journey date validation uses BD time
  • All timestamps in BD timezone

πŸ“ Project Structure

Railway-Management-System/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ Adapters/              # Payment adapter pattern
β”‚   β”œβ”€β”€ Console/Commands/      # Artisan commands
β”‚   β”‚   └── ExpirePendingBookings.php
β”‚   β”œβ”€β”€ Factories/             # Factory pattern
β”‚   β”œβ”€β”€ Flyweights/            # Flyweight pattern
β”‚   β”œβ”€β”€ Http/
β”‚   β”‚   β”œβ”€β”€ Controllers/
β”‚   β”‚   β”‚   β”œβ”€β”€ Admin/         # Admin controllers
β”‚   β”‚   β”‚   β”œβ”€β”€ Auth/          # Authentication
β”‚   β”‚   β”‚   β”œβ”€β”€ BookingController.php
β”‚   β”‚   β”‚   β”œβ”€β”€ ProfileController.php
β”‚   β”‚   β”‚   └── TrainSearchController.php
β”‚   β”‚   └── Middleware/
β”‚   β”‚       └── RedirectIfAdmin.php
β”‚   β”œβ”€β”€ Models/
β”‚   β”‚   β”œβ”€β”€ Booking.php        # Booking model with refund logic
β”‚   β”‚   β”œβ”€β”€ Seat.php
β”‚   β”‚   β”œβ”€β”€ Train.php
β”‚   β”‚   β”œβ”€β”€ TrainCoach.php
β”‚   β”‚   └── User.php
β”‚   └── Proxies/               # Proxy pattern
β”œβ”€β”€ database/
β”‚   β”œβ”€β”€ migrations/            # Database migrations
β”‚   └── seeders/               # Database seeders
β”œβ”€β”€ public/                    # Public assets
β”œβ”€β”€ resources/
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── app.css           # Tailwind CSS
β”‚   β”œβ”€β”€ js/
β”‚   β”‚   β”œβ”€β”€ app.js            # Main JavaScript
β”‚   β”‚   └── bootstrap.js      # Bootstrap setup
β”‚   └── views/
β”‚       β”œβ”€β”€ admin/            # Admin panel views
β”‚       β”œβ”€β”€ auth/             # Authentication views
β”‚       β”œβ”€β”€ bookings/         # Booking views
β”‚       β”œβ”€β”€ layouts/          # Layout templates
β”‚       β”œβ”€β”€ profile/          # Profile views
β”‚       └── trains/           # Train search views
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ console.php           # Scheduler configuration
β”‚   └── web.php               # Web routes
β”œβ”€β”€ storage/                  # File storage
β”œβ”€β”€ tests/                    # Unit & feature tests
β”œβ”€β”€ .env.example              # Environment template
β”œβ”€β”€ composer.json             # PHP dependencies
β”œβ”€β”€ package.json              # Node dependencies
β”œβ”€β”€ README.md                 # This file
β”œβ”€β”€ start-scheduler.bat       # Scheduler startup script
└── vite.config.js           # Vite configuration

πŸ”Œ API Endpoints

Public Routes

  • GET / - Home page
  • GET /login - Login page
  • POST /login - Login action
  • GET /register - Registration page
  • POST /register - Registration action

Customer Routes (Auth Required)

  • GET /trains/search - Search trains
  • GET /trains/{train}/details - Train details
  • GET /trains/{train}/select-seats - Seat selection
  • POST /bookings/reserve-seats - Reserve seats
  • POST /trains/{train}/book - Create booking
  • GET /bookings/{booking}/payment - Payment page
  • POST /bookings/{booking}/process-payment - Process payment
  • GET /bookings/{booking}/confirmation - Booking confirmation
  • GET /my-bookings - View bookings
  • GET /bookings/{booking}/download-ticket - Download ticket
  • GET /bookings/{booking}/cancel - Cancel booking form
  • POST /bookings/{booking}/cancel - Cancel booking action
  • GET /profile - User profile
  • PATCH /profile - Update profile
  • DELETE /profile - Delete account

Admin Routes (Admin Only)

  • GET /admin/dashboard - Admin dashboard
  • GET /admin/users - User management
  • POST /admin/users - Create user
  • GET /admin/users/{user} - View user
  • PUT /admin/users/{user} - Update user
  • DELETE /admin/users/{user} - Delete user
  • GET /admin/trains - Train management
  • POST /admin/trains - Create train
  • GET /admin/trains/{train} - View train
  • PUT /admin/trains/{train} - Update train
  • DELETE /admin/trains/{train} - Delete train
  • GET /admin/bookings - Booking management
  • GET /admin/bookings/{booking} - View booking
  • PUT /admin/bookings/{booking} - Update booking
  • POST /admin/bookings/{booking}/cancel - Cancel booking
  • GET /admin/reports - Reports & analytics
  • GET /admin/routes - Route management
  • GET /admin/settings - System settings

πŸ”’ Security Features

  • βœ… CSRF protection on all forms
  • βœ… SQL injection prevention (Eloquent ORM)
  • βœ… XSS protection (Blade templating)
  • βœ… Password hashing (bcrypt)
  • βœ… Role-based access control
  • βœ… Middleware authentication
  • βœ… Input validation
  • βœ… Session management
  • βœ… Environment variable protection
  • βœ… HTTPS ready (production)

πŸ§ͺ Testing

Run tests:

# Run all tests
php artisan test

# Run specific test
php artisan test --filter BookingTest

# Run with coverage
php artisan test --coverage

πŸ“Š Scheduler Commands

The system uses Laravel Scheduler for automated tasks:

Expire Pending Bookings:

php artisan bookings:expire-pending
  • Runs every minute via scheduler
  • Cancels bookings older than 5 minutes
  • Releases reserved seats
  • Updates booking status

To run scheduler manually:

php artisan schedule:work

πŸš€ Deployment

Production Checklist

  • Set APP_ENV=production in .env
  • Set APP_DEBUG=false in .env
  • Configure proper database credentials
  • Set up SSL certificate (HTTPS)
  • Configure email service
  • Set up cron job for scheduler:
    * * * * * cd /path-to-project && php artisan schedule:run >> /dev/null 2>&1
  • Optimize application:
    php artisan config:cache
    php artisan route:cache
    php artisan view:cache
    php artisan optimize
  • Set proper file permissions
  • Configure backup strategy
  • Set up monitoring and logging

πŸ“ License

This project is open-source and available under the MIT License.

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

Torikul Islam

Farid Patwary

Sayeem

πŸ™ Acknowledgments

  • Laravel Framework
  • Tailwind CSS
  • Bootstrap
  • Chart.js
  • Alpine.js
  • All open-source contributors

πŸ“ž Support

For support, email torikulislam732978@gmail.com, faridpatwary2020@gmail.com, Sayeem2107033@stud.kuet.ac.bd or open an issue on GitHub.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages