# ninjao9/crimson-scheduler architecture

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

- Interactive diagram: https://gitdiagram.com/ninjao9/crimson-scheduler
- Repository: https://github.com/ninjao9/crimson-scheduler

## Overview

#### Purpose and Entry Points
Crimson Scheduler is a WSU course-search and schedule-planning application. It caches WSU schedule data in a Django database, then serves a browser-based planner without querying WSU on each search. Operational entry points are the importer at `main.py` and Django server commands through `web/manage.py`; HTTP routing begins in `web/web/urls.py`.

#### Data Ingestion Pipeline
`main.py` initializes Django and orchestrates API-based collection. Collection handlers model the hierarchical WSU source data—campus, semester, subject, and course—under `dataCollection/classHandler/campus.py`, `dataCollection/classHandler/semester.py`, and `dataCollection/classHandler/clas.py`. The importer requests WSU schedule API endpoints, transforms responses, and upserts local records through `dataCollection/dataHandler/data.py` and `dataCollection/dataHandler/storage.py`.

The legacy scraper at `dataCollection/dataHandler/scraper.py` is explicitly not the primary ingestion path.

#### Persistent Course Catalog
The Django `classes` app owns the cached academic catalog and scheduling entities in `web/classes/models.py`. Its migrations establish the evolving schema for courses, sections, semester/campus/subject metadata, lecture/lab relationships, meeting details, enrollment data, and saved schedule-section structures; key later schema evolution is represented by `web/classes/migrations/0012_course_has_required_lab_section_lab_metadata.py` and `web/classes/migrations/0013_expand_section_days_time.py`.

PostgreSQL is the intended production datastore, with SQLite supported for local development. Database connection settings are consumed by `web/web/settings.py`.

#### Search and HTTP Application Layer
The application-facing behavior is concentrated in `web/classes/views.py`, mapped by `web/classes/urls.py` and included from `web/web/urls.py`. Search filters operate against the locally cached catalog by campus, term, subject, course number, and title. HTMX requests return incremental search-result markup rather than requiring full-page navigation, with the result fragment in `web/classes/templates/classes/partials/search_results.html`.

Rate limiting is a separate boundary in `web/classes/rate_limit.py`, backed by an atomic token-bucket Lua script at `web/classes/redis_scripts/token_bucket.lua`; this implies Redis as an optional/request-protection infrastructure dependency.

#### Schedule Construction Boundary
The server provides searchable section metadata; the interactive schedule is primarily client-managed. `web/classes/templates/classes/schedule_build.html` renders the planner shell and server-provided course/section results. `web/classes/static/js/schedule_build.js` owns section selection, lecture-plus-required-lab handling, weekly calendar rendering, overlap detection, credit totals, misc handling for unscheduled courses, JSON export, responsive navigation, and cookie persistence.

This design intentionally avoids user accounts and server-side schedule ownership: selected sections and display preferences remain in browser cookies.

#### UI Composition and Deployment Runtime
Django runs through standard WSGI or ASGI entry points at `web/web/wsgi.py` and `web/web/asgi.py`. Shared page layout is defined by `web/classes/templates/classes/base.html`; dynamic planner/search presentation is supported by `web/classes/static/css/schedule_build.css` and `web/classes/static/js/schedule_build.js`. Bootstrap and HTMX are UI dependencies, while JavaScript implements planner-specific state and rendering.

#### Primary Control Flow
1. An operator runs `main.py` to refresh WSU-derived catalog data into Django’s database.
2. A user reaches Django’s routed views and loads the schedule-builder page.
3. Search requests query local models and return full pages or HTMX search fragments.
4. The browser converts chosen sections into calendar state, validates temporal conflicts, and persists the plan locally.
5. Catalog refresh and user planning remain decoupled: WSU API access is confined to ingestion, while ordinary user traffic depends on the local database.

Main entry points: [`web/classes/views.py`](https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/views.py) (Search views), [`web/classes/models.py`](https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/models.py) (Catalog models), [`dataCollection/classHandler/campus.py`](https://github.com/ninjao9/crimson-scheduler/blob/main/dataCollection/classHandler/campus.py) (Hierarchy collectors), [`web/web/urls.py`](https://github.com/ninjao9/crimson-scheduler/blob/main/web/web/urls.py) (Root routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Catalog Ingestion"]
  node_importer["Catalog importer<br/>Python entry point<br/>[main.py]"]
  node_wsu_api{{"WSU Schedule API<br/>external API"}}
  node_collectors["Hierarchy collectors<br/>collection handlers<br/>[campus.py]"]
  node_transform["Data transformation<br/>data handler<br/>[data.py]"]
  node_storage["Catalog upserts<br/>storage handler<br/>[storage.py]"]
end

subgraph group_django["Django Application"]
  node_django_models["Catalog models<br/>Django models<br/>[models.py]"]
  node_migrations["Schema migrations<br/>Django migrations"]
  node_settings["Database settings<br/>Django settings<br/>[settings.py]"]
  node_root_urls["Root routing<br/>Django URLconf<br/>[urls.py]"]
  node_class_urls["Classes routes<br/>Django URLconf<br/>[urls.py]"]
  node_views["Search views<br/>Django views<br/>[views.py]"]
  node_rate_limit["Rate limiting<br/>request protection<br/>[rate_limit.py]"]
  node_token_bucket["Token bucket script<br/>Redis Lua<br/>[token_bucket.lua]"]
  node_wsgi["WSGI server entry<br/>Django WSGI<br/>[wsgi.py]"]
  node_asgi["ASGI server entry<br/>Django ASGI<br/>[asgi.py]"]
end

subgraph group_browser["Browser Planner"]
  node_schedule_page["Planner shell<br/>Django template"]
  node_search_fragment["Search results fragment<br/>HTMX template"]
  node_planner_js["Client schedule planner<br/>browser JavaScript<br/>[schedule_build.js]"]
  node_browser_cookies[("Plan cookies<br/>browser storage")]
end

node_database[("Course catalog database<br/>PostgreSQL / SQLite")]
node_redis[("Redis<br/>optional infrastructure")]

node_importer -->|"orchestrates"| node_collectors
node_collectors -->|"requests"| node_wsu_api
node_collectors -->|"normalizes responses"| node_transform
node_transform -->|"prepares records"| node_storage
node_storage -->|"upserts"| node_django_models
node_django_models -->|"persists catalog"| node_database
node_migrations -->|"evolves schema"| node_django_models
node_settings -->|"configures connection"| node_database
node_wsgi -->|"serves HTTP"| node_root_urls
node_asgi -->|"serves HTTP"| node_root_urls
node_root_urls -->|"includes"| node_class_urls
node_class_urls -->|"maps requests"| node_views
node_views -->|"queries local catalog"| node_django_models
node_views -->|"renders"| node_schedule_page
node_views -->|"returns for HTMX"| node_search_fragment
node_schedule_page -->|"loads"| node_planner_js
node_planner_js -->|"persists plan"| node_browser_cookies
node_rate_limit -->|"executes"| node_token_bucket
node_rate_limit -.->|"uses"| node_redis

click node_importer "https://github.com/ninjao9/crimson-scheduler/blob/main/main.py"
click node_collectors "https://github.com/ninjao9/crimson-scheduler/blob/main/dataCollection/classHandler/campus.py"
click node_transform "https://github.com/ninjao9/crimson-scheduler/blob/main/dataCollection/dataHandler/data.py"
click node_storage "https://github.com/ninjao9/crimson-scheduler/blob/main/dataCollection/dataHandler/storage.py"
click node_django_models "https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/models.py"
click node_migrations "https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/migrations/0012_course_has_required_lab_section_lab_metadata.py"
click node_settings "https://github.com/ninjao9/crimson-scheduler/blob/main/web/web/settings.py"
click node_root_urls "https://github.com/ninjao9/crimson-scheduler/blob/main/web/web/urls.py"
click node_class_urls "https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/urls.py"
click node_views "https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/views.py"
click node_rate_limit "https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/rate_limit.py"
click node_token_bucket "https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/redis_scripts/token_bucket.lua"
click node_schedule_page "https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/templates/classes/schedule_build.html"
click node_search_fragment "https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/templates/classes/partials/search_results.html"
click node_planner_js "https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/static/js/schedule_build.js"
click node_wsgi "https://github.com/ninjao9/crimson-scheduler/blob/main/web/web/wsgi.py"
click node_asgi "https://github.com/ninjao9/crimson-scheduler/blob/main/web/web/asgi.py"

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_importer,node_wsu_api,node_collectors,node_transform,node_storage toneBlue
class node_django_models,node_migrations,node_settings,node_root_urls,node_class_urls,node_views,node_rate_limit,node_token_bucket,node_wsgi,node_asgi toneAmber
class node_schedule_page,node_search_fragment,node_planner_js,node_browser_cookies toneMint
class node_database,node_redis toneNeutral
```

## Components

### Catalog Ingestion

- [Catalog importer](https://github.com/ninjao9/crimson-scheduler/blob/main/main.py): Python entry point · Operator-run catalog refresh. · `main.py`
- **WSU Schedule API**: external API
- [Hierarchy collectors](https://github.com/ninjao9/crimson-scheduler/blob/main/dataCollection/classHandler/campus.py): collection handlers · Traverses campus, semester, subject, and course data. · `dataCollection/classHandler/campus.py`
- [Data transformation](https://github.com/ninjao9/crimson-scheduler/blob/main/dataCollection/dataHandler/data.py): data handler · `dataCollection/dataHandler/data.py`
- [Catalog upserts](https://github.com/ninjao9/crimson-scheduler/blob/main/dataCollection/dataHandler/storage.py): storage handler · `dataCollection/dataHandler/storage.py`

### Django Application

- [Catalog models](https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/models.py): Django models · Owns courses, sections, meetings, enrollment, and schedule entities. · `web/classes/models.py`
- [Schema migrations](https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/migrations/0012_course_has_required_lab_section_lab_metadata.py): Django migrations · Includes required-lab and expanded meeting-time schema changes. · `web/classes/migrations/0012_course_has_required_lab_section_lab_metadata.py`
- [Database settings](https://github.com/ninjao9/crimson-scheduler/blob/main/web/web/settings.py): Django settings · `web/web/settings.py`
- [Root routing](https://github.com/ninjao9/crimson-scheduler/blob/main/web/web/urls.py): Django URLconf · `web/web/urls.py`
- [Classes routes](https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/urls.py): Django URLconf · `web/classes/urls.py`
- [Search views](https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/views.py): Django views · Filters the local catalog and serves planner pages or fragments. · `web/classes/views.py`
- [Rate limiting](https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/rate_limit.py): request protection · Optional Redis-backed token bucket. · `web/classes/rate_limit.py`
- [Token bucket script](https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/redis_scripts/token_bucket.lua): Redis Lua · `web/classes/redis_scripts/token_bucket.lua`
- [WSGI server entry](https://github.com/ninjao9/crimson-scheduler/blob/main/web/web/wsgi.py): Django WSGI · `web/web/wsgi.py`
- [ASGI server entry](https://github.com/ninjao9/crimson-scheduler/blob/main/web/web/asgi.py): Django ASGI · `web/web/asgi.py`

### Browser Planner

- [Planner shell](https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/templates/classes/schedule_build.html): Django template · `web/classes/templates/classes/schedule_build.html`
- [Search results fragment](https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/templates/classes/partials/search_results.html): HTMX template · `web/classes/templates/classes/partials/search_results.html`
- [Client schedule planner](https://github.com/ninjao9/crimson-scheduler/blob/main/web/classes/static/js/schedule_build.js): browser JavaScript · Owns selection, lab rules, calendar conflicts, credits, export, and persistence. · `web/classes/static/js/schedule_build.js`
- **Plan cookies**: browser storage · Stores selected sections and display preferences without accounts.

### Other components

- **Course catalog database**: PostgreSQL / SQLite · Production PostgreSQL with local SQLite support.
- **Redis**: optional infrastructure

## Connections

- Catalog importer → Hierarchy collectors: orchestrates
- Hierarchy collectors → WSU Schedule API: requests
- Hierarchy collectors → Data transformation: normalizes responses
- Data transformation → Catalog upserts: prepares records
- Catalog upserts → Catalog models: upserts
- Catalog models → Course catalog database: persists catalog
- Schema migrations → Catalog models: evolves schema
- Database settings → Course catalog database: configures connection
- WSGI server entry → Root routing: serves HTTP
- ASGI server entry → Root routing: serves HTTP
- Root routing → Classes routes: includes
- Classes routes → Search views: maps requests
- Search views → Catalog models: queries local catalog
- Search views → Planner shell: renders
- Search views → Search results fragment: returns for HTMX
- Planner shell → Client schedule planner: loads
- Client schedule planner → Plan cookies: persists plan
- Rate limiting → Token bucket script: executes
- Rate limiting → Redis: uses
