Skip to content

Architecture

This page explains how Grimoire works internally, to help you understand its behaviour and make informed configuration decisions.

Overview

Grimoire is a single-process Python application built on FastAPI. It combines:

  • A scheduler (APScheduler) that periodically fetches data from the GitHub API
  • A check/action engine that runs user-defined scripts against cloned repos
  • A web dashboard (Jinja2 + HTMX) and REST API for visibility and control
  • A SQLite database for persistence (zero external dependencies)

Data flow

GitHub API
    │
    ▼
┌──────────────────┐
│  GitHub Service   │──► SQLite (cache + results)
│  (httpx client)   │
└──────────────────┘
    │
    ▼
┌──────────────────┐     ┌──────────────────┐
│  Checks Engine    │────►│  Workspace Mgr   │
│  (validates)      │     │  (git clone/pull)│
└──────────────────┘     └──────────────────┘
    │
    ▼
┌──────────────────┐
│  Actions Engine   │────► git push, gh CLI
│  (remediates)     │
└──────────────────┘
    │
    ▼
┌──────────────────┐
│  Web Dashboard    │◄── HTMX polling
│  (FastAPI+Jinja2) │
└──────────────────┘

Caching and efficiency

Grimoire is designed to be friendly to the GitHub API rate limit:

  • Conditional requests: Uses ETags to avoid re-downloading unchanged data. After the initial fetch, most refreshes cost zero API calls.
  • per_page=100: Maximises data per request.
  • Batched GraphQL for PRs: The CI status of the pull requests that match a PR group is read with one GraphQL request per 20 PRs, from a rate-limit bucket separate from REST. The PRs themselves come from the pull request lists that are fetched anyway.
  • Bounded concurrency: A semaphore limits parallel API calls to 10.
  • SQLite persistence: On restart, cached data is loaded immediately. The dashboard is usable before the first refresh completes.

Scheduling

Grimoire uses APScheduler (v3) with cron triggers:

  • The global refresh_schedule controls how often repo data is fetched and default checks run.
  • Checks and actions can override this with their own schedule field.
  • Everything runs in-process — no external queue or worker needed.

Workspace management

Checks and actions run against cloned copies of your repositories:

  • Repos are cloned to workspace_dir on first use.
  • Before each check/action run, the workspace is reset to the target branch head (git fetch + git reset --hard).
  • Each check runs in an isolated temporary directory to avoid state leakage.

Database

Grimoire uses SQLite via aiosqlite + SQLModel. The database stores:

  • Cached GitHub data (repos, issues, PRs, workflow statuses)
  • Check and action results with full output logs
  • Toggle states (enabled/disabled per check/action)

The schema is migrated automatically at startup: a new database is created, and an existing one — including one from a release that predates migrations — is upgraded in place. Upgrading Grimoire never requires deleting grimoire.db; toggles, run history and the GitHub cache are kept.

Spaces

A space is a named slice of the tracked repositories, for example the repositories of one team. Several teams can then share one Grimoire, each looking at its own slice through the space selector in the navigation bar.

Spaces are a view filter, not isolation. There is one GitHub token, one git identity, one workspace, one database, one cache and one scheduler for everything. A repository that belongs to several spaces is fetched and cloned once. Display settings (staleness, backlog, dashboard, prs, refresh_schedule) are global.

  • Membership. Each source that lists a repository (the top-level repositories or a space) is one membership of that repository. Branches are merged across memberships, and each membership carries its own workflow filters. Repositories with no space are Unassigned.
  • Selection. The selector in the navigation bar picks any number of spaces. Selecting none, or every entry the selector lists (including Unassigned when it is offered), means All. The web pages keep the choice in the grimoire_spaces cookie for a year, and ?spaces= on a page applies and saves a choice. The JSON API reads only ?spaces= and never the cookie, so API results do not depend on who asks.
  • What it filters. The dashboard, backlog, checks, actions and PRs pages, and the matching APIs. It never changes what runs: a check or action's targets still decide its repositories, and spaces on a check or action only decides where it is listed.
  • Metrics. grimoire_repository_space_info{repo,space} carries the memberships; the other series are unchanged. See the metrics reference on GitHub.

Whoever can edit the configuration, a space file, or the check and action scripts can affect the whole instance. See Host Grimoire for several teams.

Security model

Trust boundary

Grimoire executes user-provided bash scripts with the same privileges as the Grimoire process. It is designed for self-hosted, trusted environments only.

  • No authentication is built in — use a reverse proxy for access control. Spaces do not restrict access: anyone who can open Grimoire can select any space.
  • The GitHub token has access to all configured repositories.
  • Actions can push commits, create PRs, and call gh CLI with the token.