# steve3184/new-api architecture

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

- Interactive diagram: https://gitdiagram.com/steve3184/new-api
- Repository: https://github.com/steve3184/new-api

## Overview

New API is an LLM gateway and AI asset-management platform: clients send model or media requests through its API, which applies routing and access controls before relay handling and upstream-provider communication. The product also documents usage accounting, billing, dashboards, and permission management; task plugins and scheduled system work are distinct supporting capabilities. The graph combines documented capabilities with relationships visible in the sampled startup, router, and relay references. Several feature implementations were not sampled, so their internal call paths are intentionally omitted.

Main entry points: [`main.go`](https://github.com/steve3184/new-api/blob/main/main.go) (Application startup), [`router/api-router.go`](https://github.com/steve3184/new-api/blob/main/router/api-router.go) (HTTP API routes), [`relay/embedding_handler.go`](https://github.com/steve3184/new-api/blob/main/relay/embedding_handler.go) (Embedding handler), [`controller`](https://github.com/steve3184/new-api/tree/main/controller) (API controllers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry and access"]
  node_api["HTTP API routes<br/>[api-router.go]"]
  node_access["Access controls"]
  node_controllers["API controllers"]
end

subgraph group_gateway["Inference gateway"]
  node_relay["Inference relay"]
  node_embedding["Embedding handler"]
  node_providers["Model providers"]
  node_file_service["File handling<br/>[file_service.go]"]
  node_plugin_engine["Plugin runtime<br/>[engine.go]"]
  node_task_plugins["Task plugins"]
end

subgraph group_operations["Accounts and operations"]
  node_billing["Usage and billing"]
  node_accounts["Accounts and permissions"]
  node_payments["Payments"]
  node_analytics["Dashboard and metrics<br/>[usedata.go]"]
  node_system_tasks["Scheduled tasks"]
end

subgraph group_runtime["Runtime foundation"]
  node_application["Application startup<br/>[main.go]"]
  node_models[("Persistent models<br/>[main.go]")]
  node_web_ui["Web console<br/>[main.tsx]"]
end

node_client(("API clients"))

node_client -->|"sends requests"| node_api
node_api -->|"routes to"| node_controllers
node_api -->|"uses middleware"| node_access
node_application -.->|"starts routes"| node_api
node_application -->|"initializes database"| node_models
node_application -->|"registers tasks"| node_system_tasks
node_application -->|"loads runtime"| node_plugin_engine
node_application -->|"loads relay"| node_relay
node_embedding -.->|"dispatches upstream"| node_providers
node_embedding -->|"records usage"| node_billing
node_controllers -.->|"invokes inference"| node_relay
node_task_plugins -.->|"uses runtime"| node_plugin_engine
node_client -->|"uses console"| node_web_ui
node_payments -.->|"funds accounts"| node_billing

click node_api "https://github.com/steve3184/new-api/blob/main/router/api-router.go"
click node_access "https://github.com/steve3184/new-api/blob/main/middleware/access_token_routes.go"
click node_controllers "https://github.com/steve3184/new-api/tree/main/controller"
click node_relay "https://github.com/steve3184/new-api/tree/main/relay"
click node_embedding "https://github.com/steve3184/new-api/blob/main/relay/embedding_handler.go"
click node_providers "https://github.com/steve3184/new-api/tree/main/relay/channel"
click node_file_service "https://github.com/steve3184/new-api/blob/main/service/file_service.go"
click node_plugin_engine "https://github.com/steve3184/new-api/blob/main/pkg/jsplugin/engine.go"
click node_task_plugins "https://github.com/steve3184/new-api/tree/main/plugins/tasks"
click node_billing "https://github.com/steve3184/new-api/tree/main/service"
click node_accounts "https://github.com/steve3184/new-api/tree/main/model"
click node_payments "https://github.com/steve3184/new-api/tree/main/controller"
click node_analytics "https://github.com/steve3184/new-api/blob/main/model/usedata.go"
click node_system_tasks "https://github.com/steve3184/new-api/blob/main/controller/system_task_handlers.go"
click node_application "https://github.com/steve3184/new-api/blob/main/main.go"
click node_models "https://github.com/steve3184/new-api/blob/main/model/main.go"
click node_web_ui "https://github.com/steve3184/new-api/blob/main/web/src/main.tsx"

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_api,node_access,node_controllers,node_client toneBlue
class node_relay,node_embedding,node_providers,node_file_service,node_plugin_engine,node_task_plugins toneAmber
class node_billing,node_accounts,node_payments,node_analytics,node_system_tasks toneMint
class node_application,node_models,node_web_ui toneRose
```

## Components

### API entry and access

- [HTTP API routes](https://github.com/steve3184/new-api/blob/main/router/api-router.go): `router/api-router.go`
- [Access controls](https://github.com/steve3184/new-api/blob/main/middleware/access_token_routes.go): `middleware/access_token_routes.go`
- [API controllers](https://github.com/steve3184/new-api/tree/main/controller): `controller`

### Inference gateway

- [Inference relay](https://github.com/steve3184/new-api/tree/main/relay): `relay`
- [Embedding handler](https://github.com/steve3184/new-api/blob/main/relay/embedding_handler.go): `relay/embedding_handler.go`
- [Model providers](https://github.com/steve3184/new-api/tree/main/relay/channel): `relay/channel`
- [File handling](https://github.com/steve3184/new-api/blob/main/service/file_service.go): `service/file_service.go`
- [Plugin runtime](https://github.com/steve3184/new-api/blob/main/pkg/jsplugin/engine.go): `pkg/jsplugin/engine.go`
- [Task plugins](https://github.com/steve3184/new-api/tree/main/plugins/tasks): `plugins/tasks`

### Accounts and operations

- [Usage and billing](https://github.com/steve3184/new-api/tree/main/service): `service`
- [Accounts and permissions](https://github.com/steve3184/new-api/tree/main/model): `model`
- [Payments](https://github.com/steve3184/new-api/tree/main/controller): `controller`
- [Dashboard and metrics](https://github.com/steve3184/new-api/blob/main/model/usedata.go): `model/usedata.go`
- [Scheduled tasks](https://github.com/steve3184/new-api/blob/main/controller/system_task_handlers.go): `controller/system_task_handlers.go`

### Runtime foundation

- [Application startup](https://github.com/steve3184/new-api/blob/main/main.go): `main.go`
- [Persistent models](https://github.com/steve3184/new-api/blob/main/model/main.go): `model/main.go`
- [Web console](https://github.com/steve3184/new-api/blob/main/web/src/main.tsx): `web/src/main.tsx`

### Other components

- **API clients**

## Connections

- API clients → HTTP API routes: sends requests
- HTTP API routes → API controllers: routes to (evidence: `router/api-router.go`)
- HTTP API routes → Access controls: uses middleware (evidence: `router/api-router.go`)
- Application startup → HTTP API routes: starts routes
- Application startup → Persistent models: initializes database (evidence: `main.go`)
- Application startup → Scheduled tasks: registers tasks (evidence: `main.go`)
- Application startup → Plugin runtime: loads runtime (evidence: `main.go`)
- Application startup → Inference relay: loads relay (evidence: `main.go`)
- Embedding handler → Model providers: dispatches upstream
- Embedding handler → Usage and billing: records usage (evidence: `relay/embedding_handler.go`)
- API controllers → Inference relay: invokes inference
- Task plugins → Plugin runtime: uses runtime
- API clients → Web console: uses console
- Payments → Usage and billing: funds accounts (evidence: `controller/system_task_handlers.go`)
