# marcr11/ba-schedule architecture

> Architecture diagram of the GitHub repository marcr11/ba-schedule, 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/marcr11/ba-schedule
- Repository: https://github.com/marcr11/ba-schedule

## Overview

1. **Top-level shape**
   - The repo is split into a **client** and a **server**.  
   - The client is a **React + TypeScript + Vite** single-page app; the server is a **Node.js + Express** API.  
   - The system is centered on one domain: **pulling university schedule data from Campus Dual and presenting it in a friendlier calendar UI**.

2. **Frontend presentation layer**
   - `client/src/components/App.tsx` is the main composition root for the UI.
   - The visible UI is built from focused components: `Calendar`, `Login`, `GeneralLogin`, `UserLogin`, `SettingsPopUp`, `SettingsButton`, `ThemeToggle`, and `LoadingAnim`.
   - The frontend also includes a couple of static entry pages in `client/pages/` (`info.html`, `timer.html`), suggesting some non-SPA or auxiliary pages alongside the main app.

3. **Frontend data handling and formatting**
   - The UI uses local helper modules to transform backend data into calendar-ready structures: `scheduleDataFormat`, `setAppointmentColors`, `hexToRgb`, and `loadingMessages`.
   - Static JSON assets such as `subjects.json` and `randomLoadingMessages.json` are part of the presentation/data layer, not server state.
   - This implies the client does some **view-model shaping** locally after receiving schedule data.

4. **Frontend state and UX concerns**
   - Theme and interaction behavior are handled explicitly through helpers like `configureTheme` and `configureKeyDownEvents`.
   - The app has a settings subsystem with dedicated popup and option components, indicating user preferences are likely managed in the UI layer rather than deeply in the backend.
   - Styling is split into component-scoped CSS files plus a global `index.css`.

5. **Backend entrypoint and API surface**
   - `server/server.js` is the backend bootstrap.
   - The main API route is organized around `routes/schedule.route.js`, with `controllers/schedule.controller.js` and `services/schedule.service.js` separating HTTP handling from business logic.
   - The backend appears to expose schedule-related functionality as the primary API contract.

6. **External schedule source integration**
   - A dedicated `campusDualFetcher` folder contains `campusDualFetcher.js` and a certificate chain file, which strongly indicates the server integrates with the **Campus Dual** university system over a trusted TLS connection.
   - This is the key external dependency in the architecture: the backend fetches authoritative schedule data from the university service, then normalizes and serves it to the client.
   - The README’s login instructions also point to the campus self-service portal as the source of a user-specific hash/credential.

7. **Persistence and user management**
   - MongoDB is the durable storage layer, configured via `configs/db.config.js` and accessed through `services/db.service.js`.
   - The data model is split into `models/user.model.js` and `models/general.model.js`, which suggests separate storage concerns for user-specific records and shared/system data.
   - Helper modules such as `createNewUser`, `checkUserExistence`, `checkUserRegistered`, `updateUserLastLogin`, and `updateUserToken` indicate the backend manages user registration state, token storage, and activity metadata.

8. **Authentication and access control**
   - Authentication is helper-driven: `checkPwd`, `verifyToken`, and the token update helpers imply the backend validates access using stored secrets/tokens rather than anonymous public access.
   - The frontend’s separate `GeneralLogin` and `UserLogin` components mirror that backend split: one flow likely handles general access, while the other handles user-linked Campus Dual login.
   - This is a boundary worth capturing in an architecture diagram: **client login → backend verification/token persistence → schedule access**.

9. **Scheduling and background work**
   - `createNewCronJob.helper.js` suggests the server can run scheduled jobs, likely to refresh schedule data or maintain user/session-related state.
   - Additional helpers like `getScheduleData`, `endTime`, and `updateUserLastLogin` indicate the server is doing more than simple proxying; it also computes or enriches schedule records before returning them.
   - The architecture therefore includes a small **backend processing layer** between the external Campus Dual source and the client calendar.

10. **Cross-cutting protections and tooling**
   - `middlewares/rateLimit.middleware.js` adds request throttling, which matters because the backend is likely protecting an external dependency and/or user-specific endpoints.
   - GitHub Actions workflows cover **build/deploy**, **CodeQL** security scanning, and **Prettier** formatting enforcement.
   - This repo is production-oriented: it has deployment automation, static typing in the client, and security/quality automation in CI.

11. **Runtime boundaries to show in a diagram**
   - **Browser/client**: renders UI, manages theme/settings, formats schedule data, and calls the API.
   - **Express backend**: handles login/schedule endpoints, validates users/tokens, applies rate limiting, and orchestrates data access.
   - **MongoDB**: persists users, tokens, and shared application data.
   - **Campus Dual external system**: authoritative source for schedule information and login-related data.

12. **Primary data flow**
   - User opens the React app → logs in with Campus Dual-derived credentials/hash → frontend sends login/schedule requests to the Express API → backend checks user/token state in MongoDB → backend fetches schedule data from Campus Dual when needed → backend returns normalized schedule payloads → frontend formats and renders them in the calendar UI.

Main entry points: [`client/src/components/App.tsx`](https://github.com/marcr11/ba-schedule/blob/main/client/src/components/App.tsx) (App), [`server/src/routes/schedule.route.js`](https://github.com/marcr11/ba-schedule/blob/main/server/src/routes/schedule.route.js) (Schedule API), [`server/src/configs/db.config.js`](https://github.com/marcr11/ba-schedule/blob/main/server/src/configs/db.config.js) (Mongo layer), [`server/src/helpers/checkPwd.helper.js`](https://github.com/marcr11/ba-schedule/blob/main/server/src/helpers/checkPwd.helper.js) (User auth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_client_app["App<br/>react composition root<br/>[App.tsx]"]
  node_client_calendar["Calendar<br/>schedule view<br/>[Calendar.tsx]"]
  node_client_login["Login<br/>auth UI<br/>[Login.tsx]"]
  node_client_settings["Settings<br/>preferences UI<br/>[SettingsPopUp.tsx]"]
  node_client_theme["Theme/UX<br/>interaction helpers<br/>[configureTheme.ts]"]
  node_client_format["Formatters<br/>view-model helpers"]
  node_client_loading["Loading UI<br/>feedback<br/>[LoadingAnim.tsx]"]
  node_client_assets["Static data<br/>client assets<br/>[subjects.json]"]
  node_client_pages["Aux pages<br/>static pages<br/>[info.html]"]
end

subgraph group_server["Server"]
  node_server_entry["Server<br/>express bootstrap<br/>[server.js]"]
  node_server_api["Schedule API<br/>route/controller/service<br/>[schedule.route.js]"]
  node_server_auth["User auth<br/>identity helpers<br/>[checkPwd.helper.js]"]
  node_server_data["Schedule processing<br/>domain helpers"]
  node_server_db[("Mongo layer<br/>persistence<br/>[db.config.js]")]
  node_server_limits["Rate limit<br/>middleware"]
  node_server_fetcher["CampusDual fetcher<br/>external adapter"]
end

subgraph group_external["External"]
  node_campus_dual[("Campus Dual<br/>external system")]
  node_mongodb[("MongoDB<br/>external datastore")]
end

node_client_app -->|"renders"| node_client_calendar
node_client_app -->|"includes"| node_client_login
node_client_app -->|"includes"| node_client_settings
node_client_app -->|"uses"| node_client_theme
node_client_app -->|"formats"| node_client_format
node_client_app -->|"shows"| node_client_loading
node_client_app -->|"reads"| node_client_assets
node_client_app -.->|"adjacent pages"| node_client_pages
node_server_entry -->|"mounts"| node_server_api
node_server_api -->|"protected by"| node_server_limits
node_server_api -->|"verifies"| node_server_auth
node_server_api -->|"orchestrates"| node_server_data
node_server_auth -->|"persists"| node_server_db
node_server_data -->|"fetches"| node_server_fetcher
node_server_fetcher -->|"connects to"| node_campus_dual
node_server_db -->|"stores in"| node_mongodb
node_server_auth -.->|"uses credentials"| node_campus_dual
node_client_login -->|"calls"| node_server_api
node_client_calendar -->|"loads schedule"| node_server_api
node_server_api -->|"reads/writes"| node_server_db
node_server_data -->|"checks state"| node_server_db

click node_client_app "https://github.com/marcr11/ba-schedule/blob/main/client/src/components/App.tsx"
click node_client_calendar "https://github.com/marcr11/ba-schedule/blob/main/client/src/components/Calendar.tsx"
click node_client_login "https://github.com/marcr11/ba-schedule/blob/main/client/src/components/Login.tsx"
click node_client_settings "https://github.com/marcr11/ba-schedule/blob/main/client/src/components/SettingsPopUp.tsx"
click node_client_theme "https://github.com/marcr11/ba-schedule/blob/main/client/src/helpers/configureTheme.ts"
click node_client_format "https://github.com/marcr11/ba-schedule/blob/main/client/src/helpers/scheduleDataFormat.ts"
click node_client_loading "https://github.com/marcr11/ba-schedule/blob/main/client/src/components/LoadingAnim.tsx"
click node_client_assets "https://github.com/marcr11/ba-schedule/blob/main/client/src/data/subjects.json"
click node_client_pages "https://github.com/marcr11/ba-schedule/blob/main/client/pages/info.html"
click node_server_entry "https://github.com/marcr11/ba-schedule/blob/main/server/server.js"
click node_server_api "https://github.com/marcr11/ba-schedule/blob/main/server/src/routes/schedule.route.js"
click node_server_auth "https://github.com/marcr11/ba-schedule/blob/main/server/src/helpers/checkPwd.helper.js"
click node_server_data "https://github.com/marcr11/ba-schedule/blob/main/server/src/helpers/getScheduleData.helper.js"
click node_server_db "https://github.com/marcr11/ba-schedule/blob/main/server/src/configs/db.config.js"
click node_server_limits "https://github.com/marcr11/ba-schedule/blob/main/server/src/middlewares/rateLimit.middleware.js"
click node_server_fetcher "https://github.com/marcr11/ba-schedule/blob/main/server/src/campusDualFetcher/campusDualFetcher.js"

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_client_app,node_client_calendar,node_client_login,node_client_settings,node_client_theme,node_client_format,node_client_loading,node_client_assets,node_client_pages toneBlue
class node_server_entry,node_server_api,node_server_auth,node_server_data,node_server_db,node_server_limits,node_server_fetcher toneAmber
class node_campus_dual,node_mongodb toneMint
```

## Components

### Client

React + TypeScript SPA that renders the schedule experience and prepares data for the calendar UI.

- [App](https://github.com/marcr11/ba-schedule/blob/main/client/src/components/App.tsx): react composition root · Main UI composition root and application shell. · `client/src/components/App.tsx`
- [Calendar](https://github.com/marcr11/ba-schedule/blob/main/client/src/components/Calendar.tsx): schedule view · Primary calendar presentation for timetable data. · `client/src/components/Calendar.tsx`
- [Login](https://github.com/marcr11/ba-schedule/blob/main/client/src/components/Login.tsx): auth UI · Login entry and credential flow components. · `client/src/components/Login.tsx`
- [Settings](https://github.com/marcr11/ba-schedule/blob/main/client/src/components/SettingsPopUp.tsx): preferences UI · Popup and option controls for app settings. · `client/src/components/SettingsPopUp.tsx`
- [Theme/UX](https://github.com/marcr11/ba-schedule/blob/main/client/src/helpers/configureTheme.ts): interaction helpers · Client-side theme and keyboard behavior helpers. · `client/src/helpers/configureTheme.ts`
- [Formatters](https://github.com/marcr11/ba-schedule/blob/main/client/src/helpers/scheduleDataFormat.ts): view-model helpers · Transforms backend schedule data into calendar-ready structures and presentation colors. · `client/src/helpers/scheduleDataFormat.ts`
- [Loading UI](https://github.com/marcr11/ba-schedule/blob/main/client/src/components/LoadingAnim.tsx): feedback · Loading animation and randomized loading messages. · `client/src/components/LoadingAnim.tsx`
- [Static data](https://github.com/marcr11/ba-schedule/blob/main/client/src/data/subjects.json): client assets · Local JSON assets used by the UI for subjects and loading messages. · `client/src/data/subjects.json`
- [Aux pages](https://github.com/marcr11/ba-schedule/blob/main/client/pages/info.html): static pages · Standalone HTML pages outside the main SPA entry. · `client/pages/info.html`

### Server

Express API that authenticates users, fetches schedule data, and serves normalized responses.

- [Server](https://github.com/marcr11/ba-schedule/blob/main/server/server.js): express bootstrap · Backend startup and Express application bootstrap. · `server/server.js`
- [Schedule API](https://github.com/marcr11/ba-schedule/blob/main/server/src/routes/schedule.route.js): route/controller/service · HTTP route, controller, and service layer for schedule-related requests. · `server/src/routes/schedule.route.js`
- [User auth](https://github.com/marcr11/ba-schedule/blob/main/server/src/helpers/checkPwd.helper.js): identity helpers · Checks password, token, and registration state while managing user records. · `server/src/helpers/checkPwd.helper.js`
- [Schedule processing](https://github.com/marcr11/ba-schedule/blob/main/server/src/helpers/getScheduleData.helper.js): domain helpers · Schedule enrichment, end-time calculation, and cron-driven background work. · `server/src/helpers/getScheduleData.helper.js`
- [Mongo layer](https://github.com/marcr11/ba-schedule/blob/main/server/src/configs/db.config.js): persistence · Database configuration, service access, and user/general models. · `server/src/configs/db.config.js`
- [Rate limit](https://github.com/marcr11/ba-schedule/blob/main/server/src/middlewares/rateLimit.middleware.js): middleware · Request throttling for protected or dependency-sensitive endpoints. · `server/src/middlewares/rateLimit.middleware.js`
- [CampusDual fetcher](https://github.com/marcr11/ba-schedule/blob/main/server/src/campusDualFetcher/campusDualFetcher.js): external adapter · Trusted integration that retrieves schedule data from Campus Dual. · `server/src/campusDualFetcher/campusDualFetcher.js`

### External

Outside systems the backend depends on for authoritative schedule and identity-related data.

- **Campus Dual**: external system · Authoritative university schedule and login source.
- **MongoDB**: external datastore · Persistent store for users, tokens, and shared application data.

## Connections

- App → Calendar: renders · The app composes the primary calendar experience.
- App → Login: includes · The app mounts login flows and access entry points.
- App → Settings: includes · The app exposes settings and preference controls.
- App → Theme/UX: uses · The app configures theme and key handling behavior.
- App → Formatters: formats · Incoming schedule payloads are reshaped before rendering.
- App → Loading UI: shows · The app uses loading feedback during async work.
- App → Static data: reads · The UI consumes local JSON data for subjects and messages.
- App → Aux pages: adjacent pages · Auxiliary static pages sit alongside the SPA.
- Server → Schedule API: mounts · Server bootstrap wires the schedule API surface.
- Schedule API → Rate limit: protected by · API requests are throttled by rate limiting middleware.
- Schedule API → User auth: verifies · Login and access flows rely on user/token checks.
- Schedule API → Schedule processing: orchestrates · The route layer delegates schedule computation and enrichment.
- User auth → Mongo layer: persists · Auth helpers read and update user records in MongoDB.
- Schedule processing → CampusDual fetcher: fetches · Schedule processing pulls authoritative data through the Campus Dual adapter.
- CampusDual fetcher → Campus Dual: connects to · Backend integration reaches the external university system.
- Mongo layer → MongoDB: stores in · Mongo-backed persistence holds application records.
- User auth → Campus Dual: uses credentials · Login-related data originates from the Campus Dual side.
- Login → Schedule API: calls · Frontend login requests are sent to the backend API.
- Calendar → Schedule API: loads schedule · Calendar data is retrieved from the backend.
- Schedule API → Mongo layer: reads/writes · API operations depend on persisted user and general data.
- Schedule processing → Mongo layer: checks state · Processing consults stored user data and related metadata.
