How zengroot147/campus_bus_assistant works
1. System shape
- This is a single-page React application for campus transportation management.
- The frontend is the primary application; backend capabilities come from Supabase rather than a custom server.
2. Entry and shell
- src/main.tsx boots the app, with App.tsx likely defining top-level routing and layout composition.
- Global styling comes from Tailwind/PostCSS plus src/index.css and src/App.css.
3. Role-based navigation and route boundaries
- The app is organized around four user roles: student, driver, coordinator, admin.
- Role-specific pages live under src/pages/<role>/..., and route protection is enforced by src/components/ProtectedRoute.tsx.
- This creates a clear boundary between authenticated app areas and the login/register flows.
4. Authentication and session state
- Auth state is centralized in src/context/AuthContext.tsx with supporting hooks under src/context/hooks.
- Login pages are split by role (StudentLogin, DriverLogin, CoordinatorLogin, AdminLogin), which suggests role-aware onboarding rather than a single generic login screen.
- src/context/utils/auth-utils.ts likely contains session/role helpers used throughout the app.
5. Feature-oriented UI composition
- Most user interactions are built as reusable dialogs and panels in src/components/.
- There are dedicated component groups for each role:
- Student: bus requests, complaints, announcements, voting, status notifications.
- Driver: alerts, schedule/profile support, vote-threshold notifications.
- Coordinator: bus, route, driver, and voting management.
- Admin: user management and reporting/export.
- Shared dashboard shells such as DashboardLayout and DashboardSidebar provide the common app frame.
6. Data access pattern
- Domain data is accessed through custom hooks in src/hooks/, such as useBuses, useAnnouncements, useComplaints, useAssignedBuses, and voting-related hooks.
- These hooks are the main boundary between UI and data fetching/subscription logic, keeping pages and components mostly presentation-focused.
- Coordinator-specific hooks (useCoordinatorBuses, useCoordinatorComplaints, useCoordinatorVoting) indicate separate query/write views for privileged operations.
7. Business logic services
- Cross-cutting workflows are isolated in src/services/.
- realTimeService.ts handles live updates, while voteThresholdService.ts encapsulates vote-driven business rules.
- This suggests the app has some stateful orchestration beyond simple CRUD, especially around bus requests and threshold-triggered actions.
8. Real-time and notification flows
- The architecture includes reactive UI updates for bus status, voting thresholds, and alerts.
- Components like RealTimeStatus, NotificationDropdown, BusRequestStatusNotification, and VoteThresholdNotification indicate that data can change asynchronously and be surfaced immediately in the UI.
- The runtime boundary here is Supabase real-time plus app-side subscription/refresh logic.
9. Operational workflows
- The core campus workflows are:
- students submit complaints, bus requests, and votes;
- coordinators manage buses/routes/drivers and respond to demand;
- drivers receive alerts and track assigned work;
- admins oversee users, reports, and system-wide data.
- These workflows are implemented as page-level screens with modal/dialog-based creation and edit actions, rather than as a separate backend workflow engine.
10. Supabase as backend boundary
- src/integrations/supabase/client.ts and generated types in src/integrations/supabase/types.ts show direct integration with Supabase.
- The repository also includes Supabase project config and migration tooling (supabase/, run-migrations.mjs, apply-migrations.mjs), so schema changes are managed alongside the frontend.
- This is the main persistence/auth/realtime boundary for the system.
11. External integrations
- The README indicates Google Maps for live bus tracking and Telegram Bot API for emergency notifications.
- These are not the central architecture, but they materially affect the live-status and alerting subsystems.
12. Shared design system and UI infrastructure
- src/components/ui/ is a Shadcn/ui-style component library used across all roles.
- theme-provider.tsx, use-mobile.tsx, Toaster, and utility helpers in src/lib/utils.ts support consistent UX and responsive behavior.
13. Deployment and build environment
- The app is built with Vite, TypeScript, Tailwind, and deployed via Vercel (vercel.json).
- The repo contains both npm and Bun lockfiles, but the architecture is still clearly a browser client with Supabase-backed services.
14. What to draw in an architecture diagram
- Center the React SPA as the orchestration layer.
- Show separate role-based UI areas feeding into shared auth/context, custom hooks, and services.
- Place Supabase as the primary backend boundary, with real-time updates and database migrations as first-class parts of the system.
- Add external integrations for Maps and Telegram as side services connected to the relevant feature flows.
Main entry points: client.ts Supabase client · DashboardLayout.tsx Dashboard layout · AuthContext.tsx Auth context · Dashboard.tsx Student pages
Components 21
App shell
SPA bootstrap, routing, auth boundaries, and shared layout.
- Main · Vite entry that mounts the React app.
src/main.tsx - App · Top-level routing and layout composition.
src/App.tsx - Protected route · Enforces authenticated access to role-specific areas.
src/components/ProtectedRoute.tsx
Role areas
User-facing pages organized by campus role.
- Student pages · Student dashboard, buses, complaints, voting, and profile pages.
src/pages/student/Dashboard.tsx - Driver pages · Driver dashboard, alerts, schedule, and profile pages.
src/pages/driver/Dashboard.tsx - Coordinator pages · Coordinator workflow pages for buses, routes, drivers, complaints, announcements, and voting.
src/pages/coordinator/Dashboard.tsx - Admin pages · Admin dashboard and management screens for users, buses, coordinators, and reports.
src/pages/admin/Dashboard.tsx
Data layer
Context, hooks, services, and Supabase integration.
- Auth context · Centralized auth/session state and actions.
src/context/AuthContext.tsx - Auth hooks · Helpers for reading and mutating auth state.
src/context/hooks/useAuthState.ts - Auth utils · Session and role helper logic.
src/context/utils/auth-utils.ts - Supabase client · Database, auth, and realtime client integration.
src/integrations/supabase/client.ts - Realtime service · Live update orchestration for changing campus state.
src/services/realTimeService.ts - Vote rules · Vote-threshold workflow and rule enforcement.
src/services/voteThresholdService.ts
Shared UI
Reusable layout, dialogs, notifications, and design-system components.
- Dashboard layout · Common dashboard shell and sidebar navigation.
src/components/DashboardLayout.tsx - Login shell · Shared wrapper for role-specific login flows.
src/components/auth/LoginShell.tsx - Notifications · Realtime notifications and status surfaces across roles.
src/components/NotificationDropdown.tsx - Student widgets · Request, complaint, status, and announcement controls for students.
src/components/RequestBusDialog.tsx - Coordinator widgets · Bus, route, driver, and voting management UI.
src/components/coordinator/BusManagement.tsx - Driver widgets · Driver alerts and vote-threshold notification surfaces.
src/components/driver/VoteThresholdNotification.tsx - Admin widgets · Admin user management and export/report tooling.
src/components/admin/AddUserDialog.tsx - UI kit · Reusable shadcn-style component library and shared primitives.
src/components/ui/button.tsx
Connections 26
- Main → App: boots · Application entry mounts the router shell.
- App → Protected route: guards · Authenticated sections are wrapped by route protection.
- App → Login shell: shows auth · Public auth flows use the shared login wrapper.
- Protected route → Auth context: reads session · Route access depends on current auth state.
- Auth context → Auth hooks: exposes · Context state is consumed through hooks.
- Auth context → Auth utils: uses · Role and session helper logic supports auth decisions.
- Auth context → Supabase client: auth via · Supabase is the backend identity boundary.
- Student pages → Dashboard layout: uses · Student pages render inside the common dashboard chrome.
- Driver pages → Dashboard layout: uses · Driver pages render inside the common dashboard chrome.
- Coordinator pages → Dashboard layout: uses · Coordinator pages render inside the common dashboard chrome.
- Admin pages → Dashboard layout: uses · Admin pages render inside the common dashboard chrome.
- Student pages → Student widgets: composes · Student screens are built from dialogs and notification panels.
- Driver pages → Driver widgets: composes · Driver screens surface alerts and threshold notifications.
- Coordinator pages → Coordinator widgets: composes · Coordinator screens use management forms and workflow controls.
- Admin pages → Admin widgets: composes · Admin screens use user and reporting tools.
- Student widgets → Notifications: subscribes · Student UI reflects async bus and complaint status.
- Driver widgets → Notifications: subscribes · Driver UI receives realtime and threshold alerts.
- Coordinator widgets → Vote rules: applies · Coordinator voting actions depend on threshold rules.
- Notifications → Realtime service: driven by · Notifications update from realtime subscriptions.
- Realtime service → Supabase client: listens to · Realtime streams come from Supabase.
- Vote rules → Supabase client: persists via · Vote-related state is stored and queried through Supabase.
- Student pages → Supabase client: reads/writes · Student workflows consume backend data directly through hooks and client integration.
- Driver pages → Supabase client: reads/writes · Driver workflows consume backend data directly through hooks and client integration.
- Coordinator pages → Supabase client: reads/writes · Coordinator workflows consume backend data directly through hooks and client integration.
- Admin pages → Supabase client: reads/writes · Admin workflows consume backend data directly through hooks and client integration.
- UI kit → Dashboard layout: underpins · Shared primitives are used throughout the app shell and screens.