# Turn a system into an InfraCity city

You are given a description of a system. Most often it is real infrastructure: Docker Compose files, Kubernetes manifests, Terraform, a diagram, an inventory or plain words. It may also be something that is not servers at all: a process, a supply chain, a work flow, how an operating system works. Turn it into **CityScript**, the short text format that InfraCity draws as a town. A place becomes a building, the parts of it floors, what is there or done in them rooms, and what passes between them becomes lines along the streets. For servers: hosts become buildings, the stacks on them floors, their services rooms, and what calls what the lines.

The result is a design. It draws with no connection to the real systems; the optional bindings (`host=`, `project=`, `service=`), which only servers have, name the real things so the same city can show live health later.

## What becomes what

| In the infrastructure | In the city | Written as |
|---|---|---|
| A group that belongs together: an environment, a network zone, a tier, a cluster, a region | A district: a named lawn that buildings stand on | `district <id> "Name" x1,y1..x2,y2` |
| A place where things run: a host, a VM, a node group, a namespace, a managed service | A building | `building <id> <type> in <district> "Name"` |
| A stack in that place: a Compose project, an application, a release | A floor of the building | `floor <id> "Label"` |
| One running thing: a service, a container, a process, a database, a queue, a job | A room on that floor, of one kind | `room <id> <kind> "Label" port=<n>` |
| The port a running thing listens on | The port of its room: its own place on the front wall, where links to it arrive | `port=5432`, or `port=4317,4318` |
| A password, key or token it holds, by its name | A padlock on the room; whatever keeps data has one even when no name is given | `secret=POSTGRES_PASSWORD` |
| What it costs each month: an instance, a managed database, a licence, a seat | A monthly cost on the room, added up on the cards of its building, district, level and boundary and for the whole city. Only if you know it: leave it out otherwise, and never guess | `cost=120` or `cost=19.99`, and `currency=EUR` on the `city` line (USD if it says none) |
| A zone of trust inside which things may talk freely: a DMZ, a VPC, a security group, a data network | A boundary: a dashed outline round the buildings inside it, and round smaller boundaries. A district is the map (where things stand); a boundary is trust (who may talk freely), so a building can be in both | `boundary <id> "Name" members=<building>,<building>` |
| A tier or layer of the whole, when there are many areas: the way in, the network, the data, delivery, observability | A level: one big area, with its own name and colour, that groups those districts so that the city can be read from far away. Use it for a big city, not a small one | `level <id> "Name" members=<district>,<district>` |
| A public way in: a domain, a published port | A gate | `gate <id> port=443 "name"` |
| A calls, reads from or depends on B | A link from the room of A to the room of B | `link <room> -> <room>` |
| Something that moves through places in order: a release, a request, a backup | A pipeline: a flow with a stage for each step | `pipeline <id> "Name" <place> -> [stage] -> <place>` |
| What a step of that flow runs: the commands of a CI job, a deploy script | The script of the stage, shown where the flow is read | `run <stage> "<command>"` under the pipeline |
| What happens at each place of that flow, as you would tell someone new | The words of each step, read when someone follows the flow | `step <place> "<words>"` under the pipeline |

## Method

1. **List what runs.** Every service, database, queue, job and proxy in the input, and where each one runs. Only what the input shows: do not add components because systems like this usually have them.
2. **Make the buildings.** One for each place things run: a host, a node group, a namespace, a managed service. When the input names services but no hosts (one Compose file, a diagram of boxes), group the services by role instead (edge, application, data, messaging, operations), one building for each role that has members, and say so in a comment.
3. **Fill them.** Every building gets at least one floor with at least one room: a link can only join rooms, and a building with no floor is drawn as an empty lot. One room for each running thing, of the kind the table below gives.
4. **Give each room its port.** `port=` is the port that service itself listens on: 5432 for the database, 6379 for the cache, 8080 for the API. Take it from the input. When the input names the software but not the port, use the port that software listens on by default and say so in a comment. Leave it out for what listens on nothing, such as a worker, and when you cannot tell.
5. **Mark what holds secrets.** A database, a cache, a queue and storage always hold a password or a key, so they are drawn with a padlock without being told. When the input names a secret (an environment variable such as `POSTGRES_PASSWORD`, an entry under `secrets:`, a reference to a secret store), write the name on the room that holds it: `secret=POSTGRES_PASSWORD`. The name only, never the value.
6. **Group the buildings into districts.** Use the grouping the input already has: environments, network zones, tiers, clusters, regions. Two to seven districts read well; with more than eight districts, group them into `level`s so the city can be read from far away. Put what everything uses (operations, CI/CD, backup) in a district of its own: the recipe gives it a second row. Every building stands in exactly one district.
7. **Add the ways in.** One gate for each public entry, a domain or a published port, with its port. The gate's port is the public one; it is not the port of the services behind it.
8. **Connect.** One `link` for each dependency, from the caller to what it calls. Use only dependencies the input shows: a `depends_on`, the name of another service in the configuration, an arrow in the diagram, a rule that allows traffic. When the input says what passes, label the link with it (`link api -> db "SQL"`, `"HTTPS"`, `"events"`), and mark a guarded crossing `variant=security` and an asynchronous or occasional one `variant=dashed`; never invent a label. What many things use or watch (monitoring, backup, CI) is not linked to every room: draw one `variant=dashed` link for each district it reaches, to the one room that stands for it there, as in `link prometheus -> api "scrape" variant=dashed`.
9. **Draw the flows.** Whatever passes through several places in order (a release, the path of a request, a backup) is a `pipeline`. Draw the few flows that matter: a handful of flows reads well, twenty is a tangle. CI/CD is always a pipeline and never a building: the Git server and the registry are buildings, the build is the flow between them. When the input shows what a stage runs, give the stage its script: one `run <stage> "<command>"` line under the pipeline for each command, in order. Then say what happens at each place in plain words, with one `step <place> "<words>"` line for each, written for someone who does not know the system (a product manager, a new colleague): `step orders "The order is checked and saved"`, not `step orders "POST /orders"`. Whoever opens the city then walks the flow: a card lists its places as numbered steps and the camera of the map travels along the line from one step to the next. So write each flow as one line that can be followed. List its places in the order the thing really goes, one after another, with no skipping and no going back and forth. Put a link between each two places that follow each other (`infracity check` points at a hop that has none). Name each stage as what happens between the two places. Keep it to one story, twelve places at most, and split a longer one into two flows. And set the districts the flow passes through next to each other in the layout, so that every hop is short.
10. **Bind when the real names are known.** `host=`, `project=` and `service=` take the exact names. Leave a binding out when you do not know the name.
11. **Lay it out** with the recipe below. Do the sums; do not guess positions.
12. **Check** against the list at the end before you answer.

## Which type, which kind

The building type only changes how a building looks:

- `tower`: a way in or a control point: a gateway, a load balancer, DNS, a scheduler, a vault, a Git server
- `factory`: where application code runs
- `warehouse`: where data is kept: databases, brokers, object storage, registries
- `depot`: something small at the edge: a cache node, a CDN location, a bastion, a probe

The room kind is the colour of the room, and what a reader sees first:

- `service`: application code that answers requests: an API, a web app, a function
- `database`: a system of record: Postgres, MySQL, MongoDB, DynamoDB
- `cache`: Redis, Memcached, a CDN or shield cache
- `worker`: anything that works without being called: a queue consumer, a cron job, a scheduler, an agent, an exporter
- `config`: configuration and secrets as a service: Vault, Consul, etcd, a config server, DNS zones, certificates
- `queue`: a broker, a topic or a stream: RabbitMQ, Kafka, NATS, SQS, Pub/Sub
- `proxy`: what stands in front: nginx, Traefik, HAProxy, Envoy, an ingress, a load balancer, a WAF
- `storage`: files and blobs: S3, MinIO, an image registry, a search index, a log or metrics store

When nothing here fits, because the input is not servers at all, read it with the section **From A process or a supply chain** below and ask for a pack that has the words (`packs=<name>`, listed under the catalog) or write a `pack` of your own in the city: its `buildingtype` and `roomkind` lines are described in the language below, and an AI should give each kind a short shape that paints at least one part `$state`.

## From Docker Compose

| In the input | In the city | Written as |
|---|---|---|
| The machine a Compose project runs on | A `building` | `host=<hostname>` |
| The Compose project (its `name:`, or the directory it is in) | A `floor` of that building | `project=<project name>` |
| Each entry under `services:` | A `room`; the kind comes from its image | `service=<service name>` |
| `ports:`, `expose:`, or the port in a URL that reaches the service | The port of its `room`: the container port, not the host port | `port=<container port>` |
| `secrets:`, `env_file:`, and environment variables named like a password, key or token | The names of the secrets its `room` holds, never the values | `secret=<NAME>` |
| `ports:` published to the outside | A `gate`, and the room behind it is usually a `proxy` | `port=<host port>` |
| `depends_on:`, and another service's name in an environment URL | A `link` from the service to what it needs | `link <room> -> <room>` |
| `networks:` that keep tiers apart, or one file per environment | A `district` for each | `in <district>` |

- Volumes, configs, secrets, healthchecks and replica counts are not drawn. Do not make rooms for them.
- When there is one Compose file and no word about hosts, group the services by role into buildings (edge, application, data, messaging, operations) and leave `host=` out.

## From Kubernetes

| In the input | In the city | Written as |
|---|---|---|
| A cluster, or an environment that has its own cluster | A `district` | one per cluster |
| A namespace (or a node pool, when the question is about nodes) | A `building` | named after the namespace |
| An application: a Helm release, an `app.kubernetes.io/name` | A `floor` | one per application |
| A Deployment, StatefulSet or DaemonSet | A `room`; the kind comes from its image | named after the workload |
| A `containerPort`, or the `targetPort` of the Service in front of the workload | The port of its `room` | `port=<port>` |
| A `secretKeyRef`, an `envFrom` a Secret, a mounted Secret | The names of the secrets its `room` holds, never the values | `secret=<key name>` |
| A CronJob or Job | A `room` of kind `worker` | named after the job |
| An Ingress, a Gateway, a Service of type LoadBalancer | A `gate`, and the ingress controller is a `proxy` room | `port=443` |
| Another Service's DNS name in the configuration, a NetworkPolicy that allows traffic | A `link` | `link <room> -> <room>` |
| Argo CD, Flux, a CI pipeline that deploys | A `pipeline` from the Git server to the namespace | `pipeline ...` |

- ConfigMaps, Secrets, Services of type ClusterIP, PVCs and replica counts are not drawn.
- A database or queue run by the cloud and not in the cluster is a building of its own, in a district such as Managed services.
- Kubernetes cannot be shown live yet: write no `host=`, `project=` or `service=`.

## From Terraform or a cloud account

| In the input | In the city | Written as |
|---|---|---|
| An account, a region, a VPC; or its public, private and isolated subnets | A `district` for each | the way in first, data last |
| A VPC, a subnet, a security group or a firewall zone, as a zone of trust: what sits inside trusts itself | A `boundary` round the buildings in it, which may sit inside a larger one | `boundary <id> "Name" members=<building>,<building>` |
| An instance, an auto-scaling group, a container service, a set of functions | A `building` of type `factory`, with a `room` for each container or function | `host=<instance name>` if it is one machine |
| A managed database, cache, queue, stream or bucket | A `building` of type `warehouse` with one `room` of the matching kind | kinds `database`, `cache`, `queue`, `storage` |
| A load balancer, an API gateway, a CDN | A `building` of type `tower` with a `proxy` room, and a `gate` for its public listener | `port=443` |
| The port of a listener, a target group, a container or a database endpoint | The port of its `room` | `port=<port>` |
| A password argument, a `sensitive` variable, an entry in a secrets manager that a resource reads | The names of the secrets its `room` holds, never the values | `secret=<name>` |
| A secrets manager, a parameter store, a DNS zone | A `room` of kind `config` | in a `tower` |
| A security group rule or a policy that lets one thing reach another | A `link` | `link <room> -> <room>` |
| A deploy pipeline | A `pipeline` | `pipeline ...` |

- IAM roles, route tables, NAT and internet gateways, log groups and alarms are not drawn unless the question is about them.
- Leave out ARNs, account numbers and IP addresses.

## From A CI/CD pipeline file

| In the input | In the city | Written as |
|---|---|---|
| A workflow or a pipeline | A `pipeline`, named as it is named there | `pipeline <id> "Name" ...` |
| The repository it is triggered from | The place it starts: a `building` of type `tower` for the Git server | the first place of the pipeline |
| A job, a stage or a step, in the order it runs | A stage of the pipeline | `[build] -> [test]` |
| The `run:` or `script:` lines of a job | The script of that stage, one line for each command | `run <stage> "<command>"` |
| A registry it pushes to, an environment or a host it deploys to | A place on the way, or the place it ends: the `building` or `district` that is that target | `-> registry -> [deploy] -> prod` |
| `secrets.NAME`, a masked or protected variable | Written by name inside a command, and on the `room` that holds it when there is one | `$NAME` in a command; `secret=<NAME>` on a room |

- A pipeline needs a place to start and a place to end. When the file does not say where it deploys, end it at the registry or the artifact store it publishes to, and say so in a comment.
- Leave out set-up steps that say nothing about the system: checking out the code, caching, installing a runtime.
- Use single quotes inside a command, and never write the value of a secret: `$NAME` stands for it.

## From A diagram or a description

| In the input | In the city | Written as |
|---|---|---|
| A box drawn around other boxes: a boundary, a subgraph, a swimlane | A `district` | named as in the diagram |
| A box | A `building` with one `floor` and one `room`, so that it can be linked | the `room` kind from the box's shape or name |
| A box plainly inside a host or a server | A `room` of that host's building | one `room` each |
| An arrow | A `link`, from the tail of the arrow to its head | `link <room> -> <room>` |
| A port written on an arrow or in a box (`:5432`, `HTTPS 443`) | The port of the `room` the arrow points at | `port=<port>` |
| A key or padlock drawn on a box, or the word credentials, password or token beside it | The name of the secret its `room` holds | `secret=<name>` |
| Numbered steps, or a sequence that passes through several boxes | A `pipeline`, with a stage named after each verb | `pipeline ...` |
| A user, a browser, the internet | A `gate` | `port=443` if it is the web |

- A cylinder is a `database`, a queue shape is a `queue`, a cloud shape is usually a `proxy` or a `gate`.
- When the description is vague, draw less: what is not said is not drawn.

## From A process or a supply chain

| In the input | In the city | Written as |
|---|---|---|
| A place where work happens or things are kept: a warehouse, a team, a program | A `building` | `building <id> <type> in <district>`, the type from a pack |
| A part of that place: a line, a desk, a layer | A `floor` of that building | `floor <id> "Name"` |
| What is there or what is done: a shelf, a form, a scanner, a driver | A `room` on that floor, of a kind from a pack | `room <id> <kind> "Name"` |
| A group of places that belong together: a depot network, a department, a region | A `district` | named as the input names it |
| Whose hands a thing is in, who may see it, what runs with full privilege | A `boundary` round the buildings | `boundary <id> "Name" members=...`, and `variant=security` on every link that crosses it |
| What passes between two parts | A `link`, from the giver to the taker | `link <room> -> <room> "what passes"` |
| The journey of one thing from start to end, step by step | A `pipeline`, with a stage named after each verb | `pipeline <id> "Name" <place> -> [step] -> <place>` |
| Where it comes in from outside: a customer, an order | A `gate` | `gate <id> "Name"` and a `road` to the first building, with no port |

- Ask for the pack that has the words (`packs=logistics` for goods on the move, `packs=workflow` for work between people, `packs=os` for layers of software), or write a `pack` of your own in the city when none fits.
- Leave out `port=`, `secret=` and `host=`: they belong to servers, and the kinds of a pack hold no secrets.
- Draw what the input says happens: a step it does not mention is not drawn.

## Layout recipe

1. Every building stands in a district and is placed with `in <district>`. Never write `at`.
2. Size each district for its buildings. For n buildings: columns = the smaller of n and 4, rows = n ÷ 4 rounded up. Width = 6 × columns + 1. Depth = 5 × rows + 1. A district with no buildings is 7 wide and 6 deep.
3. Sort the districts into two kinds. **Flow districts** are what a request, a message or a release passes through: the way in, the applications, the data, the messaging. **Shared districts** are what many of the others call or watch: operations and monitoring, CI/CD and delivery, backup, identity. When unsure, a district that would link to most of the others is shared.
4. Put the flow districts in a row from left to right, in the order things flow: the way in first, data last. Two districts with a link or a flow between them stand next to each other: a road is as long as the ground between its two ends, so one that only talks to the first district is never at the far end of the row. The first starts at x = 4, y = 4. Each next one starts 3 tiles after the one before it ends. When a district would end beyond x = 70, start a new row of districts at x = 4, 3 tiles below the deepest district so far.
5. Put the shared districts in a second row, 3 tiles below the deepest flow district (y = its y2 + 3), side by side 3 tiles apart, wrapping the same way. Centre the row under the flow row: its first district starts at x = 4 + (the flow row's largest x2 − 4 − the width of the whole second row) ÷ 2, rounded down, and never less than 4. This gives the links that everything shares streets of their own, instead of running them along the flow. The shared district that most of the others link to goes in the middle of the second row, and the others on either side of it, under what they are joined to. With no shared district there is no second row.
6. When districts are grouped into `level`s, the same holds for the levels: they follow one another in the order things flow, and a level that the others all use (operations, security, what watches the rest) stands between the levels it is joined to, never at the far end, where every one of its links would run the length of the city.
7. A district is written `x1,y1..x2,y2` with x2 = x1 + width and y2 = y1 + depth.
8. The city is `city <W>x<H>` with W = the largest x2 + 4 and H = the largest y2 + 12. The bottom rows are reserved, which is what the 12 is for.
9. A gate takes no position: gates line up on the left edge. Add one `road <gate> -> <building>` from each gate to the building it leads to.
10. If you can run commands in the InfraCity repository, have the districts seated for you when you are done: `pnpm infracity tidy city.city -o city.city` moves the districts so that what is joined stands near and the roads come out shorter, and says how much shorter. It keeps what already reads left to right, changes no name, and leaves a city alone that it cannot make better.
11. If you can run commands in the InfraCity repository, check the design too: `pnpm infracity check city.city` says what looks wrong, whatever the city is about (a sales process, an approval, an operator's console, a workflow of any kind, an infrastructure). A **mistake** is a link into a boundary that is not marked as guarded: mark it `variant=security`, or move the building. A **look** is a pattern that is often a slip and may be meant: a flow with a step no link leads to, a building many rely on that nothing else of its kind could take over from, a building nothing uses. Fix it when it is a slip, and leave it when it is on purpose. `--strict` makes the command fail on a mistake.

## Names and values

- Ids are unique across the whole city: districts, buildings, floors, rooms, gates and pipelines share one set of names. Build them from the real names so they cannot clash: building `app-1`, its floor `app-1.shop`, the rooms on it `app-1.shop.api` and `app-1.shop.worker`.
- Use only lower-case letters, digits, `-`, `_` and `.` in ids. The name in quotes after an id is what is shown, and can be anything.
- Never copy values: no passwords, secrets, tokens, connection strings, account numbers or private addresses. Names only. `secret=` takes the name of a secret and refuses anything that looks like a value.

## Showing it live

When a person connects the city to a hub, each building, floor and room lights up with the real health of what it is bound to. It only lights up when the names match what the hub's agent reports, so take them from the input:

- `host=` on a building is the host name the agent was given: `INFRACITY_HOST_NAME`, or `--name` with `pnpm live`. Hosts can be picked by label instead, as in `host=label:env=prod`, when the agent was given `--label env=prod`.
- `project=` on a floor is the Docker Compose project name, as `docker compose ls` shows it. By default it is the name of the folder the Compose file is in.
- `service=` on a room is the Compose service name: the key under `services:` in the file, not the container name.

When the input does not say what a host or a project is called, leave the binding out and say so in a comment: do not guess a name. A room with no binding still draws; it only waits for one.

You cannot connect the city to a hub yourself. If you can run commands in the InfraCity repository, you can start one for the person: `pnpm live <compose project>` starts a hub and an agent on this machine and prints an address and a view token. Give both to the person to enter under **Connect to hub** in the editor. Never write the token into the city, and never type it into a web page yourself. How a person connects, and what the browser asks them to allow, is at `/guide/live/`.

## The language

The whole of CityScript, for reference. A conversion needs no `zone` (zones grow buildings from live hosts) and no `prop` (trees are drawn without being asked for).

| Statement | Form | Notes |
|---|---|---|
| `city` | `city <W>x<H> [theme=<theme>] [packs=a,b] [currency=<CODE>]` | Optional. Default 64x64, theme `architect`. Size is 4-512 per side. `currency=` is the money the costs are in, three letters such as `USD` (the default) or `EUR`. |
| `district` | `district <id> ["Name"] <x1>,<y1>..<x2>,<y2> [color=#rrggbb]` | A rectangle of land; the end point is exclusive. May contain one `zone`. |
| `zone` | `zone host=<selector> type=<building-type> [flow=row\|column] [slots="name:n,..."]` | Indented under a `district`. Hosts matching the selector move into the district and get a building each. |
| `building` | `building <id> <type> [at x,y \| in <district>] [rot=0-3] ["Name"] [host=<selector>] [owner=<name>]` | A lot. Without `host=` it is a vacant lot. `rot` is quarter turns (or 0/90/180/270). `owner=` says who looks after it (a team, at most 40 characters; quote it if it has spaces) and is shown on its card. |
| `boundary` | `boundary <id> ["Name"] members=<id>,<id>,...` | A zone of trust: the buildings, and other boundaries, inside it. It is drawn as a dashed outline that wraps them, so boundaries nest. A building or boundary is directly inside one boundary at most, and a boundary cannot hold itself. A link that goes out of or into a boundary crosses it, and the card says so: mark the guarded ones `variant=security`. |
| `level` | `level <id> ["Name"] members=<id>,<id>,...` | A big named area that groups districts and buildings, such as the way in or the data tier: it is drawn as one plate with its name, and from far away only the names of levels are written, so a big city can be read by its levels. A district or building is in one level at most. Write the levels in the order they should be read. |
| `floor` | `floor <id> ["Label"] [project=<selector>]` | Indented under a `building`. Binds a Docker Compose project. |
| `room` | `room <id> <kind> ["Label"] [port=<n>[,<n>...]] [secret=<NAME>[,<NAME>...]] [cost=<amount>] [service=<selector>]` | Indented under a `floor`. `port=` is the port or ports the service listens on; `secret=` names the secrets it holds; `cost=` is what it costs each month; `service=` binds a Compose service. |
| `cost` | `cost <amount> ["What it pays for"] [per=month\|year] [vendor=<name>] [plan=<name>] [spec="..."]` | Indented under a `room`: one cost of that service, such as the rented server, its backups, its domain. `per=` is how often it is paid (a month when it says nothing); `vendor=` who sells it, `plan=` which plan, `spec=` what it is made of (at most 200 characters). Up to 20 for a room. |
| `gate` | `gate <id> [at x,y] [port=<1-65535>] ["Name"]` | An entry point on the park edge. Without `at` it goes on the left edge. |
| `road` | `road <a> -> <b> [-> <c> ...] [id=<id>]` | Each stop is a point `x,y` or the id of a building or gate. Routed around lots automatically. |
| `link` | `link <room> -> <room> [-> <room> ...] ["label"] [variant=emphasis\|security\|dashed] [auto=true]` | A logical connection between rooms. Drawn as a thin line over the ground from the door of one building to the door of the other, along the roads where there are any. A `"label"` says what passes (`"SQL"`, `"HTTPS"`, `"events"`) and is written on the line; `variant=` says in what way: `emphasis` stresses the main path, `security` marks a guarded crossing, `dashed` an occasional or asynchronous one. A chain gives every hop the same label and variant. |
| `pipeline` | `pipeline <id> ["Name"] <place> -> [stage] -> ... -> <place> [job=<selector>]` | A flow, such as CI/CD: where it starts, the stages it passes and where it ends. A place is the id of a building, district, gate or room; a `[stage]` is a step between places. Drawn as a line in a colour of its own from place to place, along the roads where there are any; live runs colour each stage. |
| `run` | `run <stage> "<command>"` | Indented under a `pipeline`. Adds a command to the script of one of its stages; several lines for one stage make its script, in order. Inside a command use single quotes. |
| `step` | `step <place> "<words>"` | Indented under a `pipeline`. Says in plain words what happens at one of its places (at most 200 characters), for someone who reads the flow without knowing the system: "The order is checked and saved". A place the flow comes back to takes its `step` lines in the order of the visits. |
| `prop` | `prop <type> at x,y [rot=0-3] [id=<id>]` | A decoration. |
| `pack` | `pack <id> ["Name"] [about="..."]` | Words of your own for this city: the building types and room kinds under it, which this city may then use like the built-in ones. A pack is written in the city, so it travels with it in a link, a saved design and a file; the id may not be the name of a pack InfraCity has. |
| `buildingtype` | `buildingtype <id> "Name" size=<W>x<D> floor=<height> roof=flat\|shed\|gable\|tower wall=#rrggbb top=#rrggbb [use="..."]` | Indented under a `pack`: a kind of building. `size` is its footprint in tiles, `floor` the height of one floor, `wall` and `top` its colours. |
| `roomkind` | `roomkind <id> "Name" color=#rrggbb [icon=<name>] [keeps=true] [secrets=a,b] [use="..."]` | Indented under a `pack`: a kind of room, with its shapes under it. `color` is how it is drawn in a design; `keeps=true` says it keeps things where they are put (data, stock) and not does work, which is what the Data lens follows; `secrets=` names what a room of the kind always holds, and no `secrets=` means no padlock. |
| `box` | `box [at=x,y] [size=w,d] [z=<n>] [h=<n>\|full] fill=<paint> [outline=<paint>,<width>]` | Indented under a `roomkind`: a block. `at` and `size` are shares from 0 to 1 across and along the room; `z` and `h` are heights. Every shape may also say `shade=` (0.4 to 1.6), `alpha=` (0.05 to 1) and `fine=true`. |
| `drum` | `drum [at=x,y] [r=<share>] [z=<n>] [h=<n>\|full] fill=<paint>` | A round block, `r` a share of the room's half width. |
| `dot` | `dot [at=x,y] [z=<n>] [r=<pixels>] fill=<paint>` | A dot of light, `r` in screen pixels. |
| `line` | `line points=x,y,z;x,y,z;... color=<paint> [width=<n>]` | A line through two to twelve points, each across, along and up. |
| `walls` | `walls [at=x,y] [size=w,d] [z=<n>] [h=<n>\|full] [bays=<n>] fill=<paint> [outline=<paint>,<width>]` | The two faces of a block that the viewer sees, with no roof. |
| `bitmap` | `bitmap rows=ab.,.ba palette=a=<paint>;b=<paint> [at=x,y] [size=w,d] [z=<n>] [h=<n>] [square=true]` | A picture of up to 16 rows of up to 16 letters, `.` empty, each letter painted by `palette`. |

1. **One statement per line.** Indent (any consistent number of spaces, two recommended) to nest `floor` under `building`, `room` under `floor`, `cost` under `room`, `zone` under `district`, `run` under `pipeline`. `%%` starts a comment. Blank lines are ignored.
2. **Keyword first**, lower-case: `city`, `district`, `zone`, `building`, `boundary`, `level`, `floor`, `room`, `cost`, `gate`, `road`, `link`, `pipeline`, `run`, `prop`, `pack`, `buildingtype`, `roomkind` and the shapes `box`, `drum`, `dot`, `line`, `walls`, `bitmap`.
3. **Positional words first, then `key=value` attributes.** A value containing spaces is quoted. A bare `"Quoted text"` is the display name.
4. **Ids** are letters, digits, `-`, `_`, `.` (for example `prod-1`) and must be unique across the whole city. They are required for `district`, `building`, `gate`, `floor`, `room` and `pipeline`; optional (`id=...`) for `road` and `prop`.
5. **Points and areas.** `x,y` is a tile; `x1,y1..x2,y2` is a rectangle with an exclusive end. The origin is the top-left; x grows right, y grows down. The bottom rows of the park are reserved for arrivals and cannot be built on.
6. **Placement, in order of preference:** `in <district>` (next free slot in that district), `at x,y` (exact), or nothing (next free spot in open land, left to right then top to bottom). Never compute coordinates unless you need an exact position.
7. **A boundary is trust, not place.** A `district` says where buildings stand; a `boundary` says which buildings trust each other (a DMZ, a VPC, a data network). A building can be in a district and in a boundary, and boundaries nest: `boundary core members=dmz,api`. Write the boundary after the buildings it holds. Mark the links that cross one with `variant=security` where they are guarded.
8. **A level is size, not trust.** A `boundary` says which buildings trust each other; a `level` groups whole areas so that a big city can be read: the districts and buildings that belong to one tier of the infrastructure, such as `level edge "The way in" members=front,gateway`. A level holds districts and buildings, never boundaries or other levels. Use levels when a city has more than a handful of districts; leave them out of a small one.
9. **Binding is optional** and uses selectors: `host=`, `project=`, `service=`, `job=`, `port=`. A selector is a name (`prod-1`), a glob (`web-*`), `label:key=value,key2=value2`, or `*`. A building with no `host=` is a vacant lot waiting for a host.
10. **Every service has its own port.** A room's `port=` is the port that service listens on (`port=5432`, or several as `port=4317,4318`); a gate's `port=` is the public port people come in by. They are different things: do not give every room the gate's port. Links are drawn to the port of the room they call.
11. **Secrets are named, never written.** `secret=POSTGRES_PASSWORD` says a room holds a secret of that name. Only a plain name is accepted: anything that could be a value (it has `=`, `:`, `/`, `@` or a space) is refused. A room that keeps data always holds a secret, so it is marked with a padlock even when none is named; the catalog says which kinds those are.
12. **Costs are a design, never a bill.** `cost=120` on a room says the service costs 120 a month, in the city's money (`currency=EUR` on the `city` line; USD when it says none). It is a plain number, whole or with cents (`19.99`), with no sign, symbol or unit. When the details matter (a rented server: who sells it, which plan, what it is made of) write a `cost` line under the room for each thing it costs: `cost 12 "Virtual server" vendor=Hetzner plan=CX22 spec="2 vCPU, 4 GB RAM, 40 GB SSD"`; add `per=year` for what is paid yearly. The cards add the costs up for a building, a district, a level and a boundary, and for the whole city. Nothing is read from a real invoice, and InfraCity connects to no billing account.
13. **Roads, links and pipelines use `->`.** Road stops are `x,y` points or building / gate ids. Link endpoints are room ids; ids that contain `/` refer to rooms the system generates (`building/floor/service`). Pipeline stops are place ids (a building, district, gate or room) or `[stages]`.
14. **CI/CD is a flow, never a building.** Draw it as a `pipeline` from the place a change starts (a Git server, say) through its `[stages]` to the places it ends up (staging, production). It must start and end at a place. `job=` names the live pipeline whose runs colour the stages. A stage can say what it runs: `run build "docker build -t shop ."` under the pipeline, one line for each command. A script is there to be read; nothing is run from the city, and it never holds the value of a secret (write `$TOKEN`).
15. **Types and kinds come from the catalog below.** An unknown name is an error that suggests the nearest valid one.
16. **Paint in a shape** is a `#rrggbb` colour or a role: `$state` (what the room is showing: its health, or the colour of its kind in a design), `$frame`, `$glass`, `$accent` (the light of the part), `$text` or `$ground`. Every room kind of a pack must paint at least one shape `$state`, so a room can always show how it is doing. A shape stays inside its room: heights are in the units of the built-in drawing and stay below the next floor.
17. **Forgiving, never silent.** A bad line is skipped and reported; every other line still renders.

Building types (footprint is width x depth in tiles):
- `factory` — Factory, 3x3 tiles
- `warehouse` — Warehouse, 4x2 tiles
- `tower` — Tower, 2x2 tiles
- `depot` — Depot, 3x2 tiles

Room kinds:
- `service` — Service
- `database` — Database; always holds a secret (password)
- `cache` — Cache; always holds a secret (password)
- `worker` — Worker
- `config` — Config
- `queue` — Queue; always holds a secret (credentials)
- `proxy` — Proxy
- `storage` — Storage; always holds a secret (access key)

Props:
- `tree` — Tree
- `lamp` — Lamp
- `bench` — Bench
- `container` — Container

Themes:
- `industrial` — 2100 day
- `blocks` — Blocks
- `architect` — Architect

Packs (ask for one with `packs=<name>` on the `city` line; it adds words to a city that asks, and to no other):
- `logistics` — Logistics: the journey of goods: where a parcel waits, what moves it, where it is counted, and whose hands it is in. Ask for it with `packs=logistics`, as in `city 64x64 packs=logistics`.
  Building types:
  - `hub` — Sorting hub: where parcels are sorted by destination: a sorting hub, a cross-dock
  - `shop` — Shop: where an order starts: a web shop, a store, a seller
  - `house` — Home: where the journey ends: a customer, a delivery address
  Room kinds:
  - `shelf` — Shelf: goods kept in stock: shelves, racks, a pallet position
  - `cold-store` — Cold store: goods that must stay cold: a cold room, a freezer, a medicine fridge
  - `belt` — Conveyor: what carries goods along: a conveyor, a chute, a roller track
  - `bay` — Bay: a place where parcels wait: a cage, a loading bay, a pickup point
  - `sorter` — Sorter: a machine or a person that sends each parcel its way
  - `scanner` — Scanner: where a parcel is read and counted: a scanner, a label printer, a gate reader
  - `vehicle` — Vehicle: what moves goods between sites: a truck, a van, a cargo bike
  - `door` — Door: where goods pass between inside and outside: a dock door, a front door
  - `ledger` — Ledger: the record of where each parcel is: a scan log, a manifest, a tracking table
- `workflow` — Work flow: work that passes between people and teams: what is asked, what waits, what is done, what is checked and what is kept. Ask for it with `packs=workflow`, as in `city 64x64 packs=workflow`.
  Building types:
  - `office` — Office: a team or a department where the work is done
  - `counter` — Counter: where the public meets the work: a shop counter, a help desk, a customer portal
  Room kinds:
  - `form` — Form: where something is asked or entered: an order form, a request, a sign-up
  - `inbox` — Inbox: work waiting for someone: an inbox, a list of requests, a to-do list
  - `task` — Task: a step a person does: check, prepare, call, pack
  - `review` — Review: a check that can say no: an approval, an inspection, a sign-off
  - `records` — Records: what is kept for later: an archive, a file, a register
  - `notice` — Notice: a message sent to someone: an email, a letter, a text message
  - `rule` — Rule: what decides: a policy, a checklist, a limit
- `os` — Operating system: what runs between programs and hardware: the layers of an operating system, the calls that cross them and the work the kernel does. Ask for it with `packs=os`, as in `city 64x64 packs=os`.
  Building types:
  - `program` — Program: software that runs on top: an application, a system service, a shell
  - `kernel` — Kernel: what runs with full privilege: the kernel, its drivers, a hypervisor
  - `chip` — Hardware: the machine itself: a processor, memory, a disk, a screen
  Room kinds:
  - `process` — Process: a running program: an application, a window server, a daemon
  - `driver` — Driver: what talks to a device for the kernel: a disk driver, a display driver, a network driver
  - `device` — Device: a piece of hardware: the processor, memory chips, a disk, a screen
  - `memory` — Memory: what a program or the kernel keeps in memory: an open document, virtual memory, a page cache
  - `files` — Files: what is kept on disk: a file system, a cache folder, a settings store
  - `syscall` — Interface: where a call crosses into a more privileged layer: system calls, an API, a message to another process
  - `scheduler` — Scheduler: what decides who runs next: the scheduler, a timer, a run queue

## Worked example: a shop on three hosts

Given this:

```text
Hosts
  edge-1  runs the Compose project "edge":  traefik (ports 80 and 443)
  app-1   runs the Compose project "shop":  web, api, worker
  data-1  runs the Compose project "data":  postgres, redis, rabbitmq
  ops-1   runs the Compose project "ops":   prometheus (port 9090), grafana (port 3000)

docker-compose.yml of "shop"
  services:
    web:     { image: shop/web, expose: [3000], depends_on: [api] }
    api:     { image: shop/api, expose: [8080], environment: { DATABASE_URL: "postgres://data-1:5432/shop", REDIS_URL: "redis://data-1:6379", AMQP_URL: "amqp://data-1:5672" } }
    worker:  { image: shop/worker, environment: { AMQP_URL: "amqp://data-1:5672", DATABASE_URL: "postgres://data-1:5432/shop" } }

Traefik sends shop.example.com to web.
Prometheus scrapes the api and postgres. Grafana reads from Prometheus.

.github/workflows/release.yml, on a push to main
  build:   docker build -t ghcr.io/shop/app:$GITHUB_SHA .
  test:    docker run --rm ghcr.io/shop/app:$GITHUB_SHA npm test
  push:    docker push ghcr.io/shop/app:$GITHUB_SHA
  deploy:  ssh deploy@app-1 'docker compose pull && docker compose up -d'

On data-1, POSTGRES_PASSWORD and RABBITMQ_DEFAULT_PASS are Docker secrets.
The api reads STRIPE_SECRET_KEY from its environment.
```

the answer is this:

```city
%% Input: three hosts that run Docker Compose, described in words with one Compose file.
%% Assumed: the web app calls the API (it depends on it); nothing else reaches the API.
%% Assumed: the worker listens on no port; it only reads from the queue.
%% Assumed: Redis names no secret; as a cache it is drawn as holding one all the same.
%% Assumed: operations and delivery are shared (they watch or serve every layer), so they stand in a second row under the flow row.
%% Left out: nothing. Port 80 only redirects to 443, so the gate is 443.
city 35x31

district edge "Edge" 4,4..11,10
district app "Application" 14,4..21,10
district data "Data" 24,4..31,10
district delivery "Delivery" 6,13..19,19
district ops "Operations" 22,13..29,19

building edge-1 tower in edge "edge-1" host=edge-1
  floor edge-1.edge "edge" project=edge
    room edge-1.edge.traefik proxy "Traefik" port=80,443 service=traefik
building app-1 factory in app "app-1" host=app-1
  floor app-1.shop "shop" project=shop
    room app-1.shop.web service "Web" port=3000 service=web
    room app-1.shop.api service "API" port=8080 secret=STRIPE_SECRET_KEY service=api
    room app-1.shop.worker worker "Worker" service=worker
building data-1 warehouse in data "data-1" host=data-1
  floor data-1.data "data" project=data
    room data-1.data.postgres database "Postgres" port=5432 secret=POSTGRES_PASSWORD service=postgres
    room data-1.data.redis cache "Redis" port=6379 service=redis
    room data-1.data.rabbitmq queue "RabbitMQ" port=5672 secret=RABBITMQ_DEFAULT_PASS service=rabbitmq
building ops-1 tower in ops "ops-1" host=ops-1
  floor ops-1.ops "ops" project=ops
    room ops-1.ops.prometheus service "Prometheus" port=9090 service=prometheus
    room ops-1.ops.grafana service "Grafana" port=3000 service=grafana
building github tower in delivery "GitHub"
  floor github.repo "Repository"
    room github.repo.code storage "shop repository"
building ghcr warehouse in delivery "ghcr.io"
  floor ghcr.images "Images"
    room ghcr.images.shop storage "shop images"

gate public port=443 "shop.example.com"
road public -> edge-1

link edge-1.edge.traefik -> app-1.shop.web -> app-1.shop.api "HTTP"
link app-1.shop.api -> data-1.data.postgres "SQL"
link app-1.shop.api -> data-1.data.redis "cache"
link app-1.shop.api -> data-1.data.rabbitmq "jobs" variant=dashed
link app-1.shop.worker -> data-1.data.rabbitmq "jobs" variant=dashed
link app-1.shop.worker -> data-1.data.postgres "SQL"
link ops-1.ops.prometheus -> app-1.shop.api "scrape" variant=dashed
link ops-1.ops.prometheus -> data-1.data.postgres "scrape" variant=dashed
link ops-1.ops.grafana -> ops-1.ops.prometheus "queries"

pipeline release "Release" github -> [build] -> [test] -> [push] -> ghcr -> [deploy] -> app-1
  step github "A change is merged into the shop's code"
  run build "docker build -t ghcr.io/shop/app:$GITHUB_SHA ."
  run test "docker run --rm ghcr.io/shop/app:$GITHUB_SHA npm test"
  run push "docker push ghcr.io/shop/app:$GITHUB_SHA"
  step ghcr "The tested shop is stored, ready to ship"
  run deploy "ssh deploy@app-1 'docker compose pull && docker compose up -d'"
  step app-1 "Customers get the new version of the shop"
```

## Worked example: a parcel from a web shop

Given this:

```text
A web shop sells a jar of dog vitamins. The shop takes the order and the payment.
The warehouse picks the jar from a shelf, prints a label and puts the parcel in a cage by the dock.
At the dock door the carrier's driver takes the parcel: from then on it is the carrier's, until the customer has it.
The carrier's hub scans the parcel and sorts it onto a van. The courier scans it again and brings it to the customer's front door.
```

the answer is this:

```city
%% Input: a parcel's journey from a web shop to a customer, in plain words.
%% Assumed: the warehouse and the carrier are separate; the dock door is where custody changes hands.
%% Left out: the payment: the input names it but says nothing of how it works.
city 51x22 packs=logistics

district shop "Shop" 4,4..11,10
district warehouse "Warehouse" 14,4..21,10
district carrier "Carrier" 24,4..37,10
district customer "Customer" 40,4..47,10

building web shop in shop "Web shop"
  floor web.order "Order"
    room web.order.taken service "Takes the order"
building stock warehouse in warehouse "Warehouse"
  floor stock.floor "Floor"
    room stock.floor.shelf shelf "Shelf"
    room stock.floor.label scanner "Label printer"
    room stock.floor.cage bay "Cage by the dock"
    room stock.floor.door door "Dock door"
building hub hub in carrier "Sorting hub"
  floor hub.sorting "Sorting"
    room hub.sorting.scan scanner "Hub scanner"
    room hub.sorting.sort sorter "Sorter"
building courier depot in carrier "Courier"
  floor courier.round "Round"
    room courier.round.scan scanner "Courier's scanner"
    room courier.round.van vehicle "Van"
building home house in customer "Customer"
  floor home.door "Door"
    room home.door.front door "Front door"

boundary shop-custody "Shop's custody" members=web,stock
boundary carrier-custody "Carrier's custody" members=hub,courier

gate orders "Orders come in"
road orders -> web

link web.order.taken -> stock.floor.shelf "pick list"
link stock.floor.shelf -> stock.floor.label "item"
link stock.floor.label -> stock.floor.cage "parcel"
link stock.floor.cage -> stock.floor.door "to the dock"
link stock.floor.door -> hub.sorting.scan "handover" variant=security
link hub.sorting.scan -> hub.sorting.sort "parcel"
link hub.sorting.sort -> courier.round.scan "onto a van"
link courier.round.scan -> courier.round.van "scanned"
link courier.round.van -> home.door.front "handover" variant=security

pipeline parcel "A parcel" web -> [order] -> stock -> [pick] -> [hand-over] -> hub -> [sort] -> courier -> [deliver] -> home
  step web "The customer orders on the website"
  step stock "The item is picked and packed in the warehouse"
  step hub "The carrier sorts the parcel by area"
  step courier "A courier takes it on the round"
  step home "The parcel is handed over at the door"
```

## What to answer

Reply with exactly one fenced `city` block and nothing else. Begin the block with `%%` comment lines that say what the input was, each thing you assumed, and each thing in the input you left out and why. If you are writing a file, write the same text to a file ending in `.city`.

## Check before you answer

- [ ] Every id is unique and uses only letters, digits, `-`, `_` and `.`.
- [ ] Every building has `in <district>`, the district exists, and no building has `at`.
- [ ] Every district has the size the recipe gives, none overlap, and the city is 4 wider and 12 higher than its districts reach.
- [ ] Districts that everything uses (operations, CI/CD, backup) are shared ones, in the second row, not in the flow row.
- [ ] Every flow is one line that can be followed: its places in the order it really goes, a link between each two places that follow each other, a `step` line for each place, and no more than twelve places.
- [ ] When you can run it, `pnpm infracity check city.city` shows no mistake, and each look is a slip you fixed or a choice you meant.
- [ ] No link runs past a district it has nothing to do with when moving one district would put its two ends side by side.
- [ ] Every building has at least one floor with at least one room.
- [ ] Every `link` joins two room ids that exist. None joins a building, a floor or a district.
- [ ] Every room that listens has its own `port=`. The rooms do not all carry the gate's port.
- [ ] Every `pipeline` starts and ends at a place (a building, district, gate or room), with `[stages]` only between places.
- [ ] Every `run` line is indented under its pipeline, names one of that pipeline's stages, and has its command in double quotes with only single quotes inside.
- [ ] Every building type and room kind is one the catalog lists.
- [ ] Nothing in the city is missing from the input, and whatever you left out of the input is named in a comment.
- [ ] Every secret the input names is on the room that holds it as `secret=<NAME>`, and no value of any secret appears anywhere.

## When problems come back

InfraCity reports problems as plain text with a line and a column:

```text
line 7:12 error: unknown building type "fcatory"
  did you mean "factory"?
```

Change only what the report names and return the whole city again. If you can run commands in the InfraCity repository, check your own work before you answer: `pnpm infracity check city.city` exits with 1 on any error, and `pnpm infracity render city.city -o city.svg` draws the city.
