# zengroot147/campus_bus_assistant architecture

> Architecture diagram of the GitHub repository zengroot147/campus_bus_assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zengroot147/campus_bus_assistant
- Repository: https://github.com/zengroot147/campus_bus_assistant

## Overview

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: [`src/integrations/supabase/client.ts`](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/integrations/supabase/client.ts) (Supabase client), [`src/components/DashboardLayout.tsx`](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/DashboardLayout.tsx) (Dashboard layout), [`src/context/AuthContext.tsx`](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/context/AuthContext.tsx) (Auth context), [`src/pages/student/Dashboard.tsx`](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/pages/student/Dashboard.tsx) (Student pages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_app["App shell"]
  node_node_main(("Main<br/>bootstrap<br/>[main.tsx]"))
  node_node_app["App<br/>router shell<br/>[App.tsx]"]
  node_node_protected["Protected route<br/>route guard<br/>[ProtectedRoute.tsx]"]
end

subgraph group_group_roles["Role areas"]
  node_node_student_pages["Student pages<br/>role UI<br/>[Dashboard.tsx]"]
  node_node_driver_pages["Driver pages<br/>role UI<br/>[Dashboard.tsx]"]
  node_node_coord_pages["Coordinator pages<br/>role UI<br/>[Dashboard.tsx]"]
  node_node_admin_pages["Admin pages<br/>role UI<br/>[Dashboard.tsx]"]
end

subgraph group_group_data["Data layer"]
  node_node_authctx["Auth context<br/>session state<br/>[AuthContext.tsx]"]
  node_node_authhooks["Auth hooks<br/>state hooks<br/>[useAuthState.ts]"]
  node_node_authutils["Auth utils<br/>role helpers<br/>[auth-utils.ts]"]
  node_node_supabase[("Supabase client<br/>backend boundary<br/>[client.ts]")]
  node_node_realtime["Realtime service<br/>sync service<br/>[realTimeService.ts]"]
  node_node_vote_rules["Vote rules<br/>business service"]
end

subgraph group_group_shared["Shared UI"]
  node_node_shared_layout["Dashboard layout<br/>app chrome"]
  node_node_login_shell["Login shell<br/>auth chrome<br/>[LoginShell.tsx]"]
  node_node_notifications["Notifications<br/>ui flow"]
  node_node_student_widgets["Student widgets<br/>role widgets"]
  node_node_coord_widgets["Coordinator widgets<br/>role widgets<br/>[BusManagement.tsx]"]
  node_node_driver_widgets["Driver widgets<br/>role widgets"]
  node_node_admin_widgets["Admin widgets<br/>role widgets<br/>[AddUserDialog.tsx]"]
  node_node_ui_kit["UI kit<br/>design system<br/>[button.tsx]"]
end

node_node_main -->|"boots"| node_node_app
node_node_app -->|"guards"| node_node_protected
node_node_app -->|"shows auth"| node_node_login_shell
node_node_protected -->|"reads session"| node_node_authctx
node_node_authctx -->|"exposes"| node_node_authhooks
node_node_authctx -->|"uses"| node_node_authutils
node_node_authctx -->|"auth via"| node_node_supabase
node_node_student_pages -->|"uses"| node_node_shared_layout
node_node_driver_pages -->|"uses"| node_node_shared_layout
node_node_coord_pages -->|"uses"| node_node_shared_layout
node_node_admin_pages -->|"uses"| node_node_shared_layout
node_node_student_pages -->|"composes"| node_node_student_widgets
node_node_driver_pages -->|"composes"| node_node_driver_widgets
node_node_coord_pages -->|"composes"| node_node_coord_widgets
node_node_admin_pages -->|"composes"| node_node_admin_widgets
node_node_student_widgets -->|"subscribes"| node_node_notifications
node_node_driver_widgets -->|"subscribes"| node_node_notifications
node_node_coord_widgets -->|"applies"| node_node_vote_rules
node_node_notifications -->|"driven by"| node_node_realtime
node_node_realtime -->|"listens to"| node_node_supabase
node_node_vote_rules -->|"persists via"| node_node_supabase
node_node_student_pages -->|"reads/writes"| node_node_supabase
node_node_driver_pages -->|"reads/writes"| node_node_supabase
node_node_coord_pages -->|"reads/writes"| node_node_supabase
node_node_admin_pages -->|"reads/writes"| node_node_supabase
node_node_ui_kit -->|"underpins"| node_node_shared_layout

click node_node_main "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/main.tsx"
click node_node_app "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/App.tsx"
click node_node_protected "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/ProtectedRoute.tsx"
click node_node_authctx "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/context/AuthContext.tsx"
click node_node_authhooks "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/context/hooks/useAuthState.ts"
click node_node_authutils "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/context/utils/auth-utils.ts"
click node_node_supabase "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/integrations/supabase/client.ts"
click node_node_realtime "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/services/realTimeService.ts"
click node_node_vote_rules "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/services/voteThresholdService.ts"
click node_node_student_pages "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/pages/student/Dashboard.tsx"
click node_node_driver_pages "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/pages/driver/Dashboard.tsx"
click node_node_coord_pages "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/pages/coordinator/Dashboard.tsx"
click node_node_admin_pages "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/pages/admin/Dashboard.tsx"
click node_node_shared_layout "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/DashboardLayout.tsx"
click node_node_login_shell "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/auth/LoginShell.tsx"
click node_node_notifications "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/NotificationDropdown.tsx"
click node_node_student_widgets "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/RequestBusDialog.tsx"
click node_node_coord_widgets "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/coordinator/BusManagement.tsx"
click node_node_driver_widgets "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/driver/VoteThresholdNotification.tsx"
click node_node_admin_widgets "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/admin/AddUserDialog.tsx"
click node_node_ui_kit "https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/ui/button.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_main,node_node_app,node_node_protected toneBlue
class node_node_student_pages,node_node_driver_pages,node_node_coord_pages,node_node_admin_pages toneAmber
class node_node_authctx,node_node_authhooks,node_node_authutils,node_node_supabase,node_node_realtime,node_node_vote_rules toneMint
class node_node_shared_layout,node_node_login_shell,node_node_notifications,node_node_student_widgets,node_node_coord_widgets,node_node_driver_widgets,node_node_admin_widgets,node_node_ui_kit toneRose
```

## Components

### App shell

SPA bootstrap, routing, auth boundaries, and shared layout.

- [Main](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/main.tsx): bootstrap · Vite entry that mounts the React app. · `src/main.tsx`
- [App](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/App.tsx): router shell · Top-level routing and layout composition. · `src/App.tsx`
- [Protected route](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/ProtectedRoute.tsx): route guard · Enforces authenticated access to role-specific areas. · `src/components/ProtectedRoute.tsx`

### Role areas

User-facing pages organized by campus role.

- [Student pages](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/pages/student/Dashboard.tsx): role UI · Student dashboard, buses, complaints, voting, and profile pages. · `src/pages/student/Dashboard.tsx`
- [Driver pages](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/pages/driver/Dashboard.tsx): role UI · Driver dashboard, alerts, schedule, and profile pages. · `src/pages/driver/Dashboard.tsx`
- [Coordinator pages](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/pages/coordinator/Dashboard.tsx): role UI · Coordinator workflow pages for buses, routes, drivers, complaints, announcements, and voting. · `src/pages/coordinator/Dashboard.tsx`
- [Admin pages](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/pages/admin/Dashboard.tsx): role UI · 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](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/context/AuthContext.tsx): session state · Centralized auth/session state and actions. · `src/context/AuthContext.tsx`
- [Auth hooks](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/context/hooks/useAuthState.ts): state hooks · Helpers for reading and mutating auth state. · `src/context/hooks/useAuthState.ts`
- [Auth utils](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/context/utils/auth-utils.ts): role helpers · Session and role helper logic. · `src/context/utils/auth-utils.ts`
- [Supabase client](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/integrations/supabase/client.ts): backend boundary · Database, auth, and realtime client integration. · `src/integrations/supabase/client.ts`
- [Realtime service](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/services/realTimeService.ts): sync service · Live update orchestration for changing campus state. · `src/services/realTimeService.ts`
- [Vote rules](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/services/voteThresholdService.ts): business service · Vote-threshold workflow and rule enforcement. · `src/services/voteThresholdService.ts`

### Shared UI

Reusable layout, dialogs, notifications, and design-system components.

- [Dashboard layout](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/DashboardLayout.tsx): app chrome · Common dashboard shell and sidebar navigation. · `src/components/DashboardLayout.tsx`
- [Login shell](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/auth/LoginShell.tsx): auth chrome · Shared wrapper for role-specific login flows. · `src/components/auth/LoginShell.tsx`
- [Notifications](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/NotificationDropdown.tsx): ui flow · Realtime notifications and status surfaces across roles. · `src/components/NotificationDropdown.tsx`
- [Student widgets](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/RequestBusDialog.tsx): role widgets · Request, complaint, status, and announcement controls for students. · `src/components/RequestBusDialog.tsx`
- [Coordinator widgets](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/coordinator/BusManagement.tsx): role widgets · Bus, route, driver, and voting management UI. · `src/components/coordinator/BusManagement.tsx`
- [Driver widgets](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/driver/VoteThresholdNotification.tsx): role widgets · Driver alerts and vote-threshold notification surfaces. · `src/components/driver/VoteThresholdNotification.tsx`
- [Admin widgets](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/admin/AddUserDialog.tsx): role widgets · Admin user management and export/report tooling. · `src/components/admin/AddUserDialog.tsx`
- [UI kit](https://github.com/zengroot147/campus_bus_assistant/blob/main/src/components/ui/button.tsx): design system · Reusable shadcn-style component library and shared primitives. · `src/components/ui/button.tsx`

## Connections

- 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.
