# artinf0/9router architecture

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

- Interactive diagram: https://gitdiagram.com/artinf0/9router
- Repository: https://github.com/artinf0/9router

## Overview

9Router is a local AI gateway for coding tools: clients send compatible requests to its API, which translates formats and routes requests to configured providers. The dashboard manages provider connections and exposes model, usage, CLI-tool, and tunnel controls. The README also documents RTK request compression, quota tracking, automatic fallback, and token refresh. The graph includes documented product branches; unsampled implementation details are not inferred, so some links are omitted.

Main entry points: [`open-sse/handlers/chatCore.js`](https://github.com/artinf0/9router/blob/master/open-sse/handlers/chatCore.js) (Chat Core), [`src/app/(dashboard)/dashboard`](https://github.com/artinf0/9router/tree/master/src/app/(dashboard)/dashboard) (Dashboard), [`src/app/api/v1`](https://github.com/artinf0/9router/tree/master/src/app/api/v1) (OpenAI API), [`open-sse/executors/index.js`](https://github.com/artinf0/9router/blob/master/open-sse/executors/index.js) (Executor Registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Request Gateway"]
  node_gateway_api["OpenAI API"]
  node_chat_core["Chat Core<br/>[chatCore.js]"]
  node_translator["Format Translator<br/>[index.js]"]
  node_rtk["RTK Compression<br/>[index.js]"]
end

subgraph group_providers["Provider Routing"]
  node_executor_registry["Executor Registry<br/>[index.js]"]
  node_provider_services["Provider Services<br/>[provider.js]"]
  node_provider_catalog["Provider Catalog"]
end

subgraph group_management["Dashboard Management"]
  node_dashboard["Dashboard"]
  node_provider_api["Provider Management API"]
  node_database[("Application Database<br/>[localDb.js]")]
  node_model_api["Model Discovery API<br/>[route.js]"]
  node_cli_tools["CLI Tool Setup"]
end

subgraph group_capabilities["Product Capabilities"]
  node_usage["Usage Tracking"]
  node_media_api["Media APIs<br/>[route.js]"]
  node_embeddings["Embeddings<br/>[embeddings.js]"]
  node_token_refresh["Token Refresh<br/>[tokenRefresh.js]"]
end

subgraph group_operations["Access and Operations"]
  node_tunnel["Public Tunnel<br/>[manager.js]"]
  node_mitm["MITM Integration<br/>[manager.js]"]
  node_docs["Documentation Site<br/>[page.js]"]
end

node_cli(("AI Coding Tools"))
node_external_providers(("AI Providers"))

node_cli -->|"sends requests"| node_gateway_api
node_gateway_api -.->|"routes chat"| node_chat_core
node_chat_core -->|"translates formats"| node_translator
node_chat_core -->|"dispatches requests"| node_executor_registry
node_executor_registry -.->|"calls providers"| node_external_providers
node_provider_catalog -.->|"defines providers"| node_executor_registry
node_translator -->|"normalizes thinking"| node_provider_services
node_cli -->|"sends tool output"| node_rtk
node_dashboard -.->|"manages connections"| node_provider_api
node_provider_api -->|"reads and writes"| node_database
node_model_api -->|"loads connections"| node_database
node_model_api -.->|"resolves models"| node_provider_services
node_chat_core -->|"records usage"| node_usage
node_gateway_api -.->|"offers audio endpoints"| node_media_api
node_gateway_api -.->|"offers embeddings"| node_embeddings
node_chat_core -->|"refreshes credentials"| node_token_refresh
node_dashboard -.->|"configures tools"| node_cli_tools
node_dashboard -.->|"controls tunnel"| node_tunnel
node_dashboard -.->|"manages integration"| node_mitm

click node_gateway_api "https://github.com/artinf0/9router/tree/master/src/app/api/v1"
click node_chat_core "https://github.com/artinf0/9router/blob/master/open-sse/handlers/chatCore.js"
click node_translator "https://github.com/artinf0/9router/blob/master/open-sse/translator/index.js"
click node_rtk "https://github.com/artinf0/9router/blob/master/open-sse/rtk/index.js"
click node_executor_registry "https://github.com/artinf0/9router/blob/master/open-sse/executors/index.js"
click node_provider_services "https://github.com/artinf0/9router/blob/master/open-sse/services/provider.js"
click node_provider_catalog "https://github.com/artinf0/9router/tree/master/open-sse/providers/registry"
click node_dashboard "https://github.com/artinf0/9router/tree/master/src/app/(dashboard)/dashboard"
click node_provider_api "https://github.com/artinf0/9router/tree/master/src/app/api/providers"
click node_database "https://github.com/artinf0/9router/blob/master/src/lib/localDb.js"
click node_model_api "https://github.com/artinf0/9router/blob/master/src/app/api/v1/models/route.js"
click node_usage "https://github.com/artinf0/9router/tree/master/src/app/api/usage"
click node_media_api "https://github.com/artinf0/9router/blob/master/src/app/api/v1/audio/speech/route.js"
click node_embeddings "https://github.com/artinf0/9router/blob/master/src/sse/handlers/embeddings.js"
click node_token_refresh "https://github.com/artinf0/9router/blob/master/open-sse/services/tokenRefresh.js"
click node_cli_tools "https://github.com/artinf0/9router/tree/master/src/app/api/cli-tools"
click node_tunnel "https://github.com/artinf0/9router/blob/master/src/lib/tunnel/cloudflare/manager.js"
click node_mitm "https://github.com/artinf0/9router/blob/master/src/mitm/manager.js"
click node_docs "https://github.com/artinf0/9router/blob/master/gitbook/app/%5Blang%5D/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_core,node_translator,node_rtk toneBlue
class node_executor_registry,node_provider_services,node_provider_catalog toneAmber
class node_dashboard,node_provider_api,node_database,node_model_api,node_cli_tools toneMint
class node_usage,node_media_api,node_embeddings,node_token_refresh toneRose
class node_tunnel,node_mitm,node_docs,node_cli,node_external_providers toneIndigo
```

## Components

### Request Gateway

- [OpenAI API](https://github.com/artinf0/9router/tree/master/src/app/api/v1): `src/app/api/v1`
- [Chat Core](https://github.com/artinf0/9router/blob/master/open-sse/handlers/chatCore.js): `open-sse/handlers/chatCore.js`
- [Format Translator](https://github.com/artinf0/9router/blob/master/open-sse/translator/index.js): `open-sse/translator/index.js`
- [RTK Compression](https://github.com/artinf0/9router/blob/master/open-sse/rtk/index.js): `open-sse/rtk/index.js`

### Provider Routing

- [Executor Registry](https://github.com/artinf0/9router/blob/master/open-sse/executors/index.js): `open-sse/executors/index.js`
- [Provider Services](https://github.com/artinf0/9router/blob/master/open-sse/services/provider.js): `open-sse/services/provider.js`
- [Provider Catalog](https://github.com/artinf0/9router/tree/master/open-sse/providers/registry): `open-sse/providers/registry`

### Dashboard Management

- [Dashboard](https://github.com/artinf0/9router/tree/master/src/app/(dashboard)/dashboard): `src/app/(dashboard)/dashboard`
- [Provider Management API](https://github.com/artinf0/9router/tree/master/src/app/api/providers): `src/app/api/providers`
- [Application Database](https://github.com/artinf0/9router/blob/master/src/lib/localDb.js): `src/lib/localDb.js`
- [Model Discovery API](https://github.com/artinf0/9router/blob/master/src/app/api/v1/models/route.js): `src/app/api/v1/models/route.js`
- [CLI Tool Setup](https://github.com/artinf0/9router/tree/master/src/app/api/cli-tools): `src/app/api/cli-tools`

### Product Capabilities

- [Usage Tracking](https://github.com/artinf0/9router/tree/master/src/app/api/usage): `src/app/api/usage`
- [Media APIs](https://github.com/artinf0/9router/blob/master/src/app/api/v1/audio/speech/route.js): `src/app/api/v1/audio/speech/route.js`
- [Embeddings](https://github.com/artinf0/9router/blob/master/src/sse/handlers/embeddings.js): `src/sse/handlers/embeddings.js`
- [Token Refresh](https://github.com/artinf0/9router/blob/master/open-sse/services/tokenRefresh.js): `open-sse/services/tokenRefresh.js`

### Access and Operations

- [Public Tunnel](https://github.com/artinf0/9router/blob/master/src/lib/tunnel/cloudflare/manager.js): `src/lib/tunnel/cloudflare/manager.js`
- [MITM Integration](https://github.com/artinf0/9router/blob/master/src/mitm/manager.js): `src/mitm/manager.js`
- [Documentation Site](https://github.com/artinf0/9router/blob/master/gitbook/app/%5Blang%5D/page.js): `gitbook/app/[lang]/page.js`

### Other components

- **AI Coding Tools**
- **AI Providers**

## Connections

- AI Coding Tools → OpenAI API: sends requests
- OpenAI API → Chat Core: routes chat
- Chat Core → Format Translator: translates formats (evidence: `open-sse/handlers/chatCore.js`)
- Chat Core → Executor Registry: dispatches requests (evidence: `open-sse/handlers/chatCore.js`)
- Executor Registry → AI Providers: calls providers
- Provider Catalog → Executor Registry: defines providers
- Format Translator → Provider Services: normalizes thinking (evidence: `open-sse/translator/index.js`)
- AI Coding Tools → RTK Compression: sends tool output
- Dashboard → Provider Management API: manages connections
- Provider Management API → Application Database: reads and writes (evidence: `src/app/api/providers/route.js`)
- Model Discovery API → Application Database: loads connections (evidence: `src/app/api/v1/models/route.js`)
- Model Discovery API → Provider Services: resolves models
- Chat Core → Usage Tracking: records usage (evidence: `open-sse/handlers/chatCore.js`)
- OpenAI API → Media APIs: offers audio endpoints
- OpenAI API → Embeddings: offers embeddings
- Chat Core → Token Refresh: refreshes credentials (evidence: `open-sse/handlers/chatCore.js`)
- Dashboard → CLI Tool Setup: configures tools
- Dashboard → Public Tunnel: controls tunnel
- Dashboard → MITM Integration: manages integration
