# themdmohsin/scaffold architecture

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

- Interactive diagram: https://gitdiagram.com/themdmohsin/scaffold
- Repository: https://github.com/themdmohsin/scaffold

## Overview

This repository combines the Scaffold project-coordination product (a React dashboard and FastAPI engine) with a substantial OpenCode application tree. Scaffold users sign in, select or create a project, then manage tasks, teammates, environment settings, decisions, contracts, and activity; the dashboard talks to the engine, which persists domain data. The engine also ingests default-branch GitHub pushes and exposes an MCP server. OpenCode’s server routes and TUI are represented as a separate runtime branch. Several backend and OpenCode links rely on the SOURCE INDEX; unsampled subsystems are kept broad where their internal wiring is not shown.

Main entry points: [`engine/app/routes/github_webhook.py`](https://github.com/themdmohsin/scaffold/blob/main/engine/app/routes/github_webhook.py) (GitHub ingestion), [`engine/app/main.py`](https://github.com/themdmohsin/scaffold/blob/main/engine/app/main.py) (FastAPI engine), [`dashboard/src/lib/api.ts`](https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/lib/api.ts) (Engine API client), [`engine/app/db/session.py`](https://github.com/themdmohsin/scaffold/blob/main/engine/app/db/session.py) (Database sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_scaffold_ui["Scaffold dashboard"]
  node_dashboard_routes["Dashboard routes<br/>[App.tsx]"]
  node_auth_ui["Session and identity<br/>[auth.tsx]"]
  node_project_shell["Project workspace<br/>[ProjectLayout.tsx]"]
  node_project_views["Project views"]
  node_dashboard_api["Engine API client<br/>[api.ts]"]
  node_query_cache["Query cache<br/>[queryClient.ts]"]
  node_realtime["Realtime refresh<br/>[useRealtime.ts]"]
end

subgraph group_engine_api["Scaffold engine"]
  node_engine["FastAPI engine<br/>[main.py]"]
  node_auth_routes["Authentication routes<br/>[auth.py]"]
  node_domain_routes["Project API routes"]
  node_github_ingest["GitHub ingestion<br/>[github_webhook.py]"]
  node_mcp_server["MCP interface<br/>[mcp_server.py]"]
end

subgraph group_engine_domain["Engine domain services"]
  node_auth_service["Identity and access<br/>[auth.py]"]
  node_coordination["Coordination services<br/>[coordination.py]"]
  node_reasoning["Reasoning and retrieval<br/>[reasoning.py]"]
  node_conflict["Conflict detection"]
  node_diff_parser["Diff parsing<br/>[diff_parser.py]"]
  node_db_session["Database sessions<br/>[session.py]"]
  node_db_models[("Domain records<br/>[models.py]")]
end

subgraph group_opencode["OpenCode runtime"]
  node_opencode_routes["HTTP route assembly<br/>[routes.ts]"]
  node_opencode_handlers["Server handlers<br/>[handlers.ts]"]
  node_tui_app["Terminal interface<br/>[app.tsx]"]
  node_tui_route["Terminal routing<br/>[route.tsx]"]
end

node_user(("Project user"))
node_supabase["Supabase auth"]
node_postgres[("PostgreSQL")]
node_github["GitHub"]

node_user -->|"uses"| node_dashboard_routes
node_dashboard_routes -->|"checks session"| node_auth_ui
node_dashboard_routes -->|"opens workspace"| node_project_shell
node_dashboard_routes -->|"routes to"| node_project_views
node_auth_ui -->|"restores session"| node_supabase
node_auth_ui -->|"loads identity"| node_dashboard_api
node_project_shell -->|"loads project data"| node_dashboard_api
node_project_shell -->|"subscribes"| node_realtime
node_project_views -->|"requests domain data"| node_dashboard_api
node_dashboard_api -->|"calls API"| node_engine
node_dashboard_api -->|"gets access token"| node_supabase
node_realtime -->|"invalidates queries"| node_query_cache
node_engine -->|"mounts routes"| node_auth_routes
node_engine -->|"mounts routes"| node_domain_routes
node_engine -->|"mounts webhook"| node_github_ingest
node_engine -->|"mounts MCP"| node_mcp_server
node_auth_routes -->|"uses identity service"| node_auth_service
node_domain_routes -.->|"uses database sessions"| node_db_session
node_domain_routes -.->|"checks access"| node_auth_service
node_github -.->|"sends push events"| node_github_ingest
node_github_ingest -->|"parses changes"| node_diff_parser
node_github_ingest -->|"checks conflicts"| node_conflict
node_github_ingest -->|"summarizes changes"| node_reasoning
node_github_ingest -->|"writes records"| node_db_session
node_mcp_server -->|"uses services"| node_coordination
node_mcp_server -->|"uses database"| node_db_session
node_db_session -.->|"loads records"| node_db_models
node_db_session -->|"connects"| node_postgres
node_opencode_routes -->|"provides handlers"| node_opencode_handlers
node_tui_app -->|"uses routing"| node_tui_route

click node_dashboard_routes "https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/App.tsx"
click node_auth_ui "https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/lib/auth.tsx"
click node_project_shell "https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/pages/ProjectLayout.tsx"
click node_project_views "https://github.com/themdmohsin/scaffold/tree/main/dashboard/src/pages"
click node_dashboard_api "https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/lib/api.ts"
click node_query_cache "https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/lib/queryClient.ts"
click node_realtime "https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/lib/useRealtime.ts"
click node_engine "https://github.com/themdmohsin/scaffold/blob/main/engine/app/main.py"
click node_auth_routes "https://github.com/themdmohsin/scaffold/blob/main/engine/app/routes/auth.py"
click node_domain_routes "https://github.com/themdmohsin/scaffold/tree/main/engine/app/routes"
click node_github_ingest "https://github.com/themdmohsin/scaffold/blob/main/engine/app/routes/github_webhook.py"
click node_mcp_server "https://github.com/themdmohsin/scaffold/blob/main/engine/app/mcp_server.py"
click node_auth_service "https://github.com/themdmohsin/scaffold/blob/main/engine/app/services/auth.py"
click node_coordination "https://github.com/themdmohsin/scaffold/blob/main/engine/app/services/coordination.py"
click node_reasoning "https://github.com/themdmohsin/scaffold/blob/main/engine/app/services/reasoning.py"
click node_conflict "https://github.com/themdmohsin/scaffold/blob/main/engine/app/services/conflict_service.py"
click node_diff_parser "https://github.com/themdmohsin/scaffold/blob/main/engine/app/services/diff_parser.py"
click node_db_session "https://github.com/themdmohsin/scaffold/blob/main/engine/app/db/session.py"
click node_db_models "https://github.com/themdmohsin/scaffold/blob/main/engine/app/db/models.py"
click node_opencode_routes "https://github.com/themdmohsin/scaffold/blob/main/opencode-plugin/opencode/packages/server/src/routes.ts"
click node_opencode_handlers "https://github.com/themdmohsin/scaffold/blob/main/opencode-plugin/opencode/packages/server/src/handlers.ts"
click node_tui_app "https://github.com/themdmohsin/scaffold/blob/main/opencode-plugin/opencode/packages/tui/src/app.tsx"
click node_tui_route "https://github.com/themdmohsin/scaffold/blob/main/opencode-plugin/opencode/packages/tui/src/context/route.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_dashboard_routes,node_auth_ui,node_project_shell,node_project_views,node_dashboard_api,node_query_cache,node_realtime,node_user toneBlue
class node_engine,node_auth_routes,node_domain_routes,node_github_ingest,node_mcp_server,node_postgres toneAmber
class node_auth_service,node_coordination,node_reasoning,node_conflict,node_diff_parser,node_db_session,node_db_models toneMint
class node_opencode_routes,node_opencode_handlers,node_tui_app,node_tui_route toneRose
class node_supabase,node_github toneIndigo
```

## Components

### Scaffold dashboard

- [Dashboard routes](https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/App.tsx): `dashboard/src/App.tsx`
- [Session and identity](https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/lib/auth.tsx): `dashboard/src/lib/auth.tsx`
- [Project workspace](https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/pages/ProjectLayout.tsx): `dashboard/src/pages/ProjectLayout.tsx`
- [Project views](https://github.com/themdmohsin/scaffold/tree/main/dashboard/src/pages): `dashboard/src/pages`
- [Engine API client](https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/lib/api.ts): `dashboard/src/lib/api.ts`
- [Query cache](https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/lib/queryClient.ts): `dashboard/src/lib/queryClient.ts`
- [Realtime refresh](https://github.com/themdmohsin/scaffold/blob/main/dashboard/src/lib/useRealtime.ts): `dashboard/src/lib/useRealtime.ts`

### Scaffold engine

- [FastAPI engine](https://github.com/themdmohsin/scaffold/blob/main/engine/app/main.py): `engine/app/main.py`
- [Authentication routes](https://github.com/themdmohsin/scaffold/blob/main/engine/app/routes/auth.py): `engine/app/routes/auth.py`
- [Project API routes](https://github.com/themdmohsin/scaffold/tree/main/engine/app/routes): `engine/app/routes`
- [GitHub ingestion](https://github.com/themdmohsin/scaffold/blob/main/engine/app/routes/github_webhook.py): `engine/app/routes/github_webhook.py`
- [MCP interface](https://github.com/themdmohsin/scaffold/blob/main/engine/app/mcp_server.py): `engine/app/mcp_server.py`

### Engine domain services

- [Identity and access](https://github.com/themdmohsin/scaffold/blob/main/engine/app/services/auth.py): `engine/app/services/auth.py`
- [Coordination services](https://github.com/themdmohsin/scaffold/blob/main/engine/app/services/coordination.py): `engine/app/services/coordination.py`
- [Reasoning and retrieval](https://github.com/themdmohsin/scaffold/blob/main/engine/app/services/reasoning.py): `engine/app/services/reasoning.py`
- [Conflict detection](https://github.com/themdmohsin/scaffold/blob/main/engine/app/services/conflict_service.py): `engine/app/services/conflict_service.py`
- [Diff parsing](https://github.com/themdmohsin/scaffold/blob/main/engine/app/services/diff_parser.py): `engine/app/services/diff_parser.py`
- [Database sessions](https://github.com/themdmohsin/scaffold/blob/main/engine/app/db/session.py): `engine/app/db/session.py`
- [Domain records](https://github.com/themdmohsin/scaffold/blob/main/engine/app/db/models.py): `engine/app/db/models.py`

### OpenCode runtime

- [HTTP route assembly](https://github.com/themdmohsin/scaffold/blob/main/opencode-plugin/opencode/packages/server/src/routes.ts): `opencode-plugin/opencode/packages/server/src/routes.ts`
- [Server handlers](https://github.com/themdmohsin/scaffold/blob/main/opencode-plugin/opencode/packages/server/src/handlers.ts): `opencode-plugin/opencode/packages/server/src/handlers.ts`
- [Terminal interface](https://github.com/themdmohsin/scaffold/blob/main/opencode-plugin/opencode/packages/tui/src/app.tsx): `opencode-plugin/opencode/packages/tui/src/app.tsx`
- [Terminal routing](https://github.com/themdmohsin/scaffold/blob/main/opencode-plugin/opencode/packages/tui/src/context/route.tsx): `opencode-plugin/opencode/packages/tui/src/context/route.tsx`

### Other components

- **Project user**
- **Supabase auth**
- **PostgreSQL**
- **GitHub**

## Connections

- Project user → Dashboard routes: uses (evidence: `dashboard/src/App.tsx`)
- Dashboard routes → Session and identity: checks session (evidence: `dashboard/src/App.tsx`)
- Dashboard routes → Project workspace: opens workspace (evidence: `dashboard/src/App.tsx`)
- Dashboard routes → Project views: routes to (evidence: `dashboard/src/App.tsx`)
- Session and identity → Supabase auth: restores session (evidence: `dashboard/src/lib/auth.tsx`)
- Session and identity → Engine API client: loads identity (evidence: `dashboard/src/lib/auth.tsx`)
- Project workspace → Engine API client: loads project data (evidence: `dashboard/src/pages/ProjectLayout.tsx`)
- Project workspace → Realtime refresh: subscribes (evidence: `dashboard/src/pages/ProjectLayout.tsx`)
- Project views → Engine API client: requests domain data (evidence: `dashboard/src/pages/TasksPage.tsx`)
- Engine API client → FastAPI engine: calls API (evidence: `dashboard/src/lib/api.ts`)
- Engine API client → Supabase auth: gets access token (evidence: `dashboard/src/lib/api.ts`)
- Realtime refresh → Query cache: invalidates queries (evidence: `dashboard/src/lib/useRealtime.ts`)
- FastAPI engine → Authentication routes: mounts routes (evidence: `engine/app/main.py`)
- FastAPI engine → Project API routes: mounts routes (evidence: `engine/app/main.py`)
- FastAPI engine → GitHub ingestion: mounts webhook (evidence: `engine/app/main.py`)
- FastAPI engine → MCP interface: mounts MCP (evidence: `engine/app/main.py`)
- Authentication routes → Identity and access: uses identity service (evidence: `engine/app/routes/auth.py`)
- Project API routes → Database sessions: uses database sessions (evidence: `engine/app/routes/tasks.py`)
- Project API routes → Identity and access: checks access (evidence: `engine/app/routes/tasks.py`)
- GitHub → GitHub ingestion: sends push events
- GitHub ingestion → Diff parsing: parses changes (evidence: `engine/app/routes/github_webhook.py`)
- GitHub ingestion → Conflict detection: checks conflicts (evidence: `engine/app/routes/github_webhook.py`)
- GitHub ingestion → Reasoning and retrieval: summarizes changes (evidence: `engine/app/routes/github_webhook.py`)
- GitHub ingestion → Database sessions: writes records (evidence: `engine/app/routes/github_webhook.py`)
- MCP interface → Coordination services: uses services (evidence: `engine/app/mcp_server.py`)
- MCP interface → Database sessions: uses database (evidence: `engine/app/mcp_server.py`)
- Database sessions → Domain records: loads records
- Database sessions → PostgreSQL: connects (evidence: `engine/app/db/session.py`)
- HTTP route assembly → Server handlers: provides handlers (evidence: `opencode-plugin/opencode/packages/server/src/routes.ts`)
- Terminal interface → Terminal routing: uses routing (evidence: `opencode-plugin/opencode/packages/tui/src/app.tsx`)
