Skip to content

Architecture

Chuck edited this page Nov 30, 2026 · 5 revisions

Glint is deliberately small: one Express app, two API clients and no storage. This page explains how the pieces fit and why.


System context

flowchart LR
    subgraph net["Your network"]
        GL["GitLab<br/>(self-hosted)"]
        G["Glint<br/>webhook receiver<br/>:3000"]
    end
    A["Anthropic API<br/>(Claude)"]

    GL -- "POST /webhook<br/>MR and release events" --> G
    G -- "REST API v4<br/>read diffs, post notes,<br/>update releases" --> GL
    G -- "HTTPS<br/>prompt with changes" --> A
Loading

Only the call to the AI provider leaves your network. The diagrams show Anthropic, the default; with AI_PROVIDER=openai-compatible the same call goes to the server at OPENAI_BASE_URL instead, which can be a local model.


Repository layout

Glint/
├── webhook-receiver/          # The deployable service
│   ├── src/
│   │   ├── index.ts           # Entry point: load config, start server, handle SIGTERM
│   │   ├── app.ts             # Express app: JSON body + raw-body capture, mounts routes
│   │   ├── config.ts          # Reads and validates environment variables
│   │   ├── middleware/
│   │   │   └── validateSecret.ts   # Signing-token (HMAC) or secret-token auth
│   │   ├── routes/
│   │   │   ├── health.ts      # GET /health
│   │   │   └── webhook.ts     # POST /webhook: validation, 202, background processing
│   │   ├── services/
│   │   │   ├── gitlab.ts      # GitLab REST client (axios), private-CA trust
│   │   │   ├── ai.ts          # AiClient interface; picks the provider from AI_PROVIDER
│   │   │   ├── prompts.ts     # Prompts and truncation, shared by both providers
│   │   │   ├── claude.ts      # Anthropic SDK client
│   │   │   └── openaiCompatible.ts  # OpenAI-compatible client (axios)
│   │   ├── logger.ts          # pino logger (JSON lines, LOG_LEVEL)
│   │   ├── utils/
│   │   │   └── errors.ts      # Log-safe error descriptions
│   │   └── __tests__/         # Vitest unit tests
│   ├── Dockerfile             # Multi-stage build on node:22-alpine
│   └── .env.example
├── e2e-test/                  # End-to-end harness (never deployed)
│   └── src/
│       ├── index.ts           # Orchestrates mock GitLab + real receiver + real AI model
│       ├── mockGitlab.ts      # Fake GitLab API that serves fixtures and captures notes
│       └── fixtures/          # Sample webhook payload, MR details and diff
├── .github/workflows/         # GitHub Actions: ci.yml, release.yml
├── .gitlab-ci.yml             # Equivalent pipeline for self-hosted GitLab
├── .githooks/pre-commit       # gitleaks secret scan on staged changes
└── docker-compose.yml         # Example deployment

The receiver and the e2e harness are separate npm packages. The receiver contains no test scaffolding; the harness compiles and spawns it as a child process and talks to it over HTTP, exactly as GitLab would.


Merge request flow

sequenceDiagram
    participant GL as GitLab
    participant W as routes/webhook.ts
    participant GC as services/gitlab.ts
    participant CC as services/claude.ts
    participant A as Anthropic API

    GL->>W: POST /webhook (Merge Request Hook)
    Note over W: validateSecret → event → object_kind<br/>→ validate IDs → action open/reopen
    W-->>GL: 202 Accepted
    par in parallel
        W->>GC: getMRDetails()
        GC->>GL: GET merge_requests/:iid
    and
        W->>GC: getMRDiffs()
        GC->>GL: GET merge_requests/:iid/diffs
    end
    W->>CC: summarizeMR(details, diffs)
    CC->>A: messages.create
    A-->>CC: summary text
    W->>GC: postMRNote()
    GC->>GL: POST merge_requests/:iid/notes
Loading

Release flow

sequenceDiagram
    participant GL as GitLab
    participant W as routes/webhook.ts
    participant GC as services/gitlab.ts
    participant CC as services/claude.ts

    GL->>W: POST /webhook (Release Hook, action=create)
    W-->>GL: 202 Accepted
    W->>GC: getReleases() — find the previous release
    alt previous release found
        W->>GC: compareRefs(prev, tag) — commits + diffs
    else first release
        W->>GC: getTagCommits(tag) — commits only
    end
    W->>CC: generateReleaseNotes(...)
    W->>GC: updateRelease(tag, notes)
    GC->>GL: PUT releases/:tag
Loading

Design decisions

Respond first, work later

GitLab expects a webhook response within seconds and marks slow deliveries as failed. Fetching diffs and waiting for the AI model can take much longer, so the route sends 202 Accepted as soon as the request is validated and runs the rest in an async function. Errors in that function are caught and logged with describeError(); they can't reach the HTTP response, which has already been sent.

Consequence: there is no retry and no feedback to GitLab when background work fails. The log is the only record. Retries and a work queue are on the roadmap.

Raw body capture

HMAC signatures cover the exact bytes GitLab sent, not re-serialised JSON. app.ts passes a verify callback to express.json() that stores the raw buffer on the request for validateSecret.ts.

Two authentication modes

WEBHOOK_SIGNING_TOKEN wins when set; otherwise WEBHOOK_SECRET. The secret comparison hashes both values with SHA-256 first, so timingSafeEqual compares equal-length buffers and doesn't leak the secret's length.

Fetch, don't trust

Payloads only supply the project ID, MR IID or tag, and those are validated. MR content comes from the GitLab API with Glint's own token, so a forged or stale payload can't inject a different title or diff.

Bounded prompts

Diffs are cut at 20,000 characters (MAX_DIFF_CHARS) and commit logs at 15,000, with a note telling the model the input was truncated. This bounds cost and keeps requests well inside the model's context window. The trade-off is that very large MRs are summarised from their first files only.

Trusting a private CA without losing the public ones

Passing ca to a Node HTTPS agent replaces the default trust store. trustedCertificates() in gitlab.ts therefore combines Node's default certificates (including NODE_EXTRA_CA_CERTS on Node 22.15+) with the configured CA, and only for the GitLab client.

No state

No database, cache or queue. Each event is processed end to end and forgotten. Restarts are safe, horizontal scaling is trivial, and there's nothing to back up. The cost is no de-duplication and no history.

Fail fast

loadConfig() runs before the server binds a port. Missing variables, missing webhook authentication or an unreadable CA file stop the process with a clear message.

Clone this wiki locally