# echoping07/buddy-2api-go architecture

> Architecture diagram of the GitHub repository echoping07/buddy-2api-go, 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/echoping07/buddy-2api-go
- Repository: https://github.com/echoping07/buddy-2api-go

## Overview

Buddy 2API Go is a single-account CodeBuddy/WorkBuddy-to-OpenAI-compatible gateway with a built-in web admin. The main workflow is an OpenAI client authenticating with an API key, sending chat or model requests through the proxy to the configured upstream, and receiving compatible results; request metadata is logged for admin views. Administrators manage OAuth credentials, keys, resources, settings, and scheduled check-in/growth tasks through the web panel. The graph combines sampled call sites with README-documented capabilities; some subsystem links are therefore documented rather than verified from implementation excerpts.

Main entry points: [`main.go`](https://github.com/echoping07/buddy-2api-go/blob/main/main.go) (HTTP Application), [`internal/admin/admin.go`](https://github.com/echoping07/buddy-2api-go/blob/main/internal/admin/admin.go) (Admin API), [`internal/upstream/client.go`](https://github.com/echoping07/buddy-2api-go/blob/main/internal/upstream/client.go) (Upstream Client), [`internal/proxy/proxy.go`](https://github.com/echoping07/buddy-2api-go/blob/main/internal/proxy/proxy.go) (OpenAI Endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["OpenAI Gateway"]
  node_main["HTTP Application<br/>[main.go]"]
  node_proxy["OpenAI Endpoints<br/>[proxy.go]"]
  node_keys["API Key Auth<br/>[apikey.go]"]
end

subgraph group_admin["Admin Panel"]
  node_adminui["Web Admin UI<br/>[web.go]"]
  node_adminapi["Admin API<br/>[admin.go]"]
  node_admin_growth["Growth Controls<br/>[growth.go]"]
  node_session["Admin Sessions<br/>[session.go]"]
end

subgraph group_account["Account and Upstream"]
  node_auth["OAuth Credentials<br/>[token.go]"]
  node_upstream["Upstream Client<br/>[client.go]"]
  node_models["Model Catalog<br/>[models.go]"]
  node_fingerprint["Client Fingerprint<br/>[fingerprint.go]"]
  node_growthapi["Growth Operations<br/>[growth.go]"]
end

subgraph group_tasks["Scheduled Tasks"]
  node_scheduler["Task Scheduler<br/>[scheduler.go]"]
  node_growthchain["Growth Chain<br/>[growth.go]"]
end

subgraph group_persistence["Configuration and State"]
  node_config["Runtime Settings<br/>[config.go]"]
  node_store[("SQLite State<br/>[store.go]")]
end

node_client(("OpenAI Client"))
node_external["CodeBuddy Service"]

node_client -->|"sends requests"| node_main
node_main -->|"routes API"| node_proxy
node_main -->|"mounts routes"| node_adminapi
node_main -->|"mounts pages"| node_adminui
node_main -->|"initializes"| node_config
node_main -->|"initializes"| node_store
node_main -->|"initializes"| node_upstream
node_main -->|"initializes"| node_keys
node_main -->|"initializes"| node_scheduler
node_proxy -->|"uses authenticated key"| node_keys
node_proxy -->|"forwards chat"| node_upstream
node_proxy -->|"serves models"| node_models
node_proxy -->|"writes request logs"| node_store
node_keys -->|"reads and updates keys"| node_store
node_adminapi -->|"authenticates sessions"| node_session
node_adminapi -->|"manages credentials"| node_auth
node_adminapi -->|"fetches account data"| node_upstream
node_adminapi -->|"refreshes catalog"| node_models
node_adminapi -->|"manages keys"| node_keys
node_adminapi -->|"reads admin data"| node_store
node_admin_growth -->|"triggers tasks"| node_growthchain
node_adminapi -->|"routes growth controls"| node_admin_growth
node_scheduler -->|"runs scheduled chain"| node_growthchain
node_growthchain -->|"executes growth steps"| node_growthapi
node_growthchain -->|"persists daily state"| node_store
node_scheduler -->|"reads task settings"| node_config
node_upstream -->|"refreshes tokens"| node_auth
node_upstream -->|"calls upstream API"| node_external
node_growthapi -->|"reports activity"| node_external
node_models -->|"loads model config"| node_external
node_fingerprint -.->|"sets request headers"| node_upstream

click node_main "https://github.com/echoping07/buddy-2api-go/blob/main/main.go"
click node_proxy "https://github.com/echoping07/buddy-2api-go/blob/main/internal/proxy/proxy.go"
click node_keys "https://github.com/echoping07/buddy-2api-go/blob/main/internal/apikey/apikey.go"
click node_adminui "https://github.com/echoping07/buddy-2api-go/blob/main/internal/web/web.go"
click node_adminapi "https://github.com/echoping07/buddy-2api-go/blob/main/internal/admin/admin.go"
click node_admin_growth "https://github.com/echoping07/buddy-2api-go/blob/main/internal/admin/growth.go"
click node_session "https://github.com/echoping07/buddy-2api-go/blob/main/internal/admin/session.go"
click node_auth "https://github.com/echoping07/buddy-2api-go/blob/main/internal/auth/token.go"
click node_upstream "https://github.com/echoping07/buddy-2api-go/blob/main/internal/upstream/client.go"
click node_models "https://github.com/echoping07/buddy-2api-go/blob/main/internal/upstream/models.go"
click node_fingerprint "https://github.com/echoping07/buddy-2api-go/blob/main/internal/upstream/fingerprint.go"
click node_growthapi "https://github.com/echoping07/buddy-2api-go/blob/main/internal/upstream/growth.go"
click node_scheduler "https://github.com/echoping07/buddy-2api-go/blob/main/internal/scheduler/scheduler.go"
click node_growthchain "https://github.com/echoping07/buddy-2api-go/blob/main/internal/scheduler/growth.go"
click node_config "https://github.com/echoping07/buddy-2api-go/blob/main/internal/config/config.go"
click node_store "https://github.com/echoping07/buddy-2api-go/blob/main/internal/store/store.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_main,node_proxy,node_keys,node_client toneBlue
class node_adminui,node_adminapi,node_admin_growth,node_session toneAmber
class node_auth,node_upstream,node_models,node_fingerprint,node_growthapi toneMint
class node_scheduler,node_growthchain toneRose
class node_config,node_store,node_external toneIndigo
```

## Components

### OpenAI Gateway

- [HTTP Application](https://github.com/echoping07/buddy-2api-go/blob/main/main.go): `main.go`
- [OpenAI Endpoints](https://github.com/echoping07/buddy-2api-go/blob/main/internal/proxy/proxy.go): `internal/proxy/proxy.go`
- [API Key Auth](https://github.com/echoping07/buddy-2api-go/blob/main/internal/apikey/apikey.go): `internal/apikey/apikey.go`

### Admin Panel

- [Web Admin UI](https://github.com/echoping07/buddy-2api-go/blob/main/internal/web/web.go): `internal/web/web.go`
- [Admin API](https://github.com/echoping07/buddy-2api-go/blob/main/internal/admin/admin.go): `internal/admin/admin.go`
- [Growth Controls](https://github.com/echoping07/buddy-2api-go/blob/main/internal/admin/growth.go): `internal/admin/growth.go`
- [Admin Sessions](https://github.com/echoping07/buddy-2api-go/blob/main/internal/admin/session.go): `internal/admin/session.go`

### Account and Upstream

- [OAuth Credentials](https://github.com/echoping07/buddy-2api-go/blob/main/internal/auth/token.go): `internal/auth/token.go`
- [Upstream Client](https://github.com/echoping07/buddy-2api-go/blob/main/internal/upstream/client.go): `internal/upstream/client.go`
- [Model Catalog](https://github.com/echoping07/buddy-2api-go/blob/main/internal/upstream/models.go): `internal/upstream/models.go`
- [Client Fingerprint](https://github.com/echoping07/buddy-2api-go/blob/main/internal/upstream/fingerprint.go): `internal/upstream/fingerprint.go`
- [Growth Operations](https://github.com/echoping07/buddy-2api-go/blob/main/internal/upstream/growth.go): `internal/upstream/growth.go`

### Scheduled Tasks

- [Task Scheduler](https://github.com/echoping07/buddy-2api-go/blob/main/internal/scheduler/scheduler.go): `internal/scheduler/scheduler.go`
- [Growth Chain](https://github.com/echoping07/buddy-2api-go/blob/main/internal/scheduler/growth.go): `internal/scheduler/growth.go`

### Configuration and State

- [Runtime Settings](https://github.com/echoping07/buddy-2api-go/blob/main/internal/config/config.go): `internal/config/config.go`
- [SQLite State](https://github.com/echoping07/buddy-2api-go/blob/main/internal/store/store.go): `internal/store/store.go`

### Other components

- **OpenAI Client**
- **CodeBuddy Service**

## Connections

- OpenAI Client → HTTP Application: sends requests (evidence: `README.md`)
- HTTP Application → OpenAI Endpoints: routes API (evidence: `main.go`)
- HTTP Application → Admin API: mounts routes (evidence: `main.go`)
- HTTP Application → Web Admin UI: mounts pages (evidence: `main.go`)
- HTTP Application → Runtime Settings: initializes (evidence: `main.go`)
- HTTP Application → SQLite State: initializes (evidence: `main.go`)
- HTTP Application → Upstream Client: initializes (evidence: `main.go`)
- HTTP Application → API Key Auth: initializes (evidence: `main.go`)
- HTTP Application → Task Scheduler: initializes (evidence: `main.go`)
- OpenAI Endpoints → API Key Auth: uses authenticated key (evidence: `internal/proxy/proxy.go`)
- OpenAI Endpoints → Upstream Client: forwards chat (evidence: `README.md`)
- OpenAI Endpoints → Model Catalog: serves models (evidence: `README.md`)
- OpenAI Endpoints → SQLite State: writes request logs (evidence: `internal/proxy/proxy.go`)
- API Key Auth → SQLite State: reads and updates keys (evidence: `internal/apikey/apikey.go`)
- Admin API → Admin Sessions: authenticates sessions (evidence: `internal/admin/admin.go`)
- Admin API → OAuth Credentials: manages credentials (evidence: `README.md`)
- Admin API → Upstream Client: fetches account data (evidence: `internal/admin/admin.go`)
- Admin API → Model Catalog: refreshes catalog (evidence: `README.md`)
- Admin API → API Key Auth: manages keys (evidence: `internal/admin/admin.go`)
- Admin API → SQLite State: reads admin data (evidence: `internal/admin/admin.go`)
- Growth Controls → Growth Chain: triggers tasks (evidence: `README.md`)
- Admin API → Growth Controls: routes growth controls (evidence: `README.md`)
- Task Scheduler → Growth Chain: runs scheduled chain (evidence: `internal/scheduler/growth.go`)
- Growth Chain → Growth Operations: executes growth steps (evidence: `internal/scheduler/growth.go`)
- Growth Chain → SQLite State: persists daily state (evidence: `internal/scheduler/growth.go`)
- Task Scheduler → Runtime Settings: reads task settings
- Upstream Client → OAuth Credentials: refreshes tokens (evidence: `internal/upstream/client.go`)
- Upstream Client → CodeBuddy Service: calls upstream API (evidence: `README.md`)
- Growth Operations → CodeBuddy Service: reports activity (evidence: `README.md`)
- Model Catalog → CodeBuddy Service: loads model config (evidence: `README.md`)
- Client Fingerprint → Upstream Client: sets request headers
