# hssling/cbme-agent architecture

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

- Interactive diagram: https://gitdiagram.com/hssling/cbme-agent
- Repository: https://github.com/hssling/cbme-agent

## Overview

1. **What this repository is**
   - This is a monorepo for a CBME (competency-based medical education) platform centered on curriculum planning, GMER-aligned scheduling, competency catalogues, analytics, and teaching-material generation.
   - The runtime architecture is split across a shared Python core, a FastAPI backend, and multiple client surfaces.

2. **Core domain engine: `packages/cbme_core`**
   - The shared Python package is the main business-logic boundary.
   - It contains curriculum models and planners (`curriculum.py`, `planner.py`), schemas, literature/reference helpers, data templates, exporters, and AI-oriented materials support.
   - Both the API service and the Streamlit app consume this package, so the curriculum/schedule logic is centralized rather than duplicated.

3. **Primary backend: `services/api`**
   - The FastAPI service is the system’s integration layer and API gateway for clients.
   - It exposes routers for auth, institutions, batches, catalogue, schedule, materials, analytics, admin, and health.
   - This is the main boundary where external clients talk to the platform over REST.

4. **Data layer and persistence**
   - The backend uses SQLAlchemy models plus Alembic migrations, which indicates a relational persistence layer behind the API.
   - Config and dependency modules isolate database setup and request-scoped access.
   - The migrations show the core persisted entities are institution/catalogue and the platform’s operational records around scheduling and access.

5. **Asynchronous work / task processing**
   - `services/api/app/task_queue.py` and the materials endpoints imply some jobs are queued rather than handled synchronously.
   - The client-side “materials” flow in the web app polls job status, so generation tasks are treated as background work with status retrieval.

6. **Web application: `apps/web`**
   - The Next.js app is the institutional dashboard and operational UI.
   - It uses an auth context, a protected-route hook, and a shared API client to communicate with the FastAPI backend.
   - Pages cover login, dashboard, catalogue, coverage, materials, onboarding, and schedule workflows, so it is the main administrator/faculty front end.

7. **Mobile application: `apps/mobile`**
   - The React Native app provides a separate faculty/student client surface.
   - It uses Redux slices for auth and curriculum state plus navigation and screen modules for login, curriculum browsing, and dashboard-style views.
   - Architecturally, this is a thin client over the same backend concepts, optimized for mobile access rather than direct computation.

8. **Prototype / analytical UI: `apps/streamlit`**
   - The Streamlit app is a lightweight Python UI that consumes the shared core package directly.
   - It is useful as a rapid demonstration layer for curriculum briefs, schedules, integration summaries, and teaching resources without going through the full web stack.
   - This makes it a second consumer of the domain engine, but not the primary production UI.

9. **Extension and auxiliary tools**
   - `apps/vscode-codex` is a VS Code extension, likely for authoring or assisting with curriculum content.
   - The many top-level Python scripts generate reports, Excel workbooks, PDFs, proposals, assessments, and roadmaps; these are offline tooling rather than core runtime services.
   - They feed the documentation/output pipeline rather than the request/response application path.

10. **Documentation and regulatory inputs**
   - `docs/nmc-gmer` holds the GMER and related medical education reference PDFs.
   - These documents are part of the architecture because they inform the scheduling and competency alignment logic in the core package and exported reports.
   - The repo also contains large proposal/report artifacts, showing a strong documentation and compliance workflow around the software.

11. **Build, CI/CD, and deployment boundaries**
   - GitHub Actions covers Python CI, security scanning, docs, and deployment.
   - `docker-compose.yml` and the API Dockerfile indicate containerized deployment of the backend stack.
   - The repo is organized so backend, web, mobile, and auxiliary tools can be developed and deployed independently.

12. **End-to-end data flow**
   - Reference standards and imported catalogue data feed the shared core curriculum logic.
   - The API persists institutional data and exposes schedule, analytics, and materials endpoints.
   - Web/mobile clients call the API for operational workflows, while Streamlit can directly render core outputs for demos and internal analysis.
   - Exporters in the core package and the standalone scripts turn computed plans into CSV, Excel, PDF, and document artifacts for institutional use.

Main entry points: [`services/api/app/main.py`](https://github.com/hssling/cbme-agent/blob/main/services/api/app/main.py) (API app), [`services/api/app/routers`](https://github.com/hssling/cbme-agent/tree/main/services/api/app/routers) (Routers), [`packages/cbme_core/cbme_core`](https://github.com/hssling/cbme-agent/tree/main/packages/cbme_core/cbme_core) (CBME core), [`.github/workflows`](https://github.com/hssling/cbme-agent/blob/main/.github/workflows) (CI / deploy)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Shared core"]
  node_cbme_core["CBME core<br/>python package"]
  node_curriculum["Curriculum<br/>domain models<br/>[curriculum.py]"]
  node_planner["Planner<br/>schedule engine<br/>[planner.py]"]
  node_exporters["Exporters<br/>output formats<br/>[exporters.py]"]
  node_ai_materials["Materials AI<br/>content helpers<br/>[ai_materials.py]"]
end

subgraph group_api["Backend API"]
  node_api_main["API app<br/>FastAPI service<br/>[main.py]"]
  node_api_routers["Routers<br/>http endpoints"]
  node_api_models["Models<br/>[models.py]"]
  node_api_db["DB layer<br/>persistence setup<br/>[database.py]"]
  node_api_queue["Task queue<br/>background jobs<br/>[task_queue.py]"]
end

subgraph group_clients["Client apps"]
  node_web_app["Web app<br/>Next.js dashboard"]
  node_web_auth["Auth UI<br/>session boundary<br/>[AuthContext.tsx]"]
  node_web_api["API client<br/>frontend integration<br/>[api.ts]"]
  node_mobile_app["Mobile app<br/>React Native client<br/>[App.tsx]"]
  node_mobile_store["Mobile state<br/>Redux state"]
  node_streamlit_app["Streamlit UI<br/>prototype app<br/>[app.py]"]
end

subgraph group_ops["Docs & tooling"]
  node_docs_gmer["GMER docs<br/>reference corpus"]
  node_scripts["Offline scripts<br/>generators"]
  node_ci_cd["CI / deploy<br/>automation<br/>[workflows]"]
end

node_docs_gmer -->|"standards feed"| node_cbme_core
node_curriculum -->|"input"| node_planner
node_docs_gmer -->|"aligns"| node_planner
node_planner -->|"produces"| node_exporters
node_cbme_core -->|"direct consume"| node_streamlit_app
node_cbme_core -->|"shared logic"| node_api_main
node_api_main -->|"mounts"| node_api_routers
node_api_routers -->|"persists"| node_api_models
node_api_models -->|"uses"| node_api_db
node_api_routers -->|"dispatches"| node_api_queue
node_api_routers -->|"calls"| node_cbme_core
node_web_app -->|"wraps"| node_web_auth
node_web_app -->|"calls"| node_web_api
node_web_api -->|"REST"| node_api_main
node_mobile_app -->|"uses"| node_mobile_store
node_mobile_store -->|"syncs"| node_api_main
node_scripts -->|"reuses"| node_exporters
node_scripts -.->|"operates on"| node_api_models
node_ci_cd -->|"builds"| node_api_main
node_ci_cd -->|"builds"| node_web_app
node_ci_cd -.->|"supports"| node_mobile_app

click node_cbme_core "https://github.com/hssling/cbme-agent/tree/main/packages/cbme_core/cbme_core"
click node_curriculum "https://github.com/hssling/cbme-agent/blob/main/packages/cbme_core/cbme_core/curriculum.py"
click node_planner "https://github.com/hssling/cbme-agent/blob/main/packages/cbme_core/cbme_core/planner.py"
click node_exporters "https://github.com/hssling/cbme-agent/blob/main/packages/cbme_core/cbme_core/exporters.py"
click node_ai_materials "https://github.com/hssling/cbme-agent/blob/main/packages/cbme_core/cbme_core/ai_materials.py"
click node_api_main "https://github.com/hssling/cbme-agent/blob/main/services/api/app/main.py"
click node_api_routers "https://github.com/hssling/cbme-agent/tree/main/services/api/app/routers"
click node_api_models "https://github.com/hssling/cbme-agent/blob/main/services/api/app/models.py"
click node_api_db "https://github.com/hssling/cbme-agent/blob/main/services/api/app/database.py"
click node_api_queue "https://github.com/hssling/cbme-agent/blob/main/services/api/app/task_queue.py"
click node_web_app "https://github.com/hssling/cbme-agent/tree/main/apps/web/src/pages"
click node_web_auth "https://github.com/hssling/cbme-agent/blob/main/apps/web/src/context/AuthContext.tsx"
click node_web_api "https://github.com/hssling/cbme-agent/blob/main/apps/web/src/lib/api.ts"
click node_mobile_app "https://github.com/hssling/cbme-agent/blob/main/apps/mobile/src/App.tsx"
click node_mobile_store "https://github.com/hssling/cbme-agent/tree/main/apps/mobile/src/store"
click node_streamlit_app "https://github.com/hssling/cbme-agent/blob/main/apps/streamlit/app.py"
click node_docs_gmer "https://github.com/hssling/cbme-agent/tree/main/docs/nmc-gmer"
click node_ci_cd "https://github.com/hssling/cbme-agent/blob/main/.github/workflows"

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_cbme_core,node_curriculum,node_planner,node_exporters,node_ai_materials toneBlue
class node_api_main,node_api_routers,node_api_models,node_api_db,node_api_queue toneAmber
class node_web_app,node_web_auth,node_web_api,node_mobile_app,node_mobile_store,node_streamlit_app toneMint
class node_docs_gmer,node_scripts,node_ci_cd toneRose
```

## Components

### Shared core

Central CBME domain engine used by multiple runtimes.

- [CBME core](https://github.com/hssling/cbme-agent/tree/main/packages/cbme_core/cbme_core): python package · Shared domain package for curriculum planning, schemas, literature, exporting, and AI materials support. · `packages/cbme_core/cbme_core`
- [Curriculum](https://github.com/hssling/cbme-agent/blob/main/packages/cbme_core/cbme_core/curriculum.py): domain models · Curriculum structures and competency-oriented data models. · `packages/cbme_core/cbme_core/curriculum.py`
- [Planner](https://github.com/hssling/cbme-agent/blob/main/packages/cbme_core/cbme_core/planner.py): schedule engine · Core planning logic that turns curriculum and reference inputs into schedules and plans. · `packages/cbme_core/cbme_core/planner.py`
- [Exporters](https://github.com/hssling/cbme-agent/blob/main/packages/cbme_core/cbme_core/exporters.py): output formats · Transforms core plans into CSV, Excel, PDF, and document artifacts. · `packages/cbme_core/cbme_core/exporters.py`
- [Materials AI](https://github.com/hssling/cbme-agent/blob/main/packages/cbme_core/cbme_core/ai_materials.py): content helpers · AI-oriented teaching-material generation and related helpers. · `packages/cbme_core/cbme_core/ai_materials.py`

### Backend API

FastAPI service, persistence, and background work.

- [API app](https://github.com/hssling/cbme-agent/blob/main/services/api/app/main.py): FastAPI service · Backend entrypoint and integration boundary for external clients. · `services/api/app/main.py`
- [Routers](https://github.com/hssling/cbme-agent/tree/main/services/api/app/routers): http endpoints · REST surface for auth, institutions, batches, catalogue, schedule, materials, analytics, admin, and health. · `services/api/app/routers`
- [Models](https://github.com/hssling/cbme-agent/blob/main/services/api/app/models.py): ORM models · SQLAlchemy persistence models for institutional and operational records. · `services/api/app/models.py`
- [DB layer](https://github.com/hssling/cbme-agent/blob/main/services/api/app/database.py): persistence setup · Database configuration and session wiring for request-scoped access. · `services/api/app/database.py`
- [Task queue](https://github.com/hssling/cbme-agent/blob/main/services/api/app/task_queue.py): background jobs · Background job processing used by asynchronous materials workflows. · `services/api/app/task_queue.py`

### Client apps

Web, mobile, and prototype user surfaces.

- [Web app](https://github.com/hssling/cbme-agent/tree/main/apps/web/src/pages): Next.js dashboard · Institutional admin and faculty UI for operational workflows. · `apps/web/src/pages`
- [Auth UI](https://github.com/hssling/cbme-agent/blob/main/apps/web/src/context/AuthContext.tsx): session boundary · Auth context and protected-route handling for the web client. · `apps/web/src/context/AuthContext.tsx`
- [API client](https://github.com/hssling/cbme-agent/blob/main/apps/web/src/lib/api.ts): frontend integration · Shared web client for talking to the backend API. · `apps/web/src/lib/api.ts`
- [Mobile app](https://github.com/hssling/cbme-agent/blob/main/apps/mobile/src/App.tsx): React Native client · Mobile faculty/student client for curriculum and dashboard views. · `apps/mobile/src/App.tsx`
- [Mobile state](https://github.com/hssling/cbme-agent/tree/main/apps/mobile/src/store): Redux state · Auth and curriculum slices that coordinate the mobile experience. · `apps/mobile/src/store`
- [Streamlit UI](https://github.com/hssling/cbme-agent/blob/main/apps/streamlit/app.py): prototype app · Lightweight analytical and demo UI that consumes the shared core directly. · `apps/streamlit/app.py`

### Docs & tooling

Offline generators, reference material, and repo-level delivery tooling.

- [GMER docs](https://github.com/hssling/cbme-agent/tree/main/docs/nmc-gmer): reference corpus · Medical education standards and curriculum PDFs used as domain inputs. · `docs/nmc-gmer`
- **Offline scripts**: generators · Standalone report, workbook, proposal, and assessment generation scripts.
- [CI / deploy](https://github.com/hssling/cbme-agent/blob/main/.github/workflows): automation · GitHub Actions, Docker, and repo deployment boundaries. · `.github/workflows`

## Connections

- GMER docs → CBME core: standards feed · Reference PDFs inform curriculum alignment and scheduling logic.
- Curriculum → Planner: input · Planner consumes curriculum structures and competencies.
- GMER docs → Planner: aligns · Planner uses GMER-aligned reference material.
- Planner → Exporters: produces · Planned schedules and plans are exported into deliverable formats.
- CBME core → Streamlit UI: direct consume · Streamlit renders the shared core outputs without the API layer.
- CBME core → API app: shared logic · Backend relies on the shared domain engine for core CBME behavior.
- API app → Routers: mounts · The FastAPI app wires the route surface.
- Routers → Models: persists · Routers operate on ORM-backed institutional and operational data.
- Models → DB layer: uses · Models are backed by the database/session configuration.
- Routers → Task queue: dispatches · Materials and similar workflows can offload work to background jobs.
- Routers → CBME core: calls · Schedule, catalogue, and materials endpoints reuse core planning logic.
- Web app → Auth UI: wraps · The web UI uses an auth context and protected routes.
- Web app → API client: calls · Pages use the shared client to talk to the backend.
- API client → API app: REST · Web requests target the FastAPI service.
- Mobile app → Mobile state: uses · Screens depend on Redux state for auth and curriculum.
- Mobile state → API app: syncs · Mobile state is populated through backend API calls.
- Offline scripts → Exporters: reuses · Offline generators reuse the same document and workbook outputs.
- Offline scripts → Models: operates on · Some scripts seed or inspect persisted platform data.
- CI / deploy → API app: builds · Deployment workflows package and ship the backend service.
- CI / deploy → Web app: builds · Frontend workflows validate and deploy the web client.
- CI / deploy → Mobile app: supports · Repository automation supports the mobile runtime as a separate surface.
