# wei-shaw/sub2api architecture

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

- Interactive diagram: https://gitdiagram.com/wei-shaw/sub2api
- Repository: https://github.com/wei-shaw/sub2api
- Video tour (about a minute): https://gitdiagram.com/wei-shaw/sub2api/video

## Overview

Sub2API is an AI API gateway platform for distributing subscription quota. The principal workflow is a client sending a compatible model request, the gateway routing it to an upstream AI account, and the platform recording usage against quota. Separate product areas handle account authentication, administration, payments, monitoring, and image workloads. The graph also shows the frontend and persistence layers. Backend wiring and most handlers were not sampled, so inferred runtime links are dashed and have no evidence path.

Main entry points: [`frontend/src/api/client.ts`](https://github.com/wei-shaw/sub2api/blob/main/frontend/src/api/client.ts) (HTTP API client), [`backend/ent/client.go`](https://github.com/wei-shaw/sub2api/blob/main/backend/ent/client.go) (Application data), [`backend/internal/service/openai_gateway_cc_pipeline.go`](https://github.com/wei-shaw/sub2api/blob/main/backend/internal/service/openai_gateway_cc_pipeline.go) (Gateway processing), [`frontend/src/App.vue`](https://github.com/wei-shaw/sub2api/blob/main/frontend/src/App.vue) (Web application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client application"]
  node_frontend["Web application<br/>[App.vue]"]
  node_frontend_api["HTTP API client<br/>[client.ts]"]
end

subgraph group_gateway["AI gateway"]
  node_server["Backend server<br/>[main.go]"]
  node_gateway_handler["Gateway endpoints<br/>[gateway_handler.go]"]
  node_openai_handler["OpenAI-compatible API"]
  node_gateway_service["Gateway processing"]
end

subgraph group_accounts["Accounts and access"]
  node_auth["Authentication<br/>[auth_handler.go]"]
  node_admin["Admin management<br/>[account_handler.go]"]
  node_subscription["Subscriptions"]
  node_payments["Payment processing<br/>[payment_handler.go]"]
end

subgraph group_operations["Platform operations"]
  node_channel_monitor["Channel monitoring"]
  node_batch_images["Batch image jobs"]
  node_image_storage["Image storage<br/>[image_storage.go]"]
  node_management_mcp["Management MCP<br/>[server.go]"]
end

subgraph group_persistence["Persistence"]
  node_database[("Application data<br/>[client.go]")]
end

node_user(("API client"))
node_upstream{{"AI providers"}}
node_payment_providers{{"Payment providers"}}
node_s3[("S3-compatible storage")]

node_user -.->|"uses console"| node_frontend
node_frontend -.->|"requests data"| node_frontend_api
node_frontend_api -.->|"calls API"| node_server
node_server -.->|"serves gateway"| node_gateway_handler
node_gateway_handler -.->|"dispatches requests"| node_openai_handler
node_openai_handler -.->|"processes requests"| node_gateway_service
node_gateway_service -.->|"routes model calls"| node_upstream
node_gateway_service -.->|"records usage"| node_database
node_frontend_api -.->|"calls auth API"| node_auth
node_frontend_api -.->|"calls admin API"| node_admin
node_frontend_api -.->|"calls subscription API"| node_subscription
node_frontend_api -.->|"calls payment API"| node_payments
node_payments -.->|"initiates payments"| node_payment_providers
node_frontend_api -.->|"calls monitoring API"| node_channel_monitor
node_frontend_api -.->|"calls image API"| node_batch_images
node_batch_images -.->|"stores images"| node_image_storage
node_image_storage -.->|"uploads objects"| node_s3
node_management_mcp -.->|"manages platform data"| node_database
node_auth -.->|"persists identity"| node_database
node_admin -.->|"manages records"| node_database

click node_frontend "https://github.com/wei-shaw/sub2api/blob/main/frontend/src/App.vue"
click node_frontend_api "https://github.com/wei-shaw/sub2api/blob/main/frontend/src/api/client.ts"
click node_server "https://github.com/wei-shaw/sub2api/blob/main/backend/cmd/server/main.go"
click node_gateway_handler "https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/gateway_handler.go"
click node_openai_handler "https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/openai_gateway_handler.go"
click node_gateway_service "https://github.com/wei-shaw/sub2api/blob/main/backend/internal/service/openai_gateway_cc_pipeline.go"
click node_auth "https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/auth_handler.go"
click node_admin "https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/admin/account_handler.go"
click node_subscription "https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/subscription_handler.go"
click node_payments "https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/payment_handler.go"
click node_channel_monitor "https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/channel_monitor_v2_handler.go"
click node_batch_images "https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/batch_image_handler.go"
click node_image_storage "https://github.com/wei-shaw/sub2api/blob/main/backend/internal/service/image_storage.go"
click node_management_mcp "https://github.com/wei-shaw/sub2api/blob/main/backend/internal/managementmcp/server.go"
click node_database "https://github.com/wei-shaw/sub2api/blob/main/backend/ent/client.go"

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_frontend,node_frontend_api,node_user toneBlue
class node_server,node_gateway_handler,node_openai_handler,node_gateway_service,node_s3 toneAmber
class node_auth,node_admin,node_subscription,node_payments toneMint
class node_channel_monitor,node_batch_images,node_image_storage,node_management_mcp toneRose
class node_database,node_upstream,node_payment_providers toneIndigo
```

## Components

### Client application

- [Web application](https://github.com/wei-shaw/sub2api/blob/main/frontend/src/App.vue): `frontend/src/App.vue`
- [HTTP API client](https://github.com/wei-shaw/sub2api/blob/main/frontend/src/api/client.ts): `frontend/src/api/client.ts`

### AI gateway

- [Backend server](https://github.com/wei-shaw/sub2api/blob/main/backend/cmd/server/main.go): `backend/cmd/server/main.go`
- [Gateway endpoints](https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/gateway_handler.go): `backend/internal/handler/gateway_handler.go`
- [OpenAI-compatible API](https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/openai_gateway_handler.go): `backend/internal/handler/openai_gateway_handler.go`
- [Gateway processing](https://github.com/wei-shaw/sub2api/blob/main/backend/internal/service/openai_gateway_cc_pipeline.go): `backend/internal/service/openai_gateway_cc_pipeline.go`

### Accounts and access

- [Authentication](https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/auth_handler.go): `backend/internal/handler/auth_handler.go`
- [Admin management](https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/admin/account_handler.go): `backend/internal/handler/admin/account_handler.go`
- [Subscriptions](https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/subscription_handler.go): `backend/internal/handler/subscription_handler.go`
- [Payment processing](https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/payment_handler.go): `backend/internal/handler/payment_handler.go`

### Platform operations

- [Channel monitoring](https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/channel_monitor_v2_handler.go): `backend/internal/handler/channel_monitor_v2_handler.go`
- [Batch image jobs](https://github.com/wei-shaw/sub2api/blob/main/backend/internal/handler/batch_image_handler.go): `backend/internal/handler/batch_image_handler.go`
- [Image storage](https://github.com/wei-shaw/sub2api/blob/main/backend/internal/service/image_storage.go): `backend/internal/service/image_storage.go`
- [Management MCP](https://github.com/wei-shaw/sub2api/blob/main/backend/internal/managementmcp/server.go): `backend/internal/managementmcp/server.go`

### Persistence

- [Application data](https://github.com/wei-shaw/sub2api/blob/main/backend/ent/client.go): `backend/ent/client.go`

### Other components

- **API client**
- **AI providers**
- **Payment providers**
- **S3-compatible storage**

## Connections

- API client → Web application: uses console
- Web application → HTTP API client: requests data
- HTTP API client → Backend server: calls API
- Backend server → Gateway endpoints: serves gateway
- Gateway endpoints → OpenAI-compatible API: dispatches requests
- OpenAI-compatible API → Gateway processing: processes requests
- Gateway processing → AI providers: routes model calls
- Gateway processing → Application data: records usage
- HTTP API client → Authentication: calls auth API
- HTTP API client → Admin management: calls admin API
- HTTP API client → Subscriptions: calls subscription API
- HTTP API client → Payment processing: calls payment API
- Payment processing → Payment providers: initiates payments
- HTTP API client → Channel monitoring: calls monitoring API
- HTTP API client → Batch image jobs: calls image API
- Batch image jobs → Image storage: stores images
- Image storage → S3-compatible storage: uploads objects
- Management MCP → Application data: manages platform data
- Authentication → Application data: persists identity
- Admin management → Application data: manages records
