Skip to content

Architecture

Lionel Serrao edited this page Nov 29, 2026 · 2 revisions

Architecture

A tour of the code for anyone who wants to change it. Everything lives in extension/src. It's plain TypeScript with no runtime dependencies: it talks to Flagsmith with fetch.

The pieces

flowchart TB
    subgraph VSCode["Inside VS Code"]
        EXT["extension.ts<br/>commands, dialogs, notifications"]
        ED["editor.ts<br/>code lenses, hovers, warnings, quick fixes"]
        VW["views.ts<br/>Flags and Code audit sidebars"]
        ST["store.ts<br/>state, polling, incidents, restore records"]
        US["usage.ts<br/>where each flag is read in the workspace"]
        LOC["local.ts<br/>start a local Flagsmith with Docker"]
    end
    subgraph Pure["No VS Code (unit tested, reused by the CLI and e2e)"]
        OPS["incidentOps.ts<br/>kill switch + restore"]
        API["api.ts<br/>Flagsmith client"]
        SC["scanner.ts<br/>finds flag keys in code"]
        REP["report.ts<br/>code vs Flagsmith"]
        INC["incident.ts<br/>who's still on, incident summary"]
        AR["alertRule.ts<br/>Prometheus rule + receiver"]
        TM["timing.ts<br/>flag change vs alert time"]
        MD["markdown.ts<br/>safe hover text"]
        CR["coderefs.ts / gitInfo.ts / gitUrl.ts<br/>code references, permalinks"]
    end
    CLI["cli.ts<br/>scan / check / publish-refs"]
    FS[("Flagsmith<br/>self-hosted")]

    EXT --> ST
    ED --> ST
    VW --> ST
    ED --> US
    US --> SC
    ST --> OPS
    ST --> API
    OPS --> API
    EXT --> INC
    EXT --> AR
    ED --> MD
    CLI --> SC
    CLI --> REP
    CLI --> API
    API --> FS
Loading

The split is deliberate. Anything that decides or talks to Flagsmith sits in the "no VS Code" half, so it runs under node --test and in the CLI, and the live tests exercise the exact code users run.

One refresh, step by step

store.ts refreshes every flaglens.pollSeconds (15 by default), and after every change you make:

sequenceDiagram
    participant S as store.ts
    participant F as Flagsmith
    S->>F: features, tags, environments, Feature Health events (in parallel)
    S->>F: per environment: default states + override counts
    S->>F: per environment: A/B tests, and results for running ones
    Note over S: newest health event per flag and environment
    S->>F: for flags with an open alert: every state + segment links (who is still on?)
    Note over S: new UNHEALTHY → incident, new HEALTHY → offer restore
    S-->>S: fire change event → lenses, hovers, sidebars, status bar redraw
Loading

Errors in optional parts (tags, experiments, results) don't stop a refresh. If the refresh itself fails, the status bar shows a warning and the last good data stays on screen.

Where state lives

What Where
API key VS Code secret storage (OS keychain)
Flagsmith URL and chosen project (the saved connection) VS Code global state, so every window reconnects
Restore records ("what the kill switch turned off") VS Code workspace state, key flaglens.restorePlans
Last "Check a user" input VS Code workspace state
Flags, states, events, tests Memory, rebuilt on each refresh

Hovers are trusted Markdown, so text is escaped

Hovers contain command links (toggle, kill switch, check a user), so VS Code has to trust them. Flag names, values, environment names and alert text come from Flagsmith, and alert text comes from whoever can call the webhook. markdown.ts escapes all of it, so that text can never become a command link. It has its own tests.

Adding a feature: a typical path

  1. Add the Flagsmith call to api.ts (and a unit test with a scripted fetch in test/api.test.ts).
  2. If it decides something, put that logic in a pure module and test it.
  3. Wire it into store.ts (data) and editor.ts / extension.ts (UI).
  4. Add a live case to demo-app/e2e.mjs if it writes to Flagsmith.
  5. npm test, then npm run package and install the .vsix.

Clone this wiki locally