afi

module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2026 License: MIT

README

AFI - AI Gateway

AFI is a self-hostable LLM gateway with a control plane (configuration, identity, snapshots) and a data plane (high-performance inference). The data plane serves requests from immutable configuration snapshots — it never queries the config database on the hot path.

Prerequisites

Tool Notes
Docker Compose v2 — enough for Quick start
Go See go.mod (1.25.x) — local development only
pnpm Optional, for web/ and docs (make doc-serve)
OpenAI API key For live inference

Quick start (Docker Compose)

export OPENAI_API_KEY="sk-..."   # optional but needed for chat
make quickstart

Then open http://localhost:3000 (admin@afi.local / admin) or call the gateway:

curl -s http://localhost:8080/v1/chat/completions \
  -H "Authorization: Bearer sk-project-local-dev-token-12345" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"ping"}]}'

Guide: docs/guides/quick-start.md. Host-based Go workflow: docs/development/local-dev.md.

Components

Process Port Role
controlplane :8081 Admin, platform API, snapshot publish
gateway :8080 OpenAI-compatible inference + quota enforcement
worker Drains usage outbox → usage_events
Postgres :5433 Config + snapshots (make dev-up)
Adminer :5050 DB UI
web/ :3000 Platform UI (pnpm --dir web dev)

Common commands

make quickstart         # full stack via Docker Compose
make build              # bin/controlplane, bin/gateway, bin/afi
make test               # unit tests (preferred quality bar)
make verify             # smoke against a running local stack
make seed               # CLI: seed local data + publish snapshot
make snapshot-publish
make doc-serve          # http://localhost:4321

Architecture (short)

%%{init: {"theme":"base","themeVariables":{"primaryColor":"#ffffff","primaryTextColor":"#111111","primaryBorderColor":"#111111","lineColor":"#111111","secondaryColor":"#f5f5f5","tertiaryColor":"#ffffff","fontFamily":"ui-sans-serif,system-ui,sans-serif"}}}%%
flowchart LR
  UI[Platform UI / CLI] --> CP[Control Plane] --> SS[(Snapshot Store)]
  Clients --> GW[Gateway] --> PA[Provider adapters]
  SS -.->|watch / hot reload| GW

  classDef node fill:#ffffff,stroke:#111111,color:#111111,stroke-width:2px
  classDef store fill:#f5f5f5,stroke:#111111,color:#111111,stroke-width:2px
  class UI,CP,Clients,GW,PA node
  class SS store

See docs/development/architecture.md.

Directories

Path Synopsis
cmd
cli command
controlplane command
gateway command
worker command
examples
a2a-echo command
Command a2a-echo is a minimal Agent2Agent (A2A) JSON-RPC upstream for local AFI testing.
Command a2a-echo is a minimal Agent2Agent (A2A) JSON-RPC upstream for local AFI testing.
extensions
grpcecho command
Command grpcecho is a sample gRPC extension plugin (ChatIR provider + BeforeCall/BeforeChat).
Command grpcecho is a sample gRPC extension plugin (ChatIR provider + BeforeCall/BeforeChat).
tagquota
Package tagquota is an **example** BeforeCall hook that rate-limits by an X-AFI-Tags value.
Package tagquota is an **example** BeforeCall hook that rate-limits by an X-AFI-Tags value.
gen
internal
adapters/grpcprovider
Package grpcprovider hosts process-isolated gRPC extensions for the gateway.
Package grpcprovider hosts process-isolated gRPC extensions for the gateway.
adapters/objectstore
Package objectstore provides an S3-compatible object store for generated assets.
Package objectstore provides an S3-compatible object store for generated assets.
adapters/wasm
Package wasm hosts TinyGo-compiled lifecycle hooks via wazero.
Package wasm hosts TinyGo-compiled lifecycle hooks via wazero.
audit
Package audit is the durable org-scoped audit trail bounded context.
Package audit is the durable org-scoped audit trail bounded context.
dataplane/dialect
Package dialect encodes/decodes client wire formats against chat IR.
Package dialect encodes/decodes client wire formats against chat IR.
dataplane/ir
Package ir defines the gateway-owned chat internal representation.
Package ir defines the gateway-owned chat internal representation.
telemetry
Package telemetry configures OpenTelemetry metrics and traces for AFI processes.
Package telemetry configures OpenTelemetry metrics and traces for AFI processes.
sdk
chatir
Package chatir defines the gateway-owned chat internal representation used by in-process SDK adapters and (via protobuf) gRPC extensions.
Package chatir defines the gateway-owned chat internal representation used by in-process SDK adapters and (via protobuf) gRPC extensions.
hook
Package hook defines the in-process lifecycle contract for gateway extensions.
Package hook defines the in-process lifecycle contract for gateway extensions.
provider
Package provider documents the AFI gateway ChatProvider contract for multi-model extensibility.
Package provider documents the AFI gateway ChatProvider contract for multi-model extensibility.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL