# chdsbd/kodiak architecture

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

- Interactive diagram: https://gitdiagram.com/chdsbd/kodiak
- Repository: https://github.com/chdsbd/kodiak

## Overview

#### Purpose and Top-Level Services
Kodiak is a GitHub App that automatically updates and merges pull requests when configured requirements—such as CI, approvals, and labels—are met. It is a multi-service repository: the operational bot, a dashboard API, a React dashboard, documentation, and deployment automation. Primary roots: `bot/`, `web_api/`, `web_ui/`, `infrastructure/`.

#### GitHub Bot: Ingress and Execution
The Python bot is the core runtime. Its HTTP ingestion process accepts GitHub webhook events, authenticates/parses them, and places work onto a Redis-backed queue; separate workers process queued PR evaluations and GitHub mutations. Entrypoints are `bot/kodiak/entrypoints/ingest.py` and `bot/kodiak/entrypoints/worker.py`; deployment composition is provided by `bot/Dockerfile`, `bot/docker-compose.yml`, and `bot/supervisord.conf`.

#### Event-to-PR Processing Pipeline
GitHub webhook payloads are modeled and dispatched by event-specific handlers in `bot/kodiak/events/base.py` and event modules such as `bot/kodiak/events/pull_request.py`, `bot/kodiak/events/check_run.py`, and `bot/kodiak/events/status.py`. Handlers identify affected PRs and enqueue/requeue evaluation work through `bot/kodiak/queue.py`. This isolates request handling from potentially slow GitHub API calls and merge/update actions.

#### Evaluation, Configuration, and GitHub Boundary
Worker-side decision logic determines whether a PR should be updated or merged, including branch protection, checks, approvals, merge method/message, and dependency-bot behavior. Core modules are `bot/kodiak/evaluation.py`, `bot/kodiak/pull_request.py`, and `bot/kodiak/dependencies.py`. Repository-level Kodiak configuration is parsed and validated in `bot/kodiak/config.py` and `bot/kodiak/app_config.py`. GitHub API access is encapsulated by `bot/kodiak/http.py` and query modules such as `bot/kodiak/queries/commits.py`, keeping external API interaction distinct from policy evaluation.

#### Queueing and Operational Dependencies
Redis is the bot’s durable/asynchronous coordination boundary, represented by `bot/kodiak/redis_client.py`, `bot/kodiak/queue.py`, and `bot/kodiak/throttle.py`. The bot runs as a containerized Python service and communicates with GitHub as an installed App; credentials and runtime settings are environment-driven (`bot/example.env`). Refresh logic in `bot/kodiak/refresh_pull_requests.py` supports reevaluating active PRs beyond direct webhook triggers.

#### Dashboard API and Persistent Data
`web_api/` is a Django-based API for the dashboard and activity/billing domain. ASGI/WSGI application entrypoints are `web_api/web_api/asgi.py` and `web_api/web_api/wsgi.py`; routing and endpoint handling live in `web_api/web_api/urls.py` and `web_api/web_api/views.py`. Its domain persistence is defined in `web_api/web_api/models.py` and schema migrations under `web_api/web_api/migrations/`. It also ingests GitHub events (`web_api/web_api/event_ingestion.py`), exposes merge-queue data (`web_api/web_api/merge_queues.py`), and uses scheduled management commands to aggregate PR/user activity.

#### Dashboard Frontend and Deployment
`web_ui/` is a TypeScript React single-page dashboard. Browser bootstrap and application composition are `web_ui/src/index.tsx` and `web_ui/src/components/App.tsx`; API/auth boundaries are `web_ui/src/api.ts` and `web_ui/src/auth.ts`. Key product views include account, activity, and usage/billing pages under `web_ui/src/components/`. Nginx/container delivery is defined by `web_ui/Dockerfile` and `web_ui/nginx.conf`. Infrastructure includes systemd timers/services for API activity aggregation in `infrastructure/systemd/` and deployment automation in `infrastructure/playbooks/dashboard-deploy.yml`.

Main entry points: [`web_api/web_api/asgi.py`](https://github.com/chdsbd/kodiak/blob/master/web_api/web_api/asgi.py) (Django API), [`bot/kodiak/evaluation.py`](https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/evaluation.py) (PR policy evaluation), [`bot/kodiak/queue.py`](https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/queue.py) (PR work queue), [`infrastructure/playbooks/dashboard-deploy.yml`](https://github.com/chdsbd/kodiak/blob/master/infrastructure/playbooks/dashboard-deploy.yml) (Dashboard deploy)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bot["GitHub Bot"]
  node_ingest["Webhook ingest<br/>Python entrypoint<br/>[ingest.py]"]
  node_events["Event dispatch<br/>event handlers<br/>[base.py]"]
  node_queue["PR work queue<br/>queue layer<br/>[queue.py]"]
  node_redis[("Redis<br/>coordination store<br/>[redis_client.py]")]
  node_worker["Evaluation worker<br/>Python entrypoint<br/>[worker.py]"]
  node_policy["PR policy evaluation<br/>decision logic<br/>[evaluation.py]"]
  node_repo_config["Repository config<br/>config parser<br/>[config.py]"]
  node_github_client["GitHub client<br/>HTTP/query boundary<br/>[http.py]"]
  node_refresh["PR refresh<br/>background refresh"]
end

subgraph group_api["Dashboard API"]
  node_dashboard_api["Django API<br/>ASGI/WSGI service<br/>[asgi.py]"]
  node_api_domain[("Activity &amp; merge queues<br/>Django domain<br/>[models.py]")]
  node_dashboard_db[("Dashboard database<br/>persistent store")]
end

subgraph group_ui["Dashboard UI"]
  node_dashboard_ui["React dashboard<br/>SPA bootstrap<br/>[index.tsx]"]
  node_ui_api["API &amp; auth client<br/>frontend boundary<br/>[api.ts]"]
  node_ui_delivery["Nginx UI delivery<br/>container delivery<br/>[nginx.conf]"]
end

subgraph group_ops["Operations"]
  node_aggregation["Activity aggregation<br/>scheduled jobs"]
  node_deploy["Dashboard deploy<br/>deployment automation"]
end

node_github{{"GitHub App &amp; API<br/>external platform"}}

node_github -->|"webhooks"| node_ingest
node_ingest -->|"parse events"| node_events
node_events -->|"enqueue PRs"| node_queue
node_queue -->|"store work"| node_redis
node_redis -->|"dequeue"| node_worker
node_worker -->|"evaluate"| node_policy
node_policy -->|"load policy"| node_repo_config
node_policy -->|"read and act"| node_github_client
node_github_client -->|"API calls"| node_github
node_refresh -.->|"requeue active PRs"| node_queue
node_github -->|"events"| node_dashboard_api
node_dashboard_api -->|"routes to domain"| node_api_domain
node_api_domain -->|"persist"| node_dashboard_db
node_dashboard_ui -->|"uses"| node_ui_api
node_ui_api -->|"dashboard API"| node_dashboard_api
node_ui_delivery -->|"serves SPA"| node_dashboard_ui
node_aggregation -->|"scheduled commands"| node_dashboard_api
node_deploy -->|"deploys"| node_dashboard_api
node_deploy -->|"deploys"| node_ui_delivery

click node_ingest "https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/entrypoints/ingest.py"
click node_events "https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/events/base.py"
click node_queue "https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/queue.py"
click node_redis "https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/redis_client.py"
click node_worker "https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/entrypoints/worker.py"
click node_policy "https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/evaluation.py"
click node_repo_config "https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/config.py"
click node_github_client "https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/http.py"
click node_refresh "https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/refresh_pull_requests.py"
click node_dashboard_api "https://github.com/chdsbd/kodiak/blob/master/web_api/web_api/asgi.py"
click node_api_domain "https://github.com/chdsbd/kodiak/blob/master/web_api/web_api/models.py"
click node_dashboard_ui "https://github.com/chdsbd/kodiak/blob/master/web_ui/src/index.tsx"
click node_ui_api "https://github.com/chdsbd/kodiak/blob/master/web_ui/src/api.ts"
click node_ui_delivery "https://github.com/chdsbd/kodiak/blob/master/web_ui/nginx.conf"
click node_deploy "https://github.com/chdsbd/kodiak/blob/master/infrastructure/playbooks/dashboard-deploy.yml"

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_ingest,node_events,node_queue,node_redis,node_worker,node_policy,node_repo_config,node_github_client,node_refresh toneBlue
class node_dashboard_api,node_api_domain,node_dashboard_db toneAmber
class node_dashboard_ui,node_ui_api,node_ui_delivery toneMint
class node_aggregation,node_deploy toneRose
class node_github toneNeutral
```

## Components

### GitHub Bot

Webhook-driven PR automation runtime.

- [Webhook ingest](https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/entrypoints/ingest.py): Python entrypoint · Authenticates and accepts GitHub events. · `bot/kodiak/entrypoints/ingest.py`
- [Event dispatch](https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/events/base.py): event handlers · Maps webhook types to affected PR work. · `bot/kodiak/events/base.py`
- [PR work queue](https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/queue.py): queue layer · Enqueues and requeues asynchronous evaluation. · `bot/kodiak/queue.py`
- [Redis](https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/redis_client.py): coordination store · Durable asynchronous queue and throttling boundary. · `bot/kodiak/redis_client.py`
- [Evaluation worker](https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/entrypoints/worker.py): Python entrypoint · Processes queued PR evaluations and actions. · `bot/kodiak/entrypoints/worker.py`
- [PR policy evaluation](https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/evaluation.py): decision logic · Evaluates checks, approvals, protections, and merge behavior. · `bot/kodiak/evaluation.py`
- [Repository config](https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/config.py): config parser · Parses and validates repository Kodiak policy. · `bot/kodiak/config.py`
- [GitHub client](https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/http.py): HTTP/query boundary · Encapsulates GitHub API reads and mutations. · `bot/kodiak/http.py`
- [PR refresh](https://github.com/chdsbd/kodiak/blob/master/bot/kodiak/refresh_pull_requests.py): background refresh · Reevaluates active PRs outside webhook triggers. · `bot/kodiak/refresh_pull_requests.py`

### Dashboard API

Django dashboard and activity domain.

- [Django API](https://github.com/chdsbd/kodiak/blob/master/web_api/web_api/asgi.py): ASGI/WSGI service · Serves dashboard endpoints and GitHub event ingestion. · `web_api/web_api/asgi.py`
- [Activity & merge queues](https://github.com/chdsbd/kodiak/blob/master/web_api/web_api/models.py): Django domain · Persistence, merge-queue data, and event ingestion. · `web_api/web_api/models.py`
- **Dashboard database**: persistent store

### Dashboard UI

React single-page dashboard.

- [React dashboard](https://github.com/chdsbd/kodiak/blob/master/web_ui/src/index.tsx): SPA bootstrap · Account, activity, and billing dashboard. · `web_ui/src/index.tsx`
- [API & auth client](https://github.com/chdsbd/kodiak/blob/master/web_ui/src/api.ts): frontend boundary · Connects the dashboard to API and authentication. · `web_ui/src/api.ts`
- [Nginx UI delivery](https://github.com/chdsbd/kodiak/blob/master/web_ui/nginx.conf): container delivery · `web_ui/nginx.conf`

### Operations

Container delivery and scheduled deployment.

- **Activity aggregation**: scheduled jobs · Systemd-triggered API activity aggregation.
- [Dashboard deploy](https://github.com/chdsbd/kodiak/blob/master/infrastructure/playbooks/dashboard-deploy.yml): deployment automation · `infrastructure/playbooks/dashboard-deploy.yml`

### Other components

- **GitHub App & API**: external platform · Webhook source and PR mutation boundary.

## Connections

- GitHub App & API → Webhook ingest: webhooks
- Webhook ingest → Event dispatch: parse events
- Event dispatch → PR work queue: enqueue PRs
- PR work queue → Redis: store work
- Redis → Evaluation worker: dequeue
- Evaluation worker → PR policy evaluation: evaluate
- PR policy evaluation → Repository config: load policy
- PR policy evaluation → GitHub client: read and act
- GitHub client → GitHub App & API: API calls
- PR refresh → PR work queue: requeue active PRs
- GitHub App & API → Django API: events
- Django API → Activity & merge queues: routes to domain
- Activity & merge queues → Dashboard database: persist
- React dashboard → API & auth client: uses
- API & auth client → Django API: dashboard API
- Nginx UI delivery → React dashboard: serves SPA
- Activity aggregation → Django API: scheduled commands
- Dashboard deploy → Django API: deploys
- Dashboard deploy → Nginx UI delivery: deploys
