Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

structurizrx fmt

Print a workspace as canonical DSL: stable ordering and layout, a .json workspace converted to DSL, a sketch promoted to a full workspace { model { … } views { … } }.

structurizrx fmt <file> [--output <path>] [--write] [--check] [--force]
FlagEffect
--output, -oWrite the result to this file instead of stdout
--writeRewrite <file> in place
--checkExit 1 if the file isn’t already in canonical form (CI); no output written
--forceWith --write, overwrite even when comments or other things would be lost

--write and --check are mutually exclusive; --force requires --write.

Promoting a sketch

A sketch (bare arrows, no workspace block) formats into a full workspace, with placeholders declared as softwareSystems and a generated systemLandscape view:

structurizrx fmt sketch.dsl

Input (site/examples/sketch.dsl):

customer -> shop "buys things"
shop -> billing "somehow charges" ?
billing -> erp

Output:

workspace "Sketch" {

    model {
        customer = softwareSystem "customer" "" "Placeholder"
        shop = softwareSystem "shop" "" "Placeholder"
        billing = softwareSystem "billing" "" "Placeholder"
        erp = softwareSystem "erp" "" "Placeholder"
        customer -> shop "buys things"
        shop -> billing "somehow charges" ?
        billing -> erp
    }

    views {
        systemLandscape "sketch" {
            include billing customer erp shop
        }
    }
}

Converting JSON to DSL

fmt accepts .json workspaces too — useful for round-tripping a workspace exported by export, or one produced by other Structurizr tooling, back into readable DSL:

structurizrx export shop.dsl --output shop.json
structurizrx fmt shop.json
workspace "Shop" {

    model {
        customer = person "Customer"
        shop = softwareSystem "Shop" {
            webApp = container "Web App" "Storefront" "TypeScript"
            api = container "API" "Handles requests" "Rust" {
                status implemented
                port customerRestApi "Customer REST API" {
                    protocol "HTTPS/JSON"
                }
            }
            database = container "Database" "Stores data" "PostgreSQL" "Database"
            webApp -> api.customerRestApi "calls"
            api -> database "reads and writes" {
                kind sync
            }
        }
        customer -> webApp "shops on"
    }
    ...
}

--write and what it refuses to lose

fmt doesn’t preserve comments, so --write (and --check, implicitly) refuses to overwrite a file that has any, or that uses !include, !docs/!adrs, constants (!const/!var), or specification kind aliases — anything the canonical rewrite would drop or normalize away:

structurizrx fmt commented.dsl --write
Error: not rewriting commented.dsl because comments are not preserved.
Use --output to write elsewhere, or --force to accept the loss.
structurizrx fmt commented.dsl --write --force
formatted commented.dsl

CI: enforce canonical form

structurizrx fmt ws.dsl --check
ws.dsl is not in canonical form (run `structurizrx fmt --write`)

Exits 0 silently when the file is already canonical.