# ajay-pujari/freellmapi architecture

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

- Interactive diagram: https://gitdiagram.com/ajay-pujari/freellmapi
- Repository: https://github.com/ajay-pujari/freellmapi

## Overview

FreeLLMAPI combines an OpenAI-compatible inference gateway with a management dashboard, CLI, and desktop shell. The main request path is a client request entering the server, being routed to a provider using configured keys and availability, and returning an inference result; the server also records request and quota information for management and analytics. The README documents catalog sync, custom endpoints, media, embeddings, compression, and agent setup. Some of those links are shown as unverified because their implementation call sites were not sampled.

Main entry points: [`server/src/app.ts`](https://github.com/ajay-pujari/freellmapi/blob/main/server/src/app.ts) (HTTP App), [`server/src/services/router.ts`](https://github.com/ajay-pujari/freellmapi/blob/main/server/src/services/router.ts) (Model Router), [`server/src/routes`](https://github.com/ajay-pujari/freellmapi/tree/main/server/src/routes) (Inference Routes), [`server/src/providers`](https://github.com/ajay-pujari/freellmapi/tree/main/server/src/providers) (Provider Adapters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Inference Gateway"]
  node_app["HTTP App<br/>[app.ts]"]
  node_wire_routes["Inference Routes"]
  node_compression["Prompt Compression<br/>[pipeline.ts]"]
end

subgraph group_routing["Routing and Providers"]
  node_router["Model Router<br/>[router.ts]"]
  node_provider_adapters["Provider Adapters"]
  node_custom_endpoints["Custom Endpoints<br/>[custom-endpoint.ts]"]
  node_quota["Quota and Limits<br/>[provider-quota.ts]"]
end

subgraph group_management["Management and Data"]
  node_catalog["Catalog Sync<br/>[catalog-sync.ts]"]
  node_database[("Application Database<br/>[index.ts]")]
  node_analytics["Request Analytics<br/>[analytics.ts]"]
  node_management_routes["Key and Settings APIs<br/>[keys.ts]"]
end

subgraph group_interfaces["User Interfaces"]
  node_dashboard["Web Dashboard<br/>[App.tsx]"]
  node_dashboard_pages["Product Pages"]
  node_cli["Agent Setup CLI<br/>[index.ts]"]
  node_desktop["Desktop Shell<br/>[main.ts]"]
end

node_api_client(("API Client"))
node_upstream(("LLM Providers"))

node_api_client -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_wire_routes
node_wire_routes -.->|"selects provider"| node_router
node_router -->|"resolves provider"| node_provider_adapters
node_provider_adapters -.->|"calls inference"| node_upstream
node_router -->|"reads routing state"| node_database
node_router -.->|"checks quota"| node_quota
node_provider_adapters -->|"records observations"| node_quota
node_app -->|"mounts routes"| node_management_routes
node_app -->|"mounts routes"| node_analytics
node_dashboard -.->|"presents features"| node_dashboard_pages
node_dashboard -.->|"uses local API"| node_app
node_cli -->|"configures clients"| node_api_client
node_desktop -->|"starts server"| node_app
node_catalog -.->|"updates catalog"| node_database
node_wire_routes -.->|"compresses prompts"| node_compression
node_api_client -.->|"configures endpoints"| node_custom_endpoints

click node_app "https://github.com/ajay-pujari/freellmapi/blob/main/server/src/app.ts"
click node_wire_routes "https://github.com/ajay-pujari/freellmapi/tree/main/server/src/routes"
click node_compression "https://github.com/ajay-pujari/freellmapi/blob/main/server/src/services/compression/pipeline.ts"
click node_router "https://github.com/ajay-pujari/freellmapi/blob/main/server/src/services/router.ts"
click node_provider_adapters "https://github.com/ajay-pujari/freellmapi/tree/main/server/src/providers"
click node_custom_endpoints "https://github.com/ajay-pujari/freellmapi/blob/main/server/src/services/custom-endpoint.ts"
click node_quota "https://github.com/ajay-pujari/freellmapi/blob/main/server/src/services/provider-quota.ts"
click node_catalog "https://github.com/ajay-pujari/freellmapi/blob/main/server/src/services/catalog-sync.ts"
click node_database "https://github.com/ajay-pujari/freellmapi/blob/main/server/src/db/index.ts"
click node_analytics "https://github.com/ajay-pujari/freellmapi/blob/main/server/src/routes/analytics.ts"
click node_management_routes "https://github.com/ajay-pujari/freellmapi/blob/main/server/src/routes/keys.ts"
click node_dashboard "https://github.com/ajay-pujari/freellmapi/blob/main/client/src/App.tsx"
click node_dashboard_pages "https://github.com/ajay-pujari/freellmapi/tree/main/client/src/pages"
click node_cli "https://github.com/ajay-pujari/freellmapi/blob/main/cli/src/index.ts"
click node_desktop "https://github.com/ajay-pujari/freellmapi/blob/main/desktop/src/main.ts"

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_app,node_wire_routes,node_compression,node_api_client toneBlue
class node_router,node_provider_adapters,node_custom_endpoints,node_quota toneAmber
class node_catalog,node_database,node_analytics,node_management_routes toneMint
class node_dashboard,node_dashboard_pages,node_cli,node_desktop toneRose
class node_upstream toneIndigo
```

## Components

### Inference Gateway

- [HTTP App](https://github.com/ajay-pujari/freellmapi/blob/main/server/src/app.ts): `server/src/app.ts`
- [Inference Routes](https://github.com/ajay-pujari/freellmapi/tree/main/server/src/routes): `server/src/routes`
- [Prompt Compression](https://github.com/ajay-pujari/freellmapi/blob/main/server/src/services/compression/pipeline.ts): `server/src/services/compression/pipeline.ts`

### Routing and Providers

- [Model Router](https://github.com/ajay-pujari/freellmapi/blob/main/server/src/services/router.ts): `server/src/services/router.ts`
- [Provider Adapters](https://github.com/ajay-pujari/freellmapi/tree/main/server/src/providers): `server/src/providers`
- [Custom Endpoints](https://github.com/ajay-pujari/freellmapi/blob/main/server/src/services/custom-endpoint.ts): `server/src/services/custom-endpoint.ts`
- [Quota and Limits](https://github.com/ajay-pujari/freellmapi/blob/main/server/src/services/provider-quota.ts): `server/src/services/provider-quota.ts`

### Management and Data

- [Catalog Sync](https://github.com/ajay-pujari/freellmapi/blob/main/server/src/services/catalog-sync.ts): `server/src/services/catalog-sync.ts`
- [Application Database](https://github.com/ajay-pujari/freellmapi/blob/main/server/src/db/index.ts): `server/src/db/index.ts`
- [Request Analytics](https://github.com/ajay-pujari/freellmapi/blob/main/server/src/routes/analytics.ts): `server/src/routes/analytics.ts`
- [Key and Settings APIs](https://github.com/ajay-pujari/freellmapi/blob/main/server/src/routes/keys.ts): `server/src/routes/keys.ts`

### User Interfaces

- [Web Dashboard](https://github.com/ajay-pujari/freellmapi/blob/main/client/src/App.tsx): `client/src/App.tsx`
- [Product Pages](https://github.com/ajay-pujari/freellmapi/tree/main/client/src/pages): `client/src/pages`
- [Agent Setup CLI](https://github.com/ajay-pujari/freellmapi/blob/main/cli/src/index.ts): `cli/src/index.ts`
- [Desktop Shell](https://github.com/ajay-pujari/freellmapi/blob/main/desktop/src/main.ts): `desktop/src/main.ts`

### Other components

- **API Client**
- **LLM Providers**

## Connections

- API Client → HTTP App: sends requests (evidence: `README.md`)
- HTTP App → Inference Routes: mounts routes (evidence: `server/src/app.ts`)
- Inference Routes → Model Router: selects provider
- Model Router → Provider Adapters: resolves provider (evidence: `server/src/services/router.ts`)
- Provider Adapters → LLM Providers: calls inference
- Model Router → Application Database: reads routing state (evidence: `server/src/services/router.ts`)
- Model Router → Quota and Limits: checks quota (evidence: `server/src/services/router.ts`)
- Provider Adapters → Quota and Limits: records observations (evidence: `server/src/providers/router9.ts`)
- HTTP App → Key and Settings APIs: mounts routes (evidence: `server/src/app.ts`)
- HTTP App → Request Analytics: mounts routes (evidence: `server/src/app.ts`)
- Web Dashboard → Product Pages: presents features
- Web Dashboard → HTTP App: uses local API
- Agent Setup CLI → API Client: configures clients
- Desktop Shell → HTTP App: starts server (evidence: `desktop/src/main.ts`)
- Catalog Sync → Application Database: updates catalog
- Inference Routes → Prompt Compression: compresses prompts
- API Client → Custom Endpoints: configures endpoints (evidence: `README.md`)
