# abhi6160/orchestration-system architecture

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

- Interactive diagram: https://gitdiagram.com/abhi6160/orchestration-system
- Repository: https://github.com/abhi6160/orchestration-system

## Overview

#### Purpose and repository shape
ContextBridge is a multi-model AI orchestration workspace: it tracks a conversation’s context usage, warns near capacity, and creates a compact structured handoff for moving work between LLM providers. The repository contains overlapping implementations: the root TypeScript React/Express application, a nested expanded copy, and a Python backend alternative. The root TypeScript stack is the architecture described by the README.

#### Runtime entry points
- React/Vite client bootstraps at `client/src/main.tsx` and owns workspace/session UI in `client/src/App.tsx`.
- Node/Express orchestrator starts at `server/src/index.ts`.
- An alternate FastAPI-style backend starts at `backend/app/main.py`; it should be treated as a separate implementation boundary rather than part of the Express request path.
- The nested `Orchestration-System-feat-contextbridge-ui/` contains another client/server tree, including additional provider adapters, likely a feature branch or duplicate deliverable.

#### Client workspace and API boundary
The browser application renders conversations, provider state, token warnings, and handoff review/approval flows. `client/src/App.tsx` is the active-session controller; presentation stages are separated into composition, message display, navigation, and modal components.
- API calls and fallback simulation are isolated in `client/src/api/client.ts`.
- Shared client contracts are in `client/src/types/index.ts`.
- Handoff and warning UX are centered on `client/src/components/HandoffModal.tsx` and `client/src/components/ContextWarning.tsx`.
This boundary lets the UI operate against the backend API or simulated data when services are unavailable.

#### Conversation lifecycle and persistence
Express routes expose conversation/thread management, active-context retrieval, handoff operations, and provider telemetry.
- Route boundaries: `server/src/routes/conversations.ts`, `server/src/routes/handoffs.ts`, `server/src/routes/providers.ts`.
- SQLite initialization and schema ownership reside in `server/src/db/database.ts`; demo/default scenarios are populated through `server/src/db/seed.ts`.
- Runtime database artifacts are under `server/data/`.
The primary persisted flow is: client selects or updates a conversation → conversation route reads/writes SQLite → returned messages/context state drives token telemetry and UI state.

#### Provider abstraction and orchestration
Provider-specific API integration is behind adapter contracts, insulating routes and the handoff engine from individual LLM SDKs.
- Contracts: `server/src/providers/types.ts`.
- Available root adapters: `server/src/providers/claudeAdapter.ts` and `server/src/providers/geminiAdapter.ts`.
- The model-transition workflow is coordinated by `server/src/providers/handoffEngine.ts`.
A handoff route gathers current conversation state, calculates/synthesizes a compact transfer payload, presents it for review, then targets a selected provider/model. The nested implementation broadens this registry with OpenAI, Cohere, DeepSeek, Grok, Llama, and Mistral adapters under `Orchestration-System-feat-contextbridge-ui/server/src/providers/`.

#### Context-management stages
The core control flow is:
1. Capture conversation messages and selected provider/model.
2. Measure token consumption against that model’s context capacity.
3. Surface a non-blocking warning around the documented 82% threshold.
4. Trigger structured compression/synthesis rather than copying raw history.
5. Let the user inspect/edit/approve the handoff.
6. Continue the thread through the destination provider, retaining source/destination state as conversation metadata.

Relevant implementation boundaries are `server/src/providers/handoffEngine.ts`, `server/src/routes/handoffs.ts`, and `client/src/components/HandoffModal.tsx`.

#### Infrastructure and external services
The primary runtime is Node.js with Express and TypeScript on the server, React/Vite/TypeScript in the browser, and SQLite via `better-sqlite3` for local persistence. External service boundaries are Anthropic Claude and Google Gemini APIs, represented by `server/src/providers/claudeAdapter.ts` and `server/src/providers/geminiAdapter.ts`; credentials are expected through environment configuration. The Python alternative contains analogous provider, token-analysis, memory, and handoff responsibilities in `backend/app/services/`.

Main entry points: [`client/src/App.tsx`](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/App.tsx) (Workspace controller), [`server/src/providers/handoffEngine.ts`](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/providers/handoffEngine.ts) (Handoff engine), [`server/src/index.ts`](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/index.ts) (Express orchestrator), [`server/src/routes/handoffs.ts`](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/routes/handoffs.ts) (Handoff routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React/Vite client"]
  node_client_bootstrap["Client bootstrap<br/>React entry<br/>[main.tsx]"]
  node_workspace["Workspace controller<br/>session UI<br/>[App.tsx]"]
  node_client_api["API client<br/>API boundary<br/>[client.ts]"]
  node_client_contracts["Client contracts<br/>TypeScript types<br/>[index.ts]"]
  node_context_warning["Context warning<br/>UI component<br/>[ContextWarning.tsx]"]
  node_handoff_modal["Handoff review<br/>UI component<br/>[HandoffModal.tsx]"]
end

subgraph group_server["Root Express service"]
  node_express["Express orchestrator<br/>Node entry<br/>[index.ts]"]
  node_conversation_routes["Conversation routes<br/>Express routes<br/>[conversations.ts]"]
  node_handoff_routes["Handoff routes<br/>Express routes<br/>[handoffs.ts]"]
  node_provider_routes["Provider telemetry routes<br/>Express routes<br/>[providers.ts]"]
  node_sqlite[("SQLite database<br/>persistence<br/>[database.ts]")]
  node_seed["Demo scenarios<br/>database seed<br/>[seed.ts]"]
end

subgraph group_providers["Provider orchestration"]
  node_handoff_engine{{"Handoff engine<br/>transition workflow<br/>[handoffEngine.ts]"}}
  node_provider_contracts["Provider contracts<br/>adapter interface<br/>[types.ts]"]
  node_claude["Claude adapter<br/>provider adapter<br/>[claudeAdapter.ts]"]
  node_gemini["Gemini adapter<br/>provider adapter<br/>[geminiAdapter.ts]"]
end

subgraph group_alternate["Alternate implementations"]
  node_fastapi_alternative["Python backend alternative<br/>FastAPI entry<br/>[main.py]"]
  node_nested_copy["Expanded nested copy<br/>duplicate client/server tree"]
end

node_claude_api(("Anthropic API<br/>external LLM"))
node_gemini_api(("Google Gemini API<br/>external LLM"))

node_client_bootstrap -->|"mounts"| node_workspace
node_workspace -->|"uses"| node_client_api
node_workspace -->|"uses"| node_client_contracts
node_workspace -->|"renders capacity state"| node_context_warning
node_workspace -->|"renders approval flow"| node_handoff_modal
node_client_api -->|"HTTP API"| node_express
node_express -->|"serves"| node_conversation_routes
node_express -->|"serves"| node_handoff_routes
node_express -->|"serves"| node_provider_routes
node_conversation_routes -->|"reads and writes threads"| node_sqlite
node_handoff_routes -->|"loads and retains state"| node_sqlite
node_handoff_routes -->|"coordinates"| node_handoff_engine
node_provider_routes -->|"reports provider state"| node_handoff_engine
node_seed -->|"populates defaults"| node_sqlite
node_handoff_engine -->|"uses abstraction"| node_provider_contracts
node_claude -->|"implements"| node_provider_contracts
node_gemini -->|"implements"| node_provider_contracts
node_handoff_engine -->|"selects source/destination"| node_claude
node_handoff_engine -->|"selects source/destination"| node_gemini
node_claude -->|"provider request"| node_claude_api
node_gemini -->|"provider request"| node_gemini_api

click node_client_bootstrap "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/main.tsx"
click node_workspace "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/App.tsx"
click node_client_api "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/api/client.ts"
click node_client_contracts "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/types/index.ts"
click node_context_warning "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/components/ContextWarning.tsx"
click node_handoff_modal "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/components/HandoffModal.tsx"
click node_express "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/index.ts"
click node_conversation_routes "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/routes/conversations.ts"
click node_handoff_routes "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/routes/handoffs.ts"
click node_provider_routes "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/routes/providers.ts"
click node_sqlite "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/db/database.ts"
click node_seed "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/db/seed.ts"
click node_handoff_engine "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/providers/handoffEngine.ts"
click node_provider_contracts "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/providers/types.ts"
click node_claude "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/providers/claudeAdapter.ts"
click node_gemini "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/providers/geminiAdapter.ts"
click node_fastapi_alternative "https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/backend/app/main.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_client_bootstrap,node_workspace,node_client_api,node_client_contracts,node_context_warning,node_handoff_modal toneBlue
class node_express,node_conversation_routes,node_handoff_routes,node_provider_routes,node_sqlite,node_seed toneAmber
class node_handoff_engine,node_provider_contracts,node_claude,node_gemini toneMint
class node_fastapi_alternative,node_nested_copy toneRose
class node_claude_api,node_gemini_api toneNeutral
```

## Components

### React/Vite client

- [Client bootstrap](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/main.tsx): React entry · `client/src/main.tsx`
- [Workspace controller](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/App.tsx): session UI · Owns active conversation and provider state. · `client/src/App.tsx`
- [API client](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/api/client.ts): API boundary · Calls backend APIs or uses fallback simulation. · `client/src/api/client.ts`
- [Client contracts](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/types/index.ts): TypeScript types · `client/src/types/index.ts`
- [Context warning](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/components/ContextWarning.tsx): UI component · Shows non-blocking capacity warnings. · `client/src/components/ContextWarning.tsx`
- [Handoff review](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/client/src/components/HandoffModal.tsx): UI component · Lets users inspect, edit, and approve a transfer. · `client/src/components/HandoffModal.tsx`

### Root Express service

- [Express orchestrator](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/index.ts): Node entry · `server/src/index.ts`
- [Conversation routes](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/routes/conversations.ts): Express routes · Manages threads and active context. · `server/src/routes/conversations.ts`
- [Handoff routes](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/routes/handoffs.ts): Express routes · `server/src/routes/handoffs.ts`
- [Provider telemetry routes](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/routes/providers.ts): Express routes · `server/src/routes/providers.ts`
- [SQLite database](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/db/database.ts): persistence · Conversation and handoff metadata store. · `server/src/db/database.ts`
- [Demo scenarios](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/db/seed.ts): database seed · `server/src/db/seed.ts`

### Provider orchestration

- [Handoff engine](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/providers/handoffEngine.ts): transition workflow · Measures context, synthesizes transfer payloads, and targets destination models. · `server/src/providers/handoffEngine.ts`
- [Provider contracts](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/providers/types.ts): adapter interface · `server/src/providers/types.ts`
- [Claude adapter](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/providers/claudeAdapter.ts): provider adapter · `server/src/providers/claudeAdapter.ts`
- [Gemini adapter](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/server/src/providers/geminiAdapter.ts): provider adapter · `server/src/providers/geminiAdapter.ts`

### Alternate implementations

Separate or duplicate implementation boundaries.

- [Python backend alternative](https://github.com/abhi6160/orchestration-system/blob/feat/contextbridge-ui/backend/app/main.py): FastAPI entry · Separate implementation, not on the Express request path. · `backend/app/main.py`
- **Expanded nested copy**: duplicate client/server tree · Feature-oriented duplicate with a broader adapter registry.

### Other components

- **Anthropic API**: external LLM
- **Google Gemini API**: external LLM

## Connections

- Client bootstrap → Workspace controller: mounts
- Workspace controller → API client: uses
- Workspace controller → Client contracts: uses
- Workspace controller → Context warning: renders capacity state
- Workspace controller → Handoff review: renders approval flow
- API client → Express orchestrator: HTTP API
- Express orchestrator → Conversation routes: serves
- Express orchestrator → Handoff routes: serves
- Express orchestrator → Provider telemetry routes: serves
- Conversation routes → SQLite database: reads and writes threads
- Handoff routes → SQLite database: loads and retains state
- Handoff routes → Handoff engine: coordinates
- Provider telemetry routes → Handoff engine: reports provider state
- Demo scenarios → SQLite database: populates defaults
- Handoff engine → Provider contracts: uses abstraction
- Claude adapter → Provider contracts: implements
- Gemini adapter → Provider contracts: implements
- Handoff engine → Claude adapter: selects source/destination
- Handoff engine → Gemini adapter: selects source/destination
- Claude adapter → Anthropic API: provider request
- Gemini adapter → Google Gemini API: provider request
