How kalebb12/bus-ticket-booking-system works
Project Type & Purpose
• The project is a backend service for a bus ticket booking system.
• It manages functionalities such as user registration/login, email verification, ride management (create, update, cancel), seat booking, QR code generation for tickets, and email notifications.
• The application uses JWT for authentication, and further integrates with external services like Nodemailer for emailing and a QR code package for generating tickets.
Overall Architectural Components
a. Application Server:
• Express-based server which handles incoming HTTP requests.
• This is initiated in files like server.js (or index.js/app.js from the file tree) where the Express app is configured.
b. API Controllers:
• These modules encapsulate business logic and interact with models.
c. Routing Layer:
• “routes” directory, with separate route definitions for admin, bookings, rides, and users.
• How each route connects to its corresponding controller.
d. Middleware:
• Authentication and request handling/validation middleware (e.g., protectMiddleware.js, protectBooking.js, restrictAccessMiddleware.js) that ensures security and validation before controllers are invoked.
e. Data Models:
f. Utilities & Helpers:
• Utility functions in the “utils” folder (error handling, token creation, QR code generation, email sending, token expiry checks).
g. External/Third-party Integrations:
• Components for integration with email services (using Nodemailer with email templates), and QR code generation (using the qrcode package).
• JWT handling, password hashing (bcrypt), and input validation libraries (Joi, Express Validator).
Relationships & Interactions
• Incoming HTTP requests flow from client endpoints (e.g., /api/users/register, /api/bookings) into the Application Server.
• The Routing layer directs these requests to the appropriate controller based on the endpoint.
• Controllers then interact with Models to perform CRUD operations on the database and use Utilities to handle tasks such as sending emails or generating QR codes.
• Middleware components are placed in the path (pre-controller) to enforce security and data validation.
• Some components may run background jobs (e.g., sending booking confirmations through email, or running crons for scheduled tasks) as indicated by files like crons.js.
Architectural Patterns & Design Principles
• Modular design through separation of concerns: Controllers, Routes, Models, and Middlewares are all separated.
• Use of the MVC-inspired pattern: Although not strictly MVC, the controllers and models are organized to keep business logic separate from routing.
• Emphasis on security (JWT authentication, password hashing, input validation) and error handling (via custom error handling modules in utils).