Keep README architecture diagrams up to date in CI
Redraw the diagrams in your README from your code and configuration on every push, with flowgraph sync, on GitHub, GitLab, Bitbucket or Azure DevOps, and commit only the ones that changed.
An architecture diagram in a README is right on the day it's drawn. flowgraph sync keeps it right afterwards: on every push, your CI job redraws the diagrams you list from the repository's own files, renders the ones that changed, and commits them into the README. This guide sets it up from scratch.
Plan: Free, Pro and Pro Max. Each image rendered uses one API render from your monthly allowance (Free 50, with a small watermark; Pro 5,000; Pro Max 20,000), and an unchanged diagram uses none. Diagrams kept as Mermaid need no renders at all. Diagrams saved in your account (draw: saved and save-to:) need Pro or Pro Max.
How it works
flowchart LR
push[Push to main] --> job[Your CI job runs<br/>flowgraph sync]
job --> draw[Draw each diagram<br/>from the checkout]
draw --> changed{Changed?}
changed -->|no| done[Nothing to commit]
changed -->|yes| render[Render the image]
render --> commit[Commit the image<br/>and the README block]- Your code stays where it is. Sync runs on the code your CI checked out, so private repositories need no extra access. Only the Mermaid of a diagram that needs rendering is sent to Flowgraph Studio's API.
- The same commit gives the same diagram. Diagrams drawn from code and configuration use no AI, so a changed diagram means the system changed.
- Only what changed is rendered and committed. An unchanged diagram uses none of your monthly renders, and sync never commits files other than its own.
1. Create an API key
Sign in, open Account settings → Render API, and choose Create key. Store it as a secret in your CI system, named FLOWGRAPH_API_KEY. A free account works; its images carry a small watermark.
You can skip the key if every diagram is written as Mermaid (format: mmd): GitHub, GitLab and Azure DevOps draw Mermaid in a README themselves, so nothing needs rendering.
2. List the diagrams in flowgraph.yml
Add flowgraph.yml at the root of the repository. Each entry names a diagram and says what to draw:
diagrams:
architecture: map # the codebase map
services: compose # services from docker-compose.yml
data-model:
draw: sql # the ER diagram from your migrations
out: docs/data-model.png
checkout-flow:
draw: flow
file: src/orders.ts
function: Orders.place
format: mmd # kept as Mermaid: no key or render needed
draw |
Drawn from |
|---|---|
map, deps, routes, classes, calls, flow |
The code: a codebase map, module dependencies, routes, class diagrams, a call map, or one function's flowchart (TypeScript, JavaScript, Python, Java, Go and C#) |
compose, kubernetes, terraform, openapi, pipeline, sql, prisma, packages |
The repository's configuration: Docker Compose, Kubernetes manifests, Terraform, OpenAPI, CI pipelines, SQL or Prisma schemas, and workspaces |
saved |
A diagram saved in your Flowgraph Studio account (see below) |
Images go to docs/diagrams/<name>.svg unless out says otherwise. A top-level theme: (the file from Export → Theme JSON in the editor) styles them all. The flowgraph-cli README lists every setting.
3. Mark where each diagram goes
In README.md, put a pair of markers where each diagram should appear, named as in flowgraph.yml:
## Architecture
<!-- flowgraph:architecture -->
<!-- /flowgraph:architecture -->
Each sync replaces what is between the two lines, with a link to the image, or a Mermaid block for an mmd diagram, and leaves the rest of the README alone.
4. Run it locally first
FLOWGRAPH_API_KEY=fg_… npx --yes flowgraph-cli@0.3.0 sync
It writes the images, fills in the README and saves .flowgraph-sync.json, which remembers what it rendered. Run it again: with nothing changed, it renders nothing and changes nothing. Commit the result once, so the first CI run starts from it.
5. Add it to your CI
Each host has a ready-made integration. Every one commits with the message Update diagrams [skip ci], so the diagrams' own commit doesn't start another run.
GitHub Actions
# .github/workflows/diagrams.yml
name: Diagrams
on:
push:
branches: [main]
permissions:
contents: write
concurrency: diagrams
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: theorence-labs/flowgraph-sync-action@v1
with:
api-key: ${{ secrets.FLOWGRAPH_API_KEY }}
GitLab CI/CD
Turn on Settings → CI/CD → Job token permissions → Allow Git push requests to the repository, so the job can push with its own token (GitLab 18.4 or later, every plan). Then include the component:
# .gitlab-ci.yml
include:
- component: gitlab.com/flowgraph-studio/flowgraph-sync/sync@1.1.0
Bitbucket Pipelines
The pipe draws and commits; the step pushes, because Bitbucket's push credentials are only reachable from the step itself:
# bitbucket-pipelines.yml
pipelines:
branches:
main:
- step:
name: Diagrams
script:
- pipe: docker://theorencelabs/flowgraph-sync-pipe:1.1.0
variables:
FLOWGRAPH_API_KEY: $FLOWGRAPH_API_KEY
- git push origin "HEAD:$BITBUCKET_BRANCH"
Azure Pipelines
Allow <project> Build Service to Contribute to the repository (Project settings → Repositories → Security), and add FLOWGRAPH_API_KEY as a secret pipeline variable:
# azure-pipelines.yml
trigger:
branches:
include: [main]
pr: none
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
persistCredentials: true
- task: NodeTool@0
inputs:
versionSpec: 22.x
- script: npx --yes flowgraph-cli@0.3.0 sync --push
env:
FLOWGRAPH_API_KEY: $(FLOWGRAPH_API_KEY)
The next push draws every diagram and commits them. After that, a push commits only the diagrams that changed.
Diagrams drawn in Flowgraph Studio
Not every diagram can be read from code: a target architecture, or an overview you've arranged by hand. On Pro and Pro Max, sync works with diagrams saved in your account too. It needs a key with Read and change saved diagrams ticked when you create it.
Put a saved diagram in the README with draw: saved and its id. The id is in the editor's address (/editor?diagram=<id>), and npx flowgraph-cli diagrams lists them all:
diagrams:
target-architecture:
draw: saved
id: 5f2c9a7e
It's rendered with the theme it has in the app, so restyling it in the editor changes the README on the next sync:
Edits in the app don't start your CI, so also run the sync on a schedule. In GitHub Actions, add schedule: [{ cron: '0 6 * * *' }] under on:.
Keep a saved diagram in step with the code with save-to: on a diagram drawn from the repository. Sync puts the new drawing into the saved diagram and keeps its title, theme and the positions you gave nodes in Manual mode. Each change is a new entry in its version history, so Compare with current shows exactly what the code changed:
diagrams:
services:
draw: compose
save-to: 81b3d0c4
A changed diagram also shows Changed since review, if you review your diagrams.
In pull requests
flowgraph sync --check changes nothing and needs no key. It says which diagrams will change once the request is merged, and exits with status 1 if any will. Use it as an advisory check rather than one that blocks a merge: the job on main updates the diagrams anyway.
- GitHub: run the action with
mode: checkonpull_request. - GitLab: also include
gitlab.com/flowgraph-studio/flowgraph-sync/check@1.1.0, which only warns by default.
Sync never pushes from a pull or merge request's build, which is a merge of it into its target: --push refuses there.
Troubleshooting
| What you see | What to do |
|---|---|
needs rendering: set FLOWGRAPH_API_KEY |
Add the key as a secret and pass it to the step, or use format: mmd for that diagram |
| The push is refused on GitHub | Branch protection blocks direct pushes to main: allow GitHub Actions to push |
| The push is refused on GitLab | Turn on Allow Git push requests to the repository, or set FLOWGRAPH_PUSH_TOKEN to a token with the write_repository scope |
A pipe can't push from Bitbucket Pipelines |
Add the git push origin "HEAD:$BITBUCKET_BRANCH" line after the pipe |
| The push is refused on Azure DevOps | Allow the Build Service to Contribute, and keep persistCredentials: true |
--push doesn't run for a pull or merge request |
Run sync --check in pull requests, and push from main |
| A diagram keeps changing without code changes | Check that its files aren't generated during the build; sync leaves its own output out of what it draws |
To see a repository's diagrams before setting up sync, draw them in the app: the import uses the same generators.
More guides
- Edit Mermaid diagrams visually in VS CodeDrag, connect and restyle a Mermaid diagram on Flowgraph's canvas inside VS Code, and every change is written back into the .mmd file or Markdown block as ordinary code.
- Keep a diagram's style in its code with %% flowgraph-themeOne comment line keeps a Mermaid diagram's Flowgraph theme in the file, so it looks the same in your repository, in VS Code, from the CLI and through the render API.
- Preview Flowgraph diagrams in VS Code, with icons, layout and your themeInstall the Flowgraph Studio extension to preview Mermaid files and Markdown blocks in VS Code as Flowgraph draws them, see mistakes in plain words, and export SVG or PNG.