How abhi6160/orchestration-system works
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: App.tsx Workspace controller · handoffEngine.ts Handoff engine · index.ts Express orchestrator · handoffs.ts Handoff routes
Components 20
React/Vite client
- Client bootstrap
client/src/main.tsx - Workspace controller · Owns active conversation and provider state.
client/src/App.tsx - API client · Calls backend APIs or uses fallback simulation.
client/src/api/client.ts - Client contracts
client/src/types/index.ts - Context warning · Shows non-blocking capacity warnings.
client/src/components/ContextWarning.tsx - Handoff review · Lets users inspect, edit, and approve a transfer.
client/src/components/HandoffModal.tsx
Root Express service
- Express orchestrator
server/src/index.ts - Conversation routes · Manages threads and active context.
server/src/routes/conversations.ts - Handoff routes
server/src/routes/handoffs.ts - Provider telemetry routes
server/src/routes/providers.ts - SQLite database · Conversation and handoff metadata store.
server/src/db/database.ts - Demo scenarios
server/src/db/seed.ts
Provider orchestration
- Handoff engine · Measures context, synthesizes transfer payloads, and targets destination models.
server/src/providers/handoffEngine.ts - Provider contracts
server/src/providers/types.ts - Claude adapter
server/src/providers/claudeAdapter.ts - Gemini adapter
server/src/providers/geminiAdapter.ts
Alternate implementations
Separate or duplicate implementation boundaries.
- Python backend alternative · Separate implementation, not on the Express request path.
backend/app/main.py - Expanded nested copy · Feature-oriented duplicate with a broader adapter registry.
Other components
- Anthropic API
- Google Gemini API
Connections 21
- 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