# azhar457/9router architecture

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

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

## Overview

9Router Plinian is an AI gateway for coding tools: clients send requests to one local endpoint, which the Go entry proxy forwards to the Next.js/Open-SSE core for provider selection, translation, execution, and responses. The README also documents combos and fallback, quota and usage tracking, media services, dashboard configuration, and fork-specific Red Team and token-saving features. Some subsystem links are documented rather than visible in sampled source; unsampled implementation details are not inferred.

Main entry points: [`open-sse/handlers/chatCore.js`](https://github.com/azhar457/9router/blob/master/open-sse/handlers/chatCore.js) (Chat request handling), [`open-sse/index.js`](https://github.com/azhar457/9router/blob/master/open-sse/index.js) (Open-SSE gateway), [`open-sse/executors/index.js`](https://github.com/azhar457/9router/blob/master/open-sse/executors/index.js) (Provider executors), [`src/app/(dashboard)/dashboard/page.js`](https://github.com/azhar457/9router/blob/master/src/app/(dashboard)/dashboard/page.js) (Dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Gateway entry"]
  node_go["Go entry proxy<br/>[main.go]"]
  node_core["Open-SSE gateway<br/>[index.js]"]
  node_chat["Chat request handling<br/>[chatCore.js]"]
end

subgraph group_routing["Provider routing"]
  node_catalog["Provider catalog<br/>[index.js]"]
  node_provider["Provider service<br/>[provider.js]"]
  node_executors["Provider executors<br/>[index.js]"]
  node_models["Models endpoint<br/>[route.js]"]
  node_combos["Combos and fallback<br/>[combo.js]"]
end

subgraph group_capabilities["Request capabilities"]
  node_translator["Format translation<br/>[index.js]"]
  node_rtk["RTK token saver<br/>[index.js]"]
  node_injection["Red Team injection<br/>[globalInject.js]"]
  node_media["Media services"]
end

subgraph group_state["Configuration and state"]
  node_db[("Local database<br/>[localDb.js]")]
  node_oauth["OAuth and credentials<br/>[server.js]"]
  node_usage["Quota and usage<br/>[usage.js]"]
end

subgraph group_interface["User interface"]
  node_dashboard["Dashboard<br/>[page.js]"]
  node_providerui["Provider management<br/>[page.js]"]
  node_console["Transparency console"]
end

node_client(("Coding tools"))
node_upstream(("AI providers"))
node_external(("Provider APIs"))

node_client -->|"sends requests"| node_go
node_go -->|"forwards requests"| node_core
node_core -->|"routes chat"| node_chat
node_chat -->|"selects provider"| node_provider
node_chat -->|"translates formats"| node_translator
node_chat -->|"dispatches requests"| node_executors
node_provider -->|"reads definitions"| node_catalog
node_executors -->|"calls provider"| node_upstream
node_chat -->|"compresses context"| node_rtk
node_chat -->|"adds prompt payload"| node_injection
node_client -->|"lists models"| node_models
node_models -->|"reads connections"| node_db
node_core -->|"uses combos"| node_combos
node_core -->|"tracks quota and usage"| node_usage
node_core -->|"serves media requests"| node_media
node_dashboard -->|"manages providers"| node_providerui
node_providerui -->|"configures connections"| node_db
node_dashboard -->|"connects accounts"| node_oauth
node_console -->|"shows injection order"| node_injection
node_executors -->|"sends upstream requests"| node_external

click node_go "https://github.com/azhar457/9router/blob/master/go/main.go"
click node_core "https://github.com/azhar457/9router/blob/master/open-sse/index.js"
click node_chat "https://github.com/azhar457/9router/blob/master/open-sse/handlers/chatCore.js"
click node_catalog "https://github.com/azhar457/9router/blob/master/open-sse/providers/registry/index.js"
click node_provider "https://github.com/azhar457/9router/blob/master/open-sse/services/provider.js"
click node_executors "https://github.com/azhar457/9router/blob/master/open-sse/executors/index.js"
click node_translator "https://github.com/azhar457/9router/blob/master/open-sse/translator/index.js"
click node_rtk "https://github.com/azhar457/9router/blob/master/open-sse/rtk/index.js"
click node_injection "https://github.com/azhar457/9router/blob/master/open-sse/rtk/globalInject.js"
click node_media "https://github.com/azhar457/9router/blob/master/open-sse/handlers/imageGenerationCore.js"
click node_models "https://github.com/azhar457/9router/blob/master/src/app/api/v1/models/route.js"
click node_combos "https://github.com/azhar457/9router/blob/master/open-sse/services/combo.js"
click node_db "https://github.com/azhar457/9router/blob/master/src/lib/localDb.js"
click node_oauth "https://github.com/azhar457/9router/blob/master/src/lib/oauth/utils/server.js"
click node_usage "https://github.com/azhar457/9router/blob/master/open-sse/services/usage.js"
click node_dashboard "https://github.com/azhar457/9router/blob/master/src/app/(dashboard)/dashboard/page.js"
click node_providerui "https://github.com/azhar457/9router/blob/master/src/app/(dashboard)/dashboard/providers/page.js"
click node_console "https://github.com/azhar457/9router/blob/master/src/app/(dashboard)/dashboard/developer/TransparencyClient.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_go,node_core,node_chat toneBlue
class node_catalog,node_provider,node_executors,node_models,node_combos toneAmber
class node_translator,node_rtk,node_injection,node_media,node_external toneMint
class node_db,node_oauth,node_usage toneRose
class node_dashboard,node_providerui,node_console,node_client,node_upstream toneIndigo
```

## Components

### Gateway entry

- [Go entry proxy](https://github.com/azhar457/9router/blob/master/go/main.go): `go/main.go`
- [Open-SSE gateway](https://github.com/azhar457/9router/blob/master/open-sse/index.js): `open-sse/index.js`
- [Chat request handling](https://github.com/azhar457/9router/blob/master/open-sse/handlers/chatCore.js): `open-sse/handlers/chatCore.js`

### Provider routing

- [Provider catalog](https://github.com/azhar457/9router/blob/master/open-sse/providers/registry/index.js): `open-sse/providers/registry/index.js`
- [Provider service](https://github.com/azhar457/9router/blob/master/open-sse/services/provider.js): `open-sse/services/provider.js`
- [Provider executors](https://github.com/azhar457/9router/blob/master/open-sse/executors/index.js): `open-sse/executors/index.js`
- [Models endpoint](https://github.com/azhar457/9router/blob/master/src/app/api/v1/models/route.js): `src/app/api/v1/models/route.js`
- [Combos and fallback](https://github.com/azhar457/9router/blob/master/open-sse/services/combo.js): `open-sse/services/combo.js`

### Request capabilities

- [Format translation](https://github.com/azhar457/9router/blob/master/open-sse/translator/index.js): `open-sse/translator/index.js`
- [RTK token saver](https://github.com/azhar457/9router/blob/master/open-sse/rtk/index.js): `open-sse/rtk/index.js`
- [Red Team injection](https://github.com/azhar457/9router/blob/master/open-sse/rtk/globalInject.js): `open-sse/rtk/globalInject.js`
- [Media services](https://github.com/azhar457/9router/blob/master/open-sse/handlers/imageGenerationCore.js): `open-sse/handlers/imageGenerationCore.js`

### Configuration and state

- [Local database](https://github.com/azhar457/9router/blob/master/src/lib/localDb.js): `src/lib/localDb.js`
- [OAuth and credentials](https://github.com/azhar457/9router/blob/master/src/lib/oauth/utils/server.js): `src/lib/oauth/utils/server.js`
- [Quota and usage](https://github.com/azhar457/9router/blob/master/open-sse/services/usage.js): `open-sse/services/usage.js`

### User interface

- [Dashboard](https://github.com/azhar457/9router/blob/master/src/app/(dashboard)/dashboard/page.js): `src/app/(dashboard)/dashboard/page.js`
- [Provider management](https://github.com/azhar457/9router/blob/master/src/app/(dashboard)/dashboard/providers/page.js): `src/app/(dashboard)/dashboard/providers/page.js`
- [Transparency console](https://github.com/azhar457/9router/blob/master/src/app/(dashboard)/dashboard/developer/TransparencyClient.js): `src/app/(dashboard)/dashboard/developer/TransparencyClient.js`

### Other components

- **Coding tools**
- **AI providers**
- **Provider APIs**

## Connections

- Coding tools → Go entry proxy: sends requests
- Go entry proxy → Open-SSE gateway: forwards requests
- Open-SSE gateway → Chat request handling: routes chat (evidence: `open-sse/index.js`)
- Chat request handling → Provider service: selects provider (evidence: `open-sse/handlers/chatCore.js`)
- Chat request handling → Format translation: translates formats (evidence: `open-sse/handlers/chatCore.js`)
- Chat request handling → Provider executors: dispatches requests (evidence: `open-sse/handlers/chatCore.js`)
- Provider service → Provider catalog: reads definitions (evidence: `open-sse/services/provider.js`)
- Provider executors → AI providers: calls provider
- Chat request handling → RTK token saver: compresses context (evidence: `open-sse/handlers/chatCore.js`)
- Chat request handling → Red Team injection: adds prompt payload (evidence: `open-sse/handlers/chatCore.js`)
- Coding tools → Models endpoint: lists models
- Models endpoint → Local database: reads connections (evidence: `src/app/api/v1/models/route.js`)
- Open-SSE gateway → Combos and fallback: uses combos
- Open-SSE gateway → Quota and usage: tracks quota and usage
- Open-SSE gateway → Media services: serves media requests
- Dashboard → Provider management: manages providers
- Provider management → Local database: configures connections
- Dashboard → OAuth and credentials: connects accounts
- Transparency console → Red Team injection: shows injection order
- Provider executors → Provider APIs: sends upstream requests
