A robust, full-stack web application for searching, booking, and managing train tickets.
Built with Flask and MongoDB, this project features a modular architecture, real-time seat availability calculation, and automated e-ticket generation.
- Secure Authentication: User registration and login with password hashing
- Profile Management: Update personal details and manage saved passengers for faster bookings
- Booking History: View past and upcoming journeys with status updates
- Smart Search: Filter trains by source, destination, and departure time (Morning, Afternoon, Evening)
- Real-time Availability: Dynamic calculation of Confirmed, RAC, and Waitlisted seats using MongoDB aggregation pipelines
- Seat Allocation: Automated logic for assigning seat numbers and berths based on class and preference
- Waitlist Logic: Automatically handles Confirmed vs. RAC vs. Waitlist status based on capacity
- PDF Generation: Instantly download professional PDF tickets with unique PNRs
- QR Code Integration: Embedded QR codes on tickets for easy validation
- Email Notifications: Booking confirmations sent directly to the user's email via SMTP
- PNR Status: Publicly accessible PNR status checker
- Manage Trains: Add new trains, routes, and schedules
- Booking Overview: View all bookings across the system with search functionality
- Route Visualization: View detailed route stops and timings
Backend
- Python
- Flask (Blueprints, Application Factory Pattern)
Database
- MongoDB (MongoEngine ODM)
Frontend
- Jinja2 Templates
- Bootstrap 5
- CSS3
Utilities
- FPDF (PDF Generation)
- QRCode (Ticket Validation)
- Flask-Mail (Email Services)
- Flask-WTF (Form Handling & CSRF Protection)
- Python 3.10+
- MongoDB (Local or Atlas)
- Gmail Account (for email notifications β App Password required)
git clone https://github.com/yourusername/railway-booking-system.git
cd railway-booking-systempython -m venv venv
# Windows
venv\Scripts\activate
# Mac/Linux
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the root directory:
SECRET_KEY=your_secure_secret_key
MONGODB_URI=mongodb+srv://<user>:<password>@cluster.mongodb.net/railway_db
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_app_passwordRun the script to populate the database with sample trains and users:
python init_db.pypython app.pyVisit: http://127.0.0.1:5000
railway-booking-system/
βββ app.py # Entry point
βββ config.py # App configuration
βββ init_db.py # Database seeder script
βββ models.py # Database schemas (User, Train, Booking)
βββ requirements.txt # Dependencies
βββ railway_app/ # Main Application Package
βββ __init__.py # App factory & extension init
βββ utils.py # Helper functions (PDF, Email, Logic)
βββ routes/ # Blueprints
β βββ admin.py
β βββ auth.py
β βββ booking.py
β βββ main.py
βββ static/ # CSS, Images
βββ templates/ # HTML Templates
Contributions are welcome!
Please follow these steps:
- Fork the project
- Create your feature branch
git checkout -b feature/AmazingFeature
- Commit your changes
git commit -m "Add some AmazingFeature" - Push to the branch
git push origin feature/AmazingFeature
- Open a Pull Request
Distributed under the MIT License.
See LICENSE for more information.