# momaimon/unical architecture

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

- Interactive diagram: https://gitdiagram.com/momaimon/unical
- Repository: https://github.com/momaimon/unical

## Overview

Unical is a university timetable planner whose documented user flow is course selection, schedule generation under constraints, and weekly-grid review; its README also describes manual and automatic modes, conflict detection, and export. In the visible implementation, scrape API routes fetch catalog data or trigger synchronization; the scraping service retrieves and maps university offerings into MongoDB, while repository-backed routes serve catalog records. The tree does not expose the planner, generator, grid, or export implementations, so those documented capabilities are represented at the app boundary rather than given speculative internal links. Evidence is limited to the README and indexed/read source excerpts.

Main entry points: [`lib/Scraping/scrape_service.ts`](https://github.com/momaimon/unical/blob/main/lib/Scraping/scrape_service.ts) (Sync orchestration), [`app/api/scrape`](https://github.com/momaimon/unical/tree/main/app/api/scrape) (Catalog routes), [`lib/db/db.ts`](https://github.com/momaimon/unical/blob/main/lib/db/db.ts) (Database connection), [`app/page.tsx`](https://github.com/momaimon/unical/blob/main/app/page.tsx) (Schedule planner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_planning["Timetable planning"]
  node_planner["Schedule planner<br/>[page.tsx]"]
  node_selection["Course selection"]
  node_generation["Schedule generation"]
  node_constraints["Schedule constraints"]
  node_conflicts["Conflict detection"]
  node_grid["Weekly grid"]
  node_export["Schedule export"]
end

subgraph group_api["Catalog API"]
  node_catalog_routes["Catalog routes"]
  node_scrape_routes["Sync routes"]
end

subgraph group_scraping["Data ingestion"]
  node_scrape_service["Sync orchestration<br/>[scrape_service.ts]"]
  node_scrape_client["University fetcher<br/>[scrape.ts]"]
  node_section_mapper["Section mapper<br/>[scrape_mappers.ts]"]
end

subgraph group_storage["Catalog storage"]
  node_college_repo["College repository"]
  node_degree_repo["Degree repository"]
  node_department_repo["Department repository"]
  node_course_repo["Course repository"]
  node_section_repo["Section repository"]
  node_pagination["Pagination helper<br/>[repo_util.ts]"]
  node_db_connection["Database connection<br/>[db.ts]"]
  node_college_model["College model<br/>[colleges.ts]"]
  node_degree_model["Degree model<br/>[degrees.ts]"]
  node_department_model["Department model<br/>[departments.ts]"]
  node_course_model["Course model<br/>[courses.ts]"]
  node_section_model["Section model<br/>[sections.ts]"]
  node_catalog_db[("MongoDB catalog")]
end

node_student(("Student"))
node_api_actor(("Admin or client"))
node_university["University offerings"]

node_student -->|"uses"| node_planner
node_planner -->|"supports"| node_selection
node_selection -->|"selects courses"| node_generation
node_generation -->|"applies"| node_constraints
node_generation -->|"checks overlaps"| node_conflicts
node_planner -->|"renders schedule"| node_grid
node_planner -->|"exports schedule"| node_export
node_api_actor -->|"requests sync"| node_scrape_routes
node_api_actor -->|"requests catalog"| node_catalog_routes
node_scrape_routes -->|"triggers sync"| node_scrape_service
node_catalog_routes -->|"queries colleges"| node_college_repo
node_catalog_routes -->|"queries degrees"| node_degree_repo
node_catalog_routes -->|"queries departments"| node_department_repo
node_catalog_routes -->|"queries courses"| node_course_repo
node_catalog_routes -->|"queries sections"| node_section_repo
node_scrape_service -->|"fetches pages"| node_scrape_client
node_scrape_client -->|"requests offerings"| node_university
node_scrape_service -->|"maps sections"| node_section_mapper
node_scrape_service -->|"upserts colleges"| node_college_model
node_scrape_service -->|"upserts degrees"| node_degree_model
node_scrape_service -->|"upserts departments"| node_department_model
node_scrape_service -->|"upserts courses"| node_course_model
node_scrape_service -->|"upserts sections"| node_section_model
node_college_repo -->|"connects"| node_db_connection
node_degree_repo -->|"connects"| node_db_connection
node_department_repo -->|"connects"| node_db_connection
node_course_repo -->|"connects"| node_db_connection
node_section_repo -->|"connects"| node_db_connection
node_course_repo -->|"uses pagination"| node_pagination
node_section_repo -->|"uses pagination"| node_pagination
node_college_repo -->|"queries"| node_college_model
node_degree_repo -->|"queries"| node_degree_model
node_department_repo -->|"queries"| node_department_model
node_course_repo -->|"queries"| node_course_model
node_section_repo -->|"queries"| node_section_model
node_college_model -.->|"persists"| node_catalog_db
node_degree_model -.->|"persists"| node_catalog_db
node_department_model -.->|"persists"| node_catalog_db
node_course_model -.->|"persists"| node_catalog_db
node_section_model -.->|"persists"| node_catalog_db

click node_planner "https://github.com/momaimon/unical/blob/main/app/page.tsx"
click node_selection "https://github.com/momaimon/unical/tree/main/app"
click node_generation "https://github.com/momaimon/unical/tree/main/app"
click node_constraints "https://github.com/momaimon/unical/tree/main/app"
click node_conflicts "https://github.com/momaimon/unical/tree/main/app"
click node_grid "https://github.com/momaimon/unical/tree/main/app"
click node_export "https://github.com/momaimon/unical/tree/main/app"
click node_catalog_routes "https://github.com/momaimon/unical/tree/main/app/api/scrape"
click node_scrape_routes "https://github.com/momaimon/unical/tree/main/app/api/scrape"
click node_scrape_service "https://github.com/momaimon/unical/blob/main/lib/Scraping/scrape_service.ts"
click node_scrape_client "https://github.com/momaimon/unical/blob/main/lib/Scraping/scrape.ts"
click node_section_mapper "https://github.com/momaimon/unical/blob/main/lib/Scraping/scrape_mappers.ts"
click node_college_repo "https://github.com/momaimon/unical/blob/main/lib/db/repositories/college_repository.ts"
click node_degree_repo "https://github.com/momaimon/unical/blob/main/lib/db/repositories/degree_repository.ts"
click node_department_repo "https://github.com/momaimon/unical/blob/main/lib/db/repositories/department_repository.ts"
click node_course_repo "https://github.com/momaimon/unical/blob/main/lib/db/repositories/course_repository.ts"
click node_section_repo "https://github.com/momaimon/unical/blob/main/lib/db/repositories/section_repository.ts"
click node_pagination "https://github.com/momaimon/unical/blob/main/lib/db/repositories/util/repo_util.ts"
click node_db_connection "https://github.com/momaimon/unical/blob/main/lib/db/db.ts"
click node_college_model "https://github.com/momaimon/unical/blob/main/lib/db/models/colleges.ts"
click node_degree_model "https://github.com/momaimon/unical/blob/main/lib/db/models/degrees.ts"
click node_department_model "https://github.com/momaimon/unical/blob/main/lib/db/models/departments.ts"
click node_course_model "https://github.com/momaimon/unical/blob/main/lib/db/models/courses.ts"
click node_section_model "https://github.com/momaimon/unical/blob/main/lib/db/models/sections.ts"

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_planner,node_selection,node_generation,node_constraints,node_conflicts,node_grid,node_export,node_api_actor toneBlue
class node_catalog_routes,node_scrape_routes toneAmber
class node_scrape_service,node_scrape_client,node_section_mapper toneMint
class node_college_repo,node_degree_repo,node_department_repo,node_course_repo,node_section_repo,node_pagination,node_db_connection,node_college_model,node_degree_model,node_department_model,node_course_model,node_section_model,node_catalog_db toneRose
class node_student,node_university toneIndigo
```

## Components

### Timetable planning

- [Schedule planner](https://github.com/momaimon/unical/blob/main/app/page.tsx): `app/page.tsx`
- [Course selection](https://github.com/momaimon/unical/tree/main/app): `app`
- [Schedule generation](https://github.com/momaimon/unical/tree/main/app): `app`
- [Schedule constraints](https://github.com/momaimon/unical/tree/main/app): `app`
- [Conflict detection](https://github.com/momaimon/unical/tree/main/app): `app`
- [Weekly grid](https://github.com/momaimon/unical/tree/main/app): `app`
- [Schedule export](https://github.com/momaimon/unical/tree/main/app): `app`

### Catalog API

- [Catalog routes](https://github.com/momaimon/unical/tree/main/app/api/scrape): `app/api/scrape`
- [Sync routes](https://github.com/momaimon/unical/tree/main/app/api/scrape): `app/api/scrape`

### Data ingestion

- [Sync orchestration](https://github.com/momaimon/unical/blob/main/lib/Scraping/scrape_service.ts): `lib/Scraping/scrape_service.ts`
- [University fetcher](https://github.com/momaimon/unical/blob/main/lib/Scraping/scrape.ts): `lib/Scraping/scrape.ts`
- [Section mapper](https://github.com/momaimon/unical/blob/main/lib/Scraping/scrape_mappers.ts): `lib/Scraping/scrape_mappers.ts`

### Catalog storage

- [College repository](https://github.com/momaimon/unical/blob/main/lib/db/repositories/college_repository.ts): `lib/db/repositories/college_repository.ts`
- [Degree repository](https://github.com/momaimon/unical/blob/main/lib/db/repositories/degree_repository.ts): `lib/db/repositories/degree_repository.ts`
- [Department repository](https://github.com/momaimon/unical/blob/main/lib/db/repositories/department_repository.ts): `lib/db/repositories/department_repository.ts`
- [Course repository](https://github.com/momaimon/unical/blob/main/lib/db/repositories/course_repository.ts): `lib/db/repositories/course_repository.ts`
- [Section repository](https://github.com/momaimon/unical/blob/main/lib/db/repositories/section_repository.ts): `lib/db/repositories/section_repository.ts`
- [Pagination helper](https://github.com/momaimon/unical/blob/main/lib/db/repositories/util/repo_util.ts): `lib/db/repositories/util/repo_util.ts`
- [Database connection](https://github.com/momaimon/unical/blob/main/lib/db/db.ts): `lib/db/db.ts`
- [College model](https://github.com/momaimon/unical/blob/main/lib/db/models/colleges.ts): `lib/db/models/colleges.ts`
- [Degree model](https://github.com/momaimon/unical/blob/main/lib/db/models/degrees.ts): `lib/db/models/degrees.ts`
- [Department model](https://github.com/momaimon/unical/blob/main/lib/db/models/departments.ts): `lib/db/models/departments.ts`
- [Course model](https://github.com/momaimon/unical/blob/main/lib/db/models/courses.ts): `lib/db/models/courses.ts`
- [Section model](https://github.com/momaimon/unical/blob/main/lib/db/models/sections.ts): `lib/db/models/sections.ts`
- **MongoDB catalog**

### Other components

- **Student**
- **Admin or client**
- **University offerings**

## Connections

- Student → Schedule planner: uses (evidence: `README.md`)
- Schedule planner → Course selection: supports (evidence: `README.md`)
- Course selection → Schedule generation: selects courses (evidence: `README.md`)
- Schedule generation → Schedule constraints: applies (evidence: `README.md`)
- Schedule generation → Conflict detection: checks overlaps (evidence: `README.md`)
- Schedule planner → Weekly grid: renders schedule (evidence: `README.md`)
- Schedule planner → Schedule export: exports schedule (evidence: `README.md`)
- Admin or client → Sync routes: requests sync (evidence: `app/api/scrape/sections/route.ts`)
- Admin or client → Catalog routes: requests catalog (evidence: `app/api/scrape/courses/route.ts`)
- Sync routes → Sync orchestration: triggers sync (evidence: `app/api/scrape/sections/route.ts`)
- Catalog routes → College repository: queries colleges (evidence: `app/api/scrape/colleges/route.ts`)
- Catalog routes → Degree repository: queries degrees (evidence: `app/api/scrape/degrees/routes.ts`)
- Catalog routes → Department repository: queries departments (evidence: `app/api/scrape/departments/route.ts`)
- Catalog routes → Course repository: queries courses (evidence: `app/api/scrape/courses/route.ts`)
- Catalog routes → Section repository: queries sections (evidence: `app/api/scrape/sections/route.ts`)
- Sync orchestration → University fetcher: fetches pages (evidence: `lib/Scraping/scrape_service.ts`)
- University fetcher → University offerings: requests offerings (evidence: `README.md`)
- Sync orchestration → Section mapper: maps sections (evidence: `lib/Scraping/scrape_service.ts`)
- Sync orchestration → College model: upserts colleges (evidence: `lib/Scraping/scrape_service.ts`)
- Sync orchestration → Degree model: upserts degrees (evidence: `lib/Scraping/scrape_service.ts`)
- Sync orchestration → Department model: upserts departments (evidence: `lib/Scraping/scrape_service.ts`)
- Sync orchestration → Course model: upserts courses (evidence: `lib/Scraping/scrape_service.ts`)
- Sync orchestration → Section model: upserts sections (evidence: `lib/Scraping/scrape_service.ts`)
- College repository → Database connection: connects (evidence: `lib/db/repositories/college_repository.ts`)
- Degree repository → Database connection: connects (evidence: `lib/db/repositories/degree_repository.ts`)
- Department repository → Database connection: connects (evidence: `lib/db/repositories/department_repository.ts`)
- Course repository → Database connection: connects (evidence: `lib/db/repositories/course_repository.ts`)
- Section repository → Database connection: connects (evidence: `lib/db/repositories/section_repository.ts`)
- Course repository → Pagination helper: uses pagination (evidence: `lib/db/repositories/course_repository.ts`)
- Section repository → Pagination helper: uses pagination (evidence: `lib/db/repositories/section_repository.ts`)
- College repository → College model: queries (evidence: `lib/db/repositories/college_repository.ts`)
- Degree repository → Degree model: queries (evidence: `lib/db/repositories/degree_repository.ts`)
- Department repository → Department model: queries (evidence: `lib/db/repositories/department_repository.ts`)
- Course repository → Course model: queries (evidence: `lib/db/repositories/course_repository.ts`)
- Section repository → Section model: queries (evidence: `lib/db/repositories/section_repository.ts`)
- College model → MongoDB catalog: persists
- Degree model → MongoDB catalog: persists
- Department model → MongoDB catalog: persists
- Course model → MongoDB catalog: persists
- Section model → MongoDB catalog: persists
