# therizwan/flagshiprouter architecture

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

- Interactive diagram: https://gitdiagram.com/therizwan/flagshiprouter
- Repository: https://github.com/therizwan/flagshiprouter

## Overview

FlagshipRouter is a local AI gateway for coding tools, with a dashboard and management APIs for configuring providers, keys, models, and tool integrations. A typical request enters through the OpenAI-compatible gateway, is translated and dispatched to a provider executor, then returns in the client’s format. The README also documents media APIs, combos, token-saving tools, usage/quota views, and proxy pools. Several links below are documented capabilities; unsampled implementation details are not inferred as call relationships.

Main entry points: [`open-sse/handlers/chatCore.js`](https://github.com/therizwan/flagshiprouter/blob/main/open-sse/handlers/chatCore.js) (Chat handling), [`src/lib/localDb.js`](https://github.com/therizwan/flagshiprouter/blob/main/src/lib/localDb.js) (Local data store), [`src/app/api/v1/models/route.js`](https://github.com/therizwan/flagshiprouter/blob/main/src/app/api/v1/models/route.js) (Models API), [`open-sse/index.js`](https://github.com/therizwan/flagshiprouter/blob/main/open-sse/index.js) (HTTP gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway runtime"]
  node_gateway_api["HTTP gateway<br/>[index.js]"]
  node_chat["Chat handling<br/>[chatCore.js]"]
  node_translate["Format translation<br/>[index.js]"]
  node_dispatch["Provider executors<br/>[index.js]"]
end

subgraph group_providers["Provider management"]
  node_provider_policy["Provider policy<br/>[policy.js]"]
  node_provider_service["Provider catalog<br/>[provider.js]"]
  node_models_api["Models API<br/>[route.js]"]
  node_connections_api["Provider management API<br/>[route.js]"]
  node_db[("Local data store<br/>[localDb.js]")]
end

subgraph group_dashboard["Dashboard experience"]
  node_models_ui["Models screen<br/>[page.js]"]
  node_endpoint_ui["Endpoint and keys"]
  node_cli_tools_ui["CLI tool setup"]
  node_usage_ui["Usage and quota<br/>[page.js]"]
end

subgraph group_media["Media and tools"]
  node_combos["Model combos<br/>[combo.js]"]
  node_media_api["Media handlers"]
  node_embedding_api["Embeddings<br/>[embeddings.js]"]
  node_search_api["Search and fetch<br/>[index.js]"]
  node_rtk["Token-saving tools<br/>[index.js]"]
end

subgraph group_operations["Local operations"]
  node_oauth["Provider sign-in<br/>[route.js]"]
  node_mitm["Tool traffic MITM<br/>[server.js]"]
  node_proxy_pools["Proxy pools<br/>[page.js]"]
end

node_tool(("Coding tool"))
node_upstream(("AI providers"))

node_tool -->|"sends requests"| node_gateway_api
node_gateway_api -->|"routes chat"| node_chat
node_chat -->|"translates formats"| node_translate
node_chat -->|"selects executor"| node_dispatch
node_dispatch -.->|"calls provider"| node_upstream
node_chat -->|"uses provider config"| node_provider_service
node_provider_service -.->|"applies policy"| node_provider_policy
node_models_api -->|"reads connections"| node_db
node_models_api -->|"supplies models"| node_models_ui
node_connections_api -.->|"manages connections"| node_db
node_endpoint_ui -->|"provides endpoint key"| node_tool
node_cli_tools_ui -->|"writes tool config"| node_tool
node_oauth -->|"saves connections"| node_db
node_combos -.->|"offers combos"| node_models_ui
node_media_api -.->|"requests generation"| node_upstream
node_embedding_api -.->|"requests embeddings"| node_upstream
node_search_api -.->|"requests search"| node_upstream
node_rtk -.->|"reduces output"| node_tool
node_usage_ui -.->|"shows usage"| node_tool
node_mitm -.->|"intercepts traffic"| node_tool
node_proxy_pools -.->|"configures pools"| node_db

click node_gateway_api "https://github.com/therizwan/flagshiprouter/blob/main/open-sse/index.js"
click node_chat "https://github.com/therizwan/flagshiprouter/blob/main/open-sse/handlers/chatCore.js"
click node_translate "https://github.com/therizwan/flagshiprouter/blob/main/open-sse/translator/index.js"
click node_dispatch "https://github.com/therizwan/flagshiprouter/blob/main/open-sse/executors/index.js"
click node_provider_policy "https://github.com/therizwan/flagshiprouter/blob/main/open-sse/providers/policy.js"
click node_provider_service "https://github.com/therizwan/flagshiprouter/blob/main/open-sse/services/provider.js"
click node_models_api "https://github.com/therizwan/flagshiprouter/blob/main/src/app/api/v1/models/route.js"
click node_connections_api "https://github.com/therizwan/flagshiprouter/blob/main/src/app/api/providers/route.js"
click node_db "https://github.com/therizwan/flagshiprouter/blob/main/src/lib/localDb.js"
click node_models_ui "https://github.com/therizwan/flagshiprouter/blob/main/src/app/(dashboard)/dashboard/models/page.js"
click node_endpoint_ui "https://github.com/therizwan/flagshiprouter/blob/main/src/app/(dashboard)/dashboard/endpoint/EndpointPageClient.js"
click node_cli_tools_ui "https://github.com/therizwan/flagshiprouter/blob/main/src/app/(dashboard)/dashboard/cli-tools/CLIToolsPageClient.js"
click node_usage_ui "https://github.com/therizwan/flagshiprouter/blob/main/src/app/(dashboard)/dashboard/usage/page.js"
click node_combos "https://github.com/therizwan/flagshiprouter/blob/main/open-sse/services/combo.js"
click node_media_api "https://github.com/therizwan/flagshiprouter/blob/main/open-sse/handlers/imageGenerationCore.js"
click node_embedding_api "https://github.com/therizwan/flagshiprouter/blob/main/src/sse/handlers/embeddings.js"
click node_search_api "https://github.com/therizwan/flagshiprouter/blob/main/open-sse/handlers/search/index.js"
click node_rtk "https://github.com/therizwan/flagshiprouter/blob/main/open-sse/rtk/index.js"
click node_oauth "https://github.com/therizwan/flagshiprouter/blob/main/src/app/api/oauth/%5Bprovider%5D/%5Baction%5D/route.js"
click node_mitm "https://github.com/therizwan/flagshiprouter/blob/main/src/mitm/server.js"
click node_proxy_pools "https://github.com/therizwan/flagshiprouter/blob/main/src/app/(dashboard)/dashboard/proxy-pools/page.js"

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_gateway_api,node_chat,node_translate,node_dispatch toneBlue
class node_provider_policy,node_provider_service,node_models_api,node_connections_api,node_db toneAmber
class node_models_ui,node_endpoint_ui,node_cli_tools_ui,node_usage_ui toneMint
class node_combos,node_media_api,node_embedding_api,node_search_api,node_rtk toneRose
class node_oauth,node_mitm,node_proxy_pools,node_tool,node_upstream toneIndigo
```

## Components

### Gateway runtime

- [HTTP gateway](https://github.com/therizwan/flagshiprouter/blob/main/open-sse/index.js): `open-sse/index.js`
- [Chat handling](https://github.com/therizwan/flagshiprouter/blob/main/open-sse/handlers/chatCore.js): `open-sse/handlers/chatCore.js`
- [Format translation](https://github.com/therizwan/flagshiprouter/blob/main/open-sse/translator/index.js): `open-sse/translator/index.js`
- [Provider executors](https://github.com/therizwan/flagshiprouter/blob/main/open-sse/executors/index.js): `open-sse/executors/index.js`

### Provider management

- [Provider policy](https://github.com/therizwan/flagshiprouter/blob/main/open-sse/providers/policy.js): `open-sse/providers/policy.js`
- [Provider catalog](https://github.com/therizwan/flagshiprouter/blob/main/open-sse/services/provider.js): `open-sse/services/provider.js`
- [Models API](https://github.com/therizwan/flagshiprouter/blob/main/src/app/api/v1/models/route.js): `src/app/api/v1/models/route.js`
- [Provider management API](https://github.com/therizwan/flagshiprouter/blob/main/src/app/api/providers/route.js): `src/app/api/providers/route.js`
- [Local data store](https://github.com/therizwan/flagshiprouter/blob/main/src/lib/localDb.js): `src/lib/localDb.js`

### Dashboard experience

- [Models screen](https://github.com/therizwan/flagshiprouter/blob/main/src/app/(dashboard)/dashboard/models/page.js): `src/app/(dashboard)/dashboard/models/page.js`
- [Endpoint and keys](https://github.com/therizwan/flagshiprouter/blob/main/src/app/(dashboard)/dashboard/endpoint/EndpointPageClient.js): `src/app/(dashboard)/dashboard/endpoint/EndpointPageClient.js`
- [CLI tool setup](https://github.com/therizwan/flagshiprouter/blob/main/src/app/(dashboard)/dashboard/cli-tools/CLIToolsPageClient.js): `src/app/(dashboard)/dashboard/cli-tools/CLIToolsPageClient.js`
- [Usage and quota](https://github.com/therizwan/flagshiprouter/blob/main/src/app/(dashboard)/dashboard/usage/page.js): `src/app/(dashboard)/dashboard/usage/page.js`

### Media and tools

- [Model combos](https://github.com/therizwan/flagshiprouter/blob/main/open-sse/services/combo.js): `open-sse/services/combo.js`
- [Media handlers](https://github.com/therizwan/flagshiprouter/blob/main/open-sse/handlers/imageGenerationCore.js): `open-sse/handlers/imageGenerationCore.js`
- [Embeddings](https://github.com/therizwan/flagshiprouter/blob/main/src/sse/handlers/embeddings.js): `src/sse/handlers/embeddings.js`
- [Search and fetch](https://github.com/therizwan/flagshiprouter/blob/main/open-sse/handlers/search/index.js): `open-sse/handlers/search/index.js`
- [Token-saving tools](https://github.com/therizwan/flagshiprouter/blob/main/open-sse/rtk/index.js): `open-sse/rtk/index.js`

### Local operations

- [Provider sign-in](https://github.com/therizwan/flagshiprouter/blob/main/src/app/api/oauth/%5Bprovider%5D/%5Baction%5D/route.js): `src/app/api/oauth/[provider]/[action]/route.js`
- [Tool traffic MITM](https://github.com/therizwan/flagshiprouter/blob/main/src/mitm/server.js): `src/mitm/server.js`
- [Proxy pools](https://github.com/therizwan/flagshiprouter/blob/main/src/app/(dashboard)/dashboard/proxy-pools/page.js): `src/app/(dashboard)/dashboard/proxy-pools/page.js`

### Other components

- **Coding tool**
- **AI providers**

## Connections

- Coding tool → HTTP gateway: sends requests (evidence: `README.md`)
- HTTP gateway → Chat handling: routes chat (evidence: `open-sse/index.js`)
- Chat handling → Format translation: translates formats (evidence: `open-sse/handlers/chatCore.js`)
- Chat handling → Provider executors: selects executor (evidence: `open-sse/handlers/chatCore.js`)
- Provider executors → AI providers: calls provider
- Chat handling → Provider catalog: uses provider config (evidence: `open-sse/handlers/chatCore.js`)
- Provider catalog → Provider policy: applies policy (evidence: `README.md`)
- Models API → Local data store: reads connections (evidence: `src/app/api/v1/models/route.js`)
- Models API → Models screen: supplies models (evidence: `README.md`)
- Provider management API → Local data store: manages connections (evidence: `src/app/api/providers/route.js`)
- Endpoint and keys → Coding tool: provides endpoint key (evidence: `README.md`)
- CLI tool setup → Coding tool: writes tool config (evidence: `README.md`)
- Provider sign-in → Local data store: saves connections
- Model combos → Models screen: offers combos (evidence: `README.md`)
- Media handlers → AI providers: requests generation
- Embeddings → AI providers: requests embeddings
- Search and fetch → AI providers: requests search
- Token-saving tools → Coding tool: reduces output (evidence: `README.md`)
- Usage and quota → Coding tool: shows usage (evidence: `README.md`)
- Tool traffic MITM → Coding tool: intercepts traffic (evidence: `README.md`)
- Proxy pools → Local data store: configures pools (evidence: `README.md`)
