How vijay193/government_bus works
Project type and purpose
• This is a full-stack bus booking system.
• Frontend: React + TypeScript (Vite), TailwindCSS.
• Backend: Node.js + Express, MySQL, REST APIs.
File structure
• Top-level: App.tsx, index.tsx (entrypoints), vite.config.ts, tsconfig.json.
• “backend/”: Node.js + Express server (server.js), package.json.
• “pages/” & “components/”: React pages (BookingPage, AdminDashboardPage, etc.) and reusable UI modules (common, bus, admin, assistant).
• “contexts/” & “hooks/”: React context for Auth, custom hooks (useAuth, useVoiceRecognition).
• “services/”: API clients, command parsing, text-to-speech.
• “dist/”: built static assets + index.html (for production deployment).
• Configuration: .gitignore, package.json, package-lock.json.
Key insights from README
• Role-based access: User, Admin, Sub-Admin.
• Core features: auth (password & OTP), schedule management, seat booking with fare & discount logic, revenue analytics, pass cards, district-wise routes.
• External dependencies: MySQL DB, CORS, dotenv, UUID.
Main components & their interactions
a. Frontend (Browser)
• UI Layers:
– Pages (Home, Booking, Profile, Admin Dashboards)
– Components (Header, SeatLayout, Modals, VoiceAssistant)
• State & Logic:
– AuthContext (manages JWT or session)
– Hooks (useAuth, useVoiceRecognition)
• Services:
– api.ts (axios/fetch calls to backend)
– textToSpeech & commandParser modules (for voice assistant)
b. Backend (Express Server)
• REST API Endpoints:
– /auth (login, OTP verification, register)
– /schedules (CRUD schedules)
– /bookings (book, cancel, free-ticket eligibility)
– /analytics (revenue, district metrics)
– /users (role management, pass cards)
• Business Logic: discounts, eligibility rules, seat allocation.
• Middleware: CORS, dotenv config, UUID generation.
• Database Access: MySQL client/ORM layer.
c. Database (MySQL)
• Tables: Users, Roles, Schedules, Bookings, DistrictRoutes, PassCards, AnalyticsRecords
• Relationships:
– One-to-Many: User→Bookings, Schedule→Bookings
– Many-to-One or Many-to-Many as needed (District↔Routes)
d. External Services
• Email/SMS OTP gateway (for OTP login)
• Hosting/CDN (serving dist/ assets)
• Possible caching layer or analytics pipeline (optional)
Architectural patterns & design principles
• Layered architecture: Presentation (React) → Application/API (Express) → Data (MySQL)
• Role-based access control via route guards (ProtectedRoute/AdminRoute)
• Separation of concerns: UI components vs. business services vs. data models
• Single Page Application (SPA) with client-side routing and dynamic code splitting (Vite)