Skip to main content

c4studio

Python implementation of Structurizr for architecture modeling and C4 diagram generation.

Install

Published on PyPI as c4studio; the import package is c4studio and the command is c4:

pipx install c4studio          # or: pip install c4studio
c4 webapp my-architecture.dsl

# or run without installing:
uvx --from c4studio c4 webapp my-architecture.dsl

Requires Python 3.13+ (uv/uvx can provision it automatically).

Quick Start

from c4studio.models import Workspace, Person, SoftwareSystem, Container, Relationship, View, ViewType

# Create workspace
ws = Workspace(
    name="My Architecture",
    description="System architecture model"
)

# Define people and systems
user = Person(id="user", name="User")
system = SoftwareSystem(id="sys", name="System")
ws.people.append(user)
ws.software_systems.append(system)

# Add relationship
rel = Relationship(
    source_id="user",
    destination_id="sys",
    description="Uses"
)
ws.relationships.append(rel)

# Create view
view = View(type=ViewType.SYSTEM_CONTEXT, key="context")
ws.views.append(view)

Documentation

Features

  • ✅ Full Structurizr metamodel support (C4 architecture model)
  • ✅ DSL and JSON parsing
  • ✅ Mermaid diagram generation — C4 syntax or flowchart/subgraph
  • ✅ Comprehensive type hints
  • ✅ Custom properties and perspectives on all elements
  • ✅ Deployment infrastructure modeling
  • ✅ Style and configuration management

Parsing

Parse Structurizr DSL or JSON files:

from c4studio.parser.dsl import parse_dsl_file
from c4studio.parser.json_parser import parse_json_file

# Parse DSL
ws = parse_dsl_file("architecture.dsl")

# Parse JSON
ws = parse_json_file("workspace.json")

Diagram Generation

Two Mermaid targets, both rendering from the same view graph — so what they show matches the web app's view semantics exactly:

Target Syntax Covers
MermaidGenerator C4Context / C4Container / C4Component system landscape, system context, container, component views
FlowchartGenerator flowchart + subgraph all of the above plus dynamic, deployment and filtered views

Mermaid's C4 diagram types are experimental upstream and lay out poorly on dense models, and GitHub pins its own Mermaid version — so prefer the flowchart target for anything rendered on GitHub or in a wiki.

from c4studio.generators import FlowchartGenerator, MermaidGenerator

for view_name, mermaid_code in MermaidGenerator(ws).generate_all().items():
    print(f"{view_name}:\n{mermaid_code}\n")

# Or the flowchart target, which renders every view type:
diagrams = FlowchartGenerator(ws).generate_all()

From the CLI:

uv run c4 generate architecture.dsl                     # C4 (default)
uv run c4 generate architecture.dsl -f flowchart        # flowchart
uv run c4 generate architecture.dsl -f flowchart -o out # one .mmd per view

Headless SVG Rendering

c4 render draws diagrams as standalone SVG with no browser and no server — for CI, docs-as-code pipelines and static sites. Layout is the same code the web app runs, so positions match what you see in the viewer, including any layout you have saved for a view.

uv run c4 render architecture.dsl -o diagrams/   # one .svg per view
uv run c4 render architecture.dsl -v Containers  # one view to stdout

Each diagram carries its own title and a legend of the styles it actually uses, so an exported file explains itself to someone who did not build it. Pass --no-title or --no-legend to leave either out.

The output is self-contained: no external fonts or stylesheets, and theme icons (the AWS/Azure/GCP service logos) are fetched once and embedded as data: URIs, so a file renders identically wherever it is opened — even offline. An icon that cannot be fetched is simply left out.

This is the only command that needs Node.js 18+ (the renderer is bundled into the wheel, so there is no npm install). Set C4STUDIO_NODE if node is not on your PATH. Parsing, Mermaid generation, JSON export and the web app all work without it.

GitHub Action

Render the diagrams on every push and pull request, so reviewers see the architecture change alongside the code change:

name: Diagrams
on: [push, pull_request]

jobs:
  render:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: geoffkoh/c4studio@v0.2.0
        id: diagrams
        with:
          workspace: docs/architecture.dsl
      - uses: actions/upload-artifact@v4
        with:
          name: diagrams
          path: ${{ steps.diagrams.outputs.diagrams-path }}
Input Default What it does
workspace required The .dsl or .json file to render
output diagrams Directory for the SVGs, one per view
view (all) Render a single view key
mode render render, commit (push the files back when they change) or comment (comment on the PR)
version c4studio pip requirement to install; local uses the checkout
python-version 3.13 Python to set up first — runners still default to an older one than this package needs. Empty string skips the step

The action checks the workspace before rendering, so a parse error fails the job with diagnostics rather than a traceback, and sets a changed output. Because rendering is deterministic, mode: commit produces no diff when the model has not changed.

Workspace JSON Export

Export any workspace (DSL or JSON) back to Structurizr workspace JSON, round-tripping with structurizr.com, Structurizr Lite, and this package's own parser:

uv run c4 export workspace.dsl -o workspace.json

Or programmatically via c4studio.generators.json_export.export_json.

VS Code Extension

editors/vscode/ ships a VS Code extension with Structurizr DSL syntax highlighting and an in-editor C4 diagram preview (the full web app in a side panel, live-reloading as you save). Build and install it locally:

cd editors/vscode && npm install && npm run package
code --install-extension c4studio-vscode-*.vsix

React Web App

A React (Vite + TypeScript) single-page app, served by a FastAPI backend and launched from the CLI, for loading DSL/JSON files from disk and exploring each view as an interactive React Flow graph (draggable nodes, pan/zoom, minimap).

uv run c4 webapp samples/          # browse a directory
uv run c4 webapp file.dsl          # preload a single file
# → opens http://127.0.0.1:8090 (use --no-browser to skip, --port to change)

Select several nodes (Shift+drag, or ⌘/Ctrl+click) to align or distribute them from the toolbar that appears, and nudge a selection with the arrow keys — 10px with Shift. Everything persists to the layout sidecar.

Pass a directory to browse and load any .dsl/.json file from the in-app file picker, or a single file to preload it. The element tree and per-view graph come from the parser and graph/view_graph; systemLandscape, systemContext, container, component, dynamic and deployment views all render as interactive graphs (other view types are flagged "not renderable yet").

The Explorer tab renders the entire static model as one graph — independent of any curated view — at a selectable abstraction level (systems / containers / components), with search across every element (press /), and a details panel showing an element's metadata, relationships, the views it appears in (click to jump) and a show-definition link into the Source pane.

The built SPA ships inside the package (c4studio/webapp/static/), so end users need no Node toolchain. To rebuild the frontend after changes (requires Node 18+):

The frontend is an npm workspace: packages/diagram-core holds the diagram layer (layout, node/edge components, image export) and frontend/ is the SPA that consumes it, so build from the repo root.

npm install
npm run build          # diagram-core, then the SPA
                       # outputs to src/c4studio/webapp/static/
# dev loop: `npm run dev --workspace c4studio-frontend`
#           (Vite :5173, proxies /api → :8090) alongside
#           `uv run c4 webapp samples/ --no-browser`

Security: the web app has no authentication and is intended for local use on 127.0.0.1.

Tests

uv run pytest                      # full suite
uv run pytest tests/test_webapp    # web app tests only

Metadata

Release files for c4studio 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for c4studio 0.2.0
File Size Uploaded Provenance Actions
c4studio-0.2.0.tar.gz 310.3 kB Without provenance Details for c4studio-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for c4studio 0.2.0
File Interpreter ABI Platform Actions
c4studio-0.2.0-py3-none-any.whl Python 3 none any Details for c4studio-0.2.0-py3-none-any.whl

Total release size: 637.2 kB

Release files / c4studio-0.2.0.tar.gz

Download URL c4studio-0.2.0.tar.gz
Size 310.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cea437a4b5962bb198e8666d17863fc9f80ce7ac37b31e91dd05a059d5c1b884
BLAKE2b-256 checksum
How to use checksums
1ffcc0243fdcfdb2f4da704ed59d772efc03b5057d757fcca00636bf81a3406e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / c4studio-0.2.0-py3-none-any.whl

Download URL c4studio-0.2.0-py3-none-any.whl
Size 326.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b5f4c8ab5a5639ba3cf55898cb0c589ef028a564685e3871b57a94a9e3c2336
BLAKE2b-256 checksum
How to use checksums
f8462ff052b3aabff7aea7c42da183096370db29c686e16e4f0a369725fddb81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for c4studio 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page