# frappe/pathway architecture

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

- Interactive diagram: https://gitdiagram.com/frappe/pathway
- Repository: https://github.com/frappe/pathway

## Overview

Pathway is Grove’s Go data plane, run as either a tenant-aware gateway or a tenant-free ingress. The main request path authenticates and checks access, selects an engine or replica, transforms and proxies the request, then records usage and hop outcome. Grove also pushes desired state and retrieves usage through admin endpoints. The README documents TLS termination, model and credit endpoints, metrics, and in-process upgrades. Some wiring and subsystem source was not sampled; edges below are limited to excerpted relationships and explicit README statements.

Main entry points: [`internal/transport/http/server.go`](https://github.com/frappe/pathway/blob/main/internal/transport/http/server.go) (HTTP server), [`internal/transport/http/middleware/builtin.go`](https://github.com/frappe/pathway/blob/main/internal/transport/http/middleware/builtin.go) (Request middleware), [`internal/service/provisioning/provisioning.go`](https://github.com/frappe/pathway/blob/main/internal/service/provisioning/provisioning.go) (State provisioning), [`cmd/pathway/main.go`](https://github.com/frappe/pathway/blob/main/cmd/pathway/main.go) (Process and lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and transport"]
  node_runtime["Process and lifecycle<br/>[main.go]"]
  node_http["HTTP server<br/>[server.go]"]
  node_middleware["Request middleware<br/>[builtin.go]"]
  node_proxyhandler["Proxy handler<br/>[proxyhandler.go]"]
  node_proxy["Streaming proxy<br/>[proxy.go]"]
  node_admin["Admin endpoints<br/>[admin.go]"]
  node_respond["API responses<br/>[respond.go]"]
  node_config["Runtime configuration<br/>[config.go]"]
  node_metrics["Metrics endpoint<br/>[metrics.go]"]
  node_tls["TLS and listeners<br/>[listeners.go]"]
end

subgraph group_services["Request services"]
  node_admission["Identity and admission<br/>[admission.go]"]
  node_catalog["Model catalog<br/>[catalog.go]"]
  node_routing["Engine selection<br/>[routing.go]"]
  node_transform["Request transforms<br/>[transform.go]"]
  node_metering["Usage metering<br/>[metering.go]"]
  node_provisioning["State provisioning<br/>[provisioning.go]"]
end

subgraph group_state["State and persistence"]
  node_authdata["Identity records<br/>[identity.go]"]
  node_routecache["Route tables<br/>[routes.go]"]
  node_usage["Usage counters<br/>[usage.go]"]
  node_repository["Storage interfaces<br/>[repository.go]"]
end

subgraph group_domain["Domain rules"]
  node_accessrules["Access decisions<br/>[access.go]"]
  node_routechoice["Route selection rules<br/>[route.go]"]
  node_usageparse["Usage parsing<br/>[usage.go]"]
end

node_client(("API caller"))
node_grove(("Grove control plane"))
node_engine{{"Engine or ingress"}}
node_redis[("Redis store")]

node_client -->|"sends requests"| node_http
node_http -->|"dispatches requests"| node_middleware
node_middleware -->|"checks identity"| node_admission
node_admission -.->|"resolves credentials"| node_authdata
node_middleware -->|"selects engine"| node_routing
node_routing -->|"reads placements"| node_routecache
node_routing -->|"picks route"| node_routechoice
node_middleware -->|"rewrites request"| node_transform
node_middleware -.->|"continues chain"| node_proxyhandler
node_proxyhandler -->|"forwards request"| node_proxy
node_proxy -->|"streams request"| node_engine
node_proxy -->|"reads usage frame"| node_usageparse
node_middleware -->|"records outcome"| node_metering
node_metering -->|"accrues usage"| node_usage
node_grove -->|"pushes state"| node_admin
node_admin -->|"applies state"| node_provisioning
node_provisioning -->|"replaces routes"| node_routecache
node_provisioning -->|"drains counters"| node_usage
node_admin -->|"returns usage"| node_grove
node_http -.->|"serves models"| node_catalog
node_client -->|"requests credits"| node_http
node_http -->|"exposes metrics"| node_metrics
node_runtime -->|"loads settings"| node_config
node_runtime -->|"constructs server"| node_http
node_runtime -->|"starts listeners"| node_tls
node_http -.->|"formats responses"| node_respond
node_repository -->|"implemented by"| node_redis
node_metering -->|"uses interfaces"| node_repository
node_provisioning -->|"uses interfaces"| node_repository

click node_runtime "https://github.com/frappe/pathway/blob/main/cmd/pathway/main.go"
click node_http "https://github.com/frappe/pathway/blob/main/internal/transport/http/server.go"
click node_middleware "https://github.com/frappe/pathway/blob/main/internal/transport/http/middleware/builtin.go"
click node_proxyhandler "https://github.com/frappe/pathway/blob/main/internal/transport/http/proxyhandler.go"
click node_proxy "https://github.com/frappe/pathway/blob/main/internal/transport/http/proxy/proxy.go"
click node_admin "https://github.com/frappe/pathway/blob/main/internal/transport/http/admin.go"
click node_respond "https://github.com/frappe/pathway/blob/main/internal/transport/respond/respond.go"
click node_admission "https://github.com/frappe/pathway/blob/main/internal/service/admission/admission.go"
click node_catalog "https://github.com/frappe/pathway/blob/main/internal/service/catalog/catalog.go"
click node_routing "https://github.com/frappe/pathway/blob/main/internal/service/routing/routing.go"
click node_transform "https://github.com/frappe/pathway/blob/main/internal/service/transform/transform.go"
click node_metering "https://github.com/frappe/pathway/blob/main/internal/service/metering/metering.go"
click node_provisioning "https://github.com/frappe/pathway/blob/main/internal/service/provisioning/provisioning.go"
click node_authdata "https://github.com/frappe/pathway/blob/main/internal/repository/redis/identity.go"
click node_routecache "https://github.com/frappe/pathway/blob/main/internal/repository/redis/routes.go"
click node_usage "https://github.com/frappe/pathway/blob/main/internal/repository/redis/usage.go"
click node_repository "https://github.com/frappe/pathway/blob/main/internal/repository/repository.go"
click node_accessrules "https://github.com/frappe/pathway/blob/main/internal/domain/access.go"
click node_routechoice "https://github.com/frappe/pathway/blob/main/internal/domain/route.go"
click node_usageparse "https://github.com/frappe/pathway/blob/main/internal/domain/usage.go"
click node_config "https://github.com/frappe/pathway/blob/main/internal/config/config.go"
click node_metrics "https://github.com/frappe/pathway/blob/main/internal/transport/http/metrics.go"
click node_tls "https://github.com/frappe/pathway/blob/main/internal/transport/http/listeners.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_runtime,node_http,node_middleware,node_proxyhandler,node_proxy,node_admin,node_respond,node_config,node_metrics,node_tls toneBlue
class node_admission,node_catalog,node_routing,node_transform,node_metering,node_provisioning,node_redis toneAmber
class node_authdata,node_routecache,node_usage,node_repository,node_client toneMint
class node_accessrules,node_routechoice,node_usageparse toneRose
class node_grove,node_engine toneIndigo
```

## Components

### Entry and transport

- [Process and lifecycle](https://github.com/frappe/pathway/blob/main/cmd/pathway/main.go): `cmd/pathway/main.go`
- [HTTP server](https://github.com/frappe/pathway/blob/main/internal/transport/http/server.go): `internal/transport/http/server.go`
- [Request middleware](https://github.com/frappe/pathway/blob/main/internal/transport/http/middleware/builtin.go): `internal/transport/http/middleware/builtin.go`
- [Proxy handler](https://github.com/frappe/pathway/blob/main/internal/transport/http/proxyhandler.go): `internal/transport/http/proxyhandler.go`
- [Streaming proxy](https://github.com/frappe/pathway/blob/main/internal/transport/http/proxy/proxy.go): `internal/transport/http/proxy/proxy.go`
- [Admin endpoints](https://github.com/frappe/pathway/blob/main/internal/transport/http/admin.go): `internal/transport/http/admin.go`
- [API responses](https://github.com/frappe/pathway/blob/main/internal/transport/respond/respond.go): `internal/transport/respond/respond.go`
- [Runtime configuration](https://github.com/frappe/pathway/blob/main/internal/config/config.go): `internal/config/config.go`
- [Metrics endpoint](https://github.com/frappe/pathway/blob/main/internal/transport/http/metrics.go): `internal/transport/http/metrics.go`
- [TLS and listeners](https://github.com/frappe/pathway/blob/main/internal/transport/http/listeners.go): `internal/transport/http/listeners.go`

### Request services

- [Identity and admission](https://github.com/frappe/pathway/blob/main/internal/service/admission/admission.go): `internal/service/admission/admission.go`
- [Model catalog](https://github.com/frappe/pathway/blob/main/internal/service/catalog/catalog.go): `internal/service/catalog/catalog.go`
- [Engine selection](https://github.com/frappe/pathway/blob/main/internal/service/routing/routing.go): `internal/service/routing/routing.go`
- [Request transforms](https://github.com/frappe/pathway/blob/main/internal/service/transform/transform.go): `internal/service/transform/transform.go`
- [Usage metering](https://github.com/frappe/pathway/blob/main/internal/service/metering/metering.go): `internal/service/metering/metering.go`
- [State provisioning](https://github.com/frappe/pathway/blob/main/internal/service/provisioning/provisioning.go): `internal/service/provisioning/provisioning.go`

### State and persistence

- [Identity records](https://github.com/frappe/pathway/blob/main/internal/repository/redis/identity.go): `internal/repository/redis/identity.go`
- [Route tables](https://github.com/frappe/pathway/blob/main/internal/repository/redis/routes.go): `internal/repository/redis/routes.go`
- [Usage counters](https://github.com/frappe/pathway/blob/main/internal/repository/redis/usage.go): `internal/repository/redis/usage.go`
- [Storage interfaces](https://github.com/frappe/pathway/blob/main/internal/repository/repository.go): `internal/repository/repository.go`

### Domain rules

- [Access decisions](https://github.com/frappe/pathway/blob/main/internal/domain/access.go): `internal/domain/access.go`
- [Route selection rules](https://github.com/frappe/pathway/blob/main/internal/domain/route.go): `internal/domain/route.go`
- [Usage parsing](https://github.com/frappe/pathway/blob/main/internal/domain/usage.go): `internal/domain/usage.go`

### Other components

- **API caller**
- **Grove control plane**
- **Engine or ingress**
- **Redis store**

## Connections

- API caller → HTTP server: sends requests
- HTTP server → Request middleware: dispatches requests (evidence: `internal/transport/http/server.go`)
- Request middleware → Identity and admission: checks identity (evidence: `internal/transport/http/middleware/builtin.go`)
- Identity and admission → Identity records: resolves credentials
- Request middleware → Engine selection: selects engine (evidence: `internal/transport/http/middleware/builtin.go`)
- Engine selection → Route tables: reads placements (evidence: `internal/service/routing/routing.go`)
- Engine selection → Route selection rules: picks route (evidence: `internal/service/routing/routing.go`)
- Request middleware → Request transforms: rewrites request (evidence: `internal/transport/http/middleware/builtin.go`)
- Request middleware → Proxy handler: continues chain
- Proxy handler → Streaming proxy: forwards request (evidence: `internal/transport/http/proxyhandler.go`)
- Streaming proxy → Engine or ingress: streams request
- Streaming proxy → Usage parsing: reads usage frame
- Request middleware → Usage metering: records outcome (evidence: `internal/transport/http/middleware/builtin.go`)
- Usage metering → Usage counters: accrues usage (evidence: `internal/service/metering/metering.go`)
- Grove control plane → Admin endpoints: pushes state
- Admin endpoints → State provisioning: applies state (evidence: `internal/transport/http/admin.go`)
- State provisioning → Route tables: replaces routes (evidence: `internal/service/provisioning/provisioning.go`)
- State provisioning → Usage counters: drains counters (evidence: `internal/service/provisioning/provisioning.go`)
- Admin endpoints → Grove control plane: returns usage
- HTTP server → Model catalog: serves models
- API caller → HTTP server: requests credits
- HTTP server → Metrics endpoint: exposes metrics
- Process and lifecycle → Runtime configuration: loads settings (evidence: `cmd/pathway/main.go`)
- Process and lifecycle → HTTP server: constructs server (evidence: `cmd/pathway/main.go`)
- Process and lifecycle → TLS and listeners: starts listeners
- HTTP server → API responses: formats responses
- Storage interfaces → Redis store: implemented by
- Usage metering → Storage interfaces: uses interfaces (evidence: `internal/service/metering/metering.go`)
- State provisioning → Storage interfaces: uses interfaces (evidence: `internal/service/provisioning/provisioning.go`)
