How chdsbd/kodiak works
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: asgi.py Django API · evaluation.py PR policy evaluation · queue.py PR work queue · dashboard-deploy.yml Dashboard deploy
Components 18
GitHub Bot
Webhook-driven PR automation runtime.
- Webhook ingest · Authenticates and accepts GitHub events.
bot/kodiak/entrypoints/ingest.py - Event dispatch · Maps webhook types to affected PR work.
bot/kodiak/events/base.py - PR work queue · Enqueues and requeues asynchronous evaluation.
bot/kodiak/queue.py - Redis · Durable asynchronous queue and throttling boundary.
bot/kodiak/redis_client.py - Evaluation worker · Processes queued PR evaluations and actions.
bot/kodiak/entrypoints/worker.py - PR policy evaluation · Evaluates checks, approvals, protections, and merge behavior.
bot/kodiak/evaluation.py - Repository config · Parses and validates repository Kodiak policy.
bot/kodiak/config.py - GitHub client · Encapsulates GitHub API reads and mutations.
bot/kodiak/http.py - PR refresh · Reevaluates active PRs outside webhook triggers.
bot/kodiak/refresh_pull_requests.py
Dashboard API
Django dashboard and activity domain.
- Django API · Serves dashboard endpoints and GitHub event ingestion.
web_api/web_api/asgi.py - Activity & merge queues · Persistence, merge-queue data, and event ingestion.
web_api/web_api/models.py - Dashboard database
Dashboard UI
React single-page dashboard.
- React dashboard · Account, activity, and billing dashboard.
web_ui/src/index.tsx - API & auth client · Connects the dashboard to API and authentication.
web_ui/src/api.ts - Nginx UI delivery
web_ui/nginx.conf
Operations
Container delivery and scheduled deployment.
- Activity aggregation · Systemd-triggered API activity aggregation.
- Dashboard deploy
infrastructure/playbooks/dashboard-deploy.yml
Other components
- GitHub App & API · Webhook source and PR mutation boundary.
Connections 19
- 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