# op7418/codepilot architecture

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

- Interactive diagram: https://gitdiagram.com/op7418/codepilot
- Repository: https://github.com/op7418/codepilot

## Overview

CodePilot is a multi-provider AI-agent desktop client. A user configures a provider, starts a chat, and receives a streamed response; the chat API coordinates runtime selection, model execution, and local persistence. The product also includes remote messaging, extensions, workspace memory, media generation, scheduled tasks, and project tools. The graph combines README-documented capabilities with relationships visible in excerpts and the SOURCE INDEX; unsampled subsystems are represented at their supported directory paths, without asserting internal calls that were not shown.

Main entry points: [`src/app/api/chat/route.ts`](https://github.com/op7418/codepilot/blob/main/src/app/api/chat/route.ts) (Chat API), [`src/lib/bridge/conversation-engine.ts`](https://github.com/op7418/codepilot/blob/main/src/lib/bridge/conversation-engine.ts) (Bridge conversations), [`src/lib/db.ts`](https://github.com/op7418/codepilot/blob/main/src/lib/db.ts) (Local SQLite), [`src/components/chat`](https://github.com/op7418/codepilot/tree/main/src/components/chat) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop and chat"]
  node_shell["Electron shell<br/>[main.ts]"]
  node_chatui["Chat interface"]
  node_chatapi["Chat API<br/>[route.ts]"]
  node_streamstate["Stream manager"]
  node_database[("Local SQLite<br/>[db.ts]")]
end

subgraph group_ai["AI configuration"]
  node_providerui["Provider settings"]
  node_providerapi["Provider APIs"]
  node_claude["Model runtime<br/>[claude-client.ts]"]
  node_codex["Codex runtime"]
end

subgraph group_extensions["Extensions and remote"]
  node_mcp["MCP management<br/>[McpManager.tsx]"]
  node_skills["Skills management<br/>[SkillsManager.tsx]"]
  node_bridge["Remote bridge<br/>[bridge-manager.ts]"]
  node_bridgeengine["Bridge conversations"]
end

subgraph group_workspace["Workspace tools"]
  node_projecttools["Files and Git"]
  node_workspaceapi["Assistant workspace"]
end

subgraph group_agent["Assistant capabilities"]
  node_media["Media studio"]
  node_scheduler["Task scheduler"]
  node_analytics["Usage analytics"]
end

node_user(("Desktop user"))
node_phone(("Remote user"))

node_user -->|"opens app"| node_shell
node_user -->|"starts conversation"| node_chatui
node_chatui -.->|"submits turn"| node_chatapi
node_chatapi -->|"streams response"| node_claude
node_chatapi -->|"reads and writes"| node_database
node_chatapi -.->|"streams to client"| node_streamstate
node_providerui -->|"configures providers"| node_providerapi
node_providerapi -->|"persists configuration"| node_database
node_chatapi -.->|"selects runtime"| node_codex
node_user -->|"manages servers"| node_mcp
node_user -->|"manages skills"| node_skills
node_phone -->|"sends messages"| node_bridge
node_bridge -->|"routes conversations"| node_bridgeengine
node_bridgeengine -->|"streams turn"| node_claude
node_bridgeengine -->|"stores messages"| node_database
node_user -->|"manages project"| node_projecttools
node_user -->|"personalizes assistant"| node_workspaceapi
node_user -->|"generates media"| node_media
node_user -->|"schedules tasks"| node_scheduler
node_user -->|"views usage"| node_analytics

click node_shell "https://github.com/op7418/codepilot/blob/main/electron/main.ts"
click node_chatui "https://github.com/op7418/codepilot/tree/main/src/components/chat"
click node_chatapi "https://github.com/op7418/codepilot/blob/main/src/app/api/chat/route.ts"
click node_streamstate "https://github.com/op7418/codepilot/blob/main/src/lib/stream-session-manager.ts"
click node_database "https://github.com/op7418/codepilot/blob/main/src/lib/db.ts"
click node_providerui "https://github.com/op7418/codepilot/blob/main/src/components/settings/ProviderManager.tsx"
click node_providerapi "https://github.com/op7418/codepilot/tree/main/src/app/api/providers"
click node_claude "https://github.com/op7418/codepilot/blob/main/src/lib/claude-client.ts"
click node_codex "https://github.com/op7418/codepilot/blob/main/src/lib/codex/app-server-manager.ts"
click node_mcp "https://github.com/op7418/codepilot/blob/main/src/components/plugins/McpManager.tsx"
click node_skills "https://github.com/op7418/codepilot/blob/main/src/components/skills/SkillsManager.tsx"
click node_bridge "https://github.com/op7418/codepilot/blob/main/src/lib/bridge/bridge-manager.ts"
click node_bridgeengine "https://github.com/op7418/codepilot/blob/main/src/lib/bridge/conversation-engine.ts"
click node_projecttools "https://github.com/op7418/codepilot/tree/main/src/app/api"
click node_workspaceapi "https://github.com/op7418/codepilot/tree/main/src/app/api/workspace"
click node_media "https://github.com/op7418/codepilot/tree/main/src/app/api/media"
click node_scheduler "https://github.com/op7418/codepilot/tree/main/src/app/api/tasks"
click node_analytics "https://github.com/op7418/codepilot/tree/main/src/app/api/usage"

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_shell,node_chatui,node_chatapi,node_streamstate,node_database,node_user,node_phone toneBlue
class node_providerui,node_providerapi,node_claude,node_codex toneAmber
class node_mcp,node_skills,node_bridge,node_bridgeengine toneMint
class node_projecttools,node_workspaceapi toneRose
class node_media,node_scheduler,node_analytics toneIndigo
```

## Components

### Desktop and chat

- [Electron shell](https://github.com/op7418/codepilot/blob/main/electron/main.ts): `electron/main.ts`
- [Chat interface](https://github.com/op7418/codepilot/tree/main/src/components/chat): `src/components/chat`
- [Chat API](https://github.com/op7418/codepilot/blob/main/src/app/api/chat/route.ts): `src/app/api/chat/route.ts`
- [Stream manager](https://github.com/op7418/codepilot/blob/main/src/lib/stream-session-manager.ts): `src/lib/stream-session-manager.ts`
- [Local SQLite](https://github.com/op7418/codepilot/blob/main/src/lib/db.ts): `src/lib/db.ts`

### AI configuration

- [Provider settings](https://github.com/op7418/codepilot/blob/main/src/components/settings/ProviderManager.tsx): `src/components/settings/ProviderManager.tsx`
- [Provider APIs](https://github.com/op7418/codepilot/tree/main/src/app/api/providers): `src/app/api/providers`
- [Model runtime](https://github.com/op7418/codepilot/blob/main/src/lib/claude-client.ts): `src/lib/claude-client.ts`
- [Codex runtime](https://github.com/op7418/codepilot/blob/main/src/lib/codex/app-server-manager.ts): `src/lib/codex/app-server-manager.ts`

### Extensions and remote

- [MCP management](https://github.com/op7418/codepilot/blob/main/src/components/plugins/McpManager.tsx): `src/components/plugins/McpManager.tsx`
- [Skills management](https://github.com/op7418/codepilot/blob/main/src/components/skills/SkillsManager.tsx): `src/components/skills/SkillsManager.tsx`
- [Remote bridge](https://github.com/op7418/codepilot/blob/main/src/lib/bridge/bridge-manager.ts): `src/lib/bridge/bridge-manager.ts`
- [Bridge conversations](https://github.com/op7418/codepilot/blob/main/src/lib/bridge/conversation-engine.ts): `src/lib/bridge/conversation-engine.ts`

### Workspace tools

- [Files and Git](https://github.com/op7418/codepilot/tree/main/src/app/api): `src/app/api`
- [Assistant workspace](https://github.com/op7418/codepilot/tree/main/src/app/api/workspace): `src/app/api/workspace`

### Assistant capabilities

- [Media studio](https://github.com/op7418/codepilot/tree/main/src/app/api/media): `src/app/api/media`
- [Task scheduler](https://github.com/op7418/codepilot/tree/main/src/app/api/tasks): `src/app/api/tasks`
- [Usage analytics](https://github.com/op7418/codepilot/tree/main/src/app/api/usage): `src/app/api/usage`

### Other components

- **Desktop user**
- **Remote user**

## Connections

- Desktop user → Electron shell: opens app (evidence: `README.md`)
- Desktop user → Chat interface: starts conversation (evidence: `README.md`)
- Chat interface → Chat API: submits turn
- Chat API → Model runtime: streams response (evidence: `src/app/api/chat/route.ts`)
- Chat API → Local SQLite: reads and writes (evidence: `src/app/api/chat/route.ts`)
- Chat API → Stream manager: streams to client
- Provider settings → Provider APIs: configures providers (evidence: `README.md`)
- Provider APIs → Local SQLite: persists configuration (evidence: `src/app/api/providers/route.ts`)
- Chat API → Codex runtime: selects runtime
- Desktop user → MCP management: manages servers (evidence: `README.md`)
- Desktop user → Skills management: manages skills (evidence: `README.md`)
- Remote user → Remote bridge: sends messages (evidence: `README.md`)
- Remote bridge → Bridge conversations: routes conversations (evidence: `src/lib/bridge/bridge-manager.ts`)
- Bridge conversations → Model runtime: streams turn (evidence: `src/lib/bridge/conversation-engine.ts`)
- Bridge conversations → Local SQLite: stores messages (evidence: `src/lib/bridge/conversation-engine.ts`)
- Desktop user → Files and Git: manages project (evidence: `README.md`)
- Desktop user → Assistant workspace: personalizes assistant (evidence: `README.md`)
- Desktop user → Media studio: generates media (evidence: `README.md`)
- Desktop user → Task scheduler: schedules tasks (evidence: `README.md`)
- Desktop user → Usage analytics: views usage (evidence: `README.md`)
