# Reports

A report is a narrative document built from your data: a cover, headings, text, KPI cards, tables and live charts, rendered as A4 pages or as 16:9 slides from a single JSON spec. Reports use the same query language, filters and chart renderer as dashboards. This page covers when to pick a report, the spec format, every section type, live data and `{{var}}` interpolation, repeating sections with `for_each`, and the CLI lifecycle.

## Report or dashboard?

If people check it throughout the day, build a [dashboard](/docs/dashboards/overview): a live grid they can filter and drill into. If it is a document someone prints, presents or sends on, such as a PDF or a slide deck for a review, build a report. A report is also the right choice when the numbers need commentary around them, since the numbers are filled in live, and when you want one section per team with the same structure, which `for_each` gives you.

## Where reports live

You author reports as JSON files in your project and publish them with the CLI. In the portal, **Reports** in the sidebar lists them with a search box and a preview. The bookmark icon on a report (**Add to favourites**) adds it to your favourites, which get their own group at the top of the list. Opening one shows it as paginated A4 with zoom and search, plus two buttons:

- **Present** opens the 16:9 slide view.
- **Export PDF** opens your browser's print dialog, where you can save the report as a PDF.

## The file

```json
{
  "name": "Minimal Demo Report",
  "description": "Cover, heading, paragraph and footer.",
  "slug": "minimal-demo",
  "spec": {
    "id": "00000000-0000-4000-a000-000000000001",
    "title": "Minimal Demo",
    "layout": "document",
    "cover": {
      "report_type": "DEMO",
      "title_line_1": "Minimal Demo",
      "subtitle": "The smallest valid report spec.",
      "client": { "name": "Example Co" },
      "date_string": "20 April 2026"
    },
    "sections": [
      { "type": "heading", "title": "Hello", "lead": "A report with no live data." },
      { "type": "paragraph", "content": "A cover and at least one section is all you need." },
      { "type": "footer", "client_name": "Example Co" }
    ]
  }
}
```

The outer `name`, `description` and `slug` are metadata, plus `id` once the report exists. Everything in `spec` is the report itself:

| Field | Meaning |
| --- | --- |
| `id` | Required. The CLI fills in a UUID if you leave it out. |
| `title` | Required. |
| `layout` | `document` (A4 portrait, paginated) or `presentation` (16:9 slides). This only picks which view people land in: every report can be shown either way. |
| `cover` | Required: `report_type`, `title_line_1` and `date_string`, plus `client: { name }`. Optional: `title_line_2`, `subtitle`, `prepared_by: { name, org? }`, `product_line`, `period_string`. |
| `filters` | Optional, up to 20. Same format as [dashboard filters](/docs/dashboards/filters#filter-fields). |
| `variables` | Optional, up to 30. A variable's `default` value is available as `{{id}}`. |
| `data_sources` | Optional, up to 30 named queries whose results feed the text. |
| `sections` | The body, 1 to 200 sections. |

The API checks the spec on every save. If something is wrong, the push fails with the exact path of the bad field, for example `/sections/3/data/fields/0/type: Expected union value`.

## Section types

| `type` | Purpose | Fields |
| --- | --- | --- |
| `heading` | Section title with an accent rule | `title`, `lead?` |
| `paragraph` | Body text | `content`, `format?: "html" \| "markdown"` (default `html`) |
| `row` | 12-column grid of other sections | `cells: [{ span: 1-12, content: <section> }]`, `align?`, `gap?`, `height?: 1-12` |
| `stat_row` | Strip of KPI cards | `cards: [{ num, label, variant?, sub? }]`, 1 to 8 cards |
| `table` | Static or data-driven table | `data: { headers, rows }` or `data: { from_rows, columns }` |
| `highlight` | Callout box | `data: { content, label?, variant? }` |
| `team_card` | Profile card for a team or other entity | `data: { name, tag?, coverage?, table?, note? }` |
| `form` | Fillable fields | `data: { fields, title?, description?, submit_label? }` |
| `data_view` | Read-only label and value pairs | `data: { fields: [{ label, value, width?, variant? }], title?, description? }` |
| `chart` | A live chart, full width | `data: <chart definition>`, `height?` |
| `chart_row` | Up to 6 charts side by side | `charts: [<chart definition>]`, `cols?: 1-6`, `height?` |
| `for_each` | Repeat sections per row or per group | `source`, `alias`, `group_by?`, `sections` |
| `page_break` | New page, or new slide in presentation view | none |
| `footer` | Closing block | `client_name`, `org_line?` |

Details worth knowing:

- **Variants.** `stat_row` cards and `team_card` coverage take `signal`, `green`, `amber` or `red`. `highlight` also accepts `blue`. A `team_card` tag takes `critical`, `warning`, `good` or `perfect`. `data_view` fields take the four colours plus `mono`.
- **Tables.** A static table has `headers` and `rows` (cells are strings, numbers, or `{ value, classes }`), plus an optional `column_alignments` list with `left`, `right` or `center` per column. A data-driven table names a source in `from_rows` and lists `columns: [{ header, field, align?, classes?, format? }]`, where `align` is `left`, `right` or `center` and `format` is `pct`, `pct1`, `int`, `float1` or `float2`. `classes` styles a cell (or every cell of a data-driven column) and takes any of `bold`, `right`, `center`, `bold-right`, `green`, `amber`, `red` and `signal`.
- **Forms.** Field types are `text`, `email`, `date`, `number`, `checkbox`, `textarea`, `signature` and `select` (with `options`), each with a `name` and `label`, and most with `required` and `width` (`full`, `half`, `quarter`). Forms are for print and on-screen sign-off: the submit button does not send or store the values anywhere.
- **Charts.** A chart section takes the same chart definition as a dashboard chart (with an `id`, `title` and `dsl`), so every [chart type](/docs/dashboards/overview#chart-types) works. Chart DSL uses `@time`, `@granularity` and `[%name%]` placeholders from the report's filters, not `{{var}}`.

## Layout: one spec, two views

The same `sections` render in both views:

- **Document**: A4 portrait, paginated. The report page, the PDF export and printing all use it.
- **Presentation**: 16:9 slides. Each `page_break` starts a new slide, and each `for_each` iteration becomes its own slide (short consecutive ones may be packed onto one slide).

Add a `page_break` between major blocks. Without breaks, a long report runs everything together.

### The 12-column `row`

```json
{
  "type": "row",
  "gap": "6mm",
  "cells": [
    {
      "span": 8,
      "content": { "type": "chart", "height": "60mm", "data": { "id": "velocity", "title": "Velocity", "dsl": "..." } }
    },
    {
      "span": 4,
      "content": {
        "type": "paragraph",
        "format": "markdown",
        "content": "**Q3 takeaways**\n\n- Revenue up **12%** on Q2\n- Activation flat"
      }
    }
  ]
}
```

- Spans should add up to 12. Extra spans wrap to the next line.
- `align` is `start`, `center`, `end` or `stretch` (default). `gap` defaults to `4mm`.
- Do not put a `row` inside a `row`. Stack rows at the top level instead.
- On narrow screens (under about 700 pixels wide) cells stack to full width, so the same report reads on a phone.
- `height: 1-12` applies in presentation view only: rows with a height share the slide space left over after headings and other content, in proportion (two rows with `8` and `4` split it 2 to 1). Document view ignores it.

### Markdown and HTML

Paragraphs are HTML by default. Set `"format": "markdown"` to write GitHub-flavoured Markdown instead: headings, bold and italic, lists, links, block quotes, code and tables all work.

HTML content (paragraphs, heading leads, highlights, team card notes and the cover subtitle) is sanitised before it is shown, so scripts and event handlers are removed. Stick to simple inline markup such as `<strong>`, `<em>`, `<br>` and `<span>`.

## Live data

### Filters

Report filters work like dashboard filters and appear in a filter bar above the report (hidden when printing). They feed both chart queries and data sources.

```json
"filters": [
  {
    "id": "time",
    "type": "select",
    "label": "Time Range",
    "scope": "global",
    "default": "90d",
    "options": [
      { "value": "30d", "label": "30 days" },
      { "value": "90d", "label": "90 days" },
      { "value": "180d", "label": "180 days" }
    ]
  }
]
```

### Data sources

A data source is a named query whose result you can quote in text:

```json
"data_sources": [
  {
    "id": "summary",
    "dsl": "source(\"gh.pr_enriched\", time: opened_at).since(@time, \"90d\").agg([count() as total_prs, count_distinct(team) as team_count])"
  }
]
```

- `id` is lower case, starting with a letter, then letters, digits or underscores (up to 64 characters).
- With `single_row` left at its default of `true`, the first row's columns are available as `{{summary.total_prs}}`.
- With `"single_row": false`, the whole result is available as a list. A `for_each` or a data-driven table needs this.

Data sources re-run when the filters change.

### `{{var}}` interpolation

Text fields can include `{{...}}` references:

```text
{{ name }}              a value
{{ summary.total_prs }} a field of an object
{{ name | none }}       a fallback when the value is missing or empty
```

The names come from, in order (later ones win): variable defaults, filter values, data source results, and `for_each` aliases. A filter's value is available under its `id`, its `variable`, its `column` and its label in snake case, so `{{time}}` and `{{time_range}}` both work for a filter with `id: time` and label "Time Range".

Numbers are formatted with thousands separators and up to three decimals. Lists of values are joined with commas. Anything missing becomes an empty string, or the fallback if you gave one, so use `{{x | n/a}}` for values that may be absent.

`[%name%]` also works in text and resolves the same way.

Interpolation applies to the cover (titles, subtitle, date, period, client name), `heading` title and lead, `paragraph` content, `stat_row` cards, static `table` cells, `highlight` label and content, `team_card` fields, `form` and `data_view` labels and values, and `footer` client name. It does not apply to chart titles or chart DSL.

## Repeating sections with `for_each`

### One iteration per row

```json
{
  "data_sources": [
    {
      "id": "top_engineers",
      "single_row": false,
      "dsl": "source(\"gh.pr_enriched\").filter(was_merged == 1).group_by([display_name]).agg([count() as merged]).sort([merged: desc]).limit(10)"
    }
  ],
  "sections": [
    {
      "type": "for_each",
      "source": "top_engineers",
      "alias": "eng",
      "sections": [
        { "type": "heading", "title": "{{eng.display_name}}" },
        { "type": "stat_row", "cards": [{ "num": "{{eng.merged}}", "label": "MERGED" }] }
      ]
    }
  ]
}
```

### One iteration per group

Set `group_by` to a column and you get one iteration per distinct value:

```json
{
  "type": "for_each",
  "source": "team_breakdown",
  "group_by": "team",
  "alias": "team",
  "sections": [
    {
      "type": "team_card",
      "data": {
        "name": "{{team.key}}",
        "tag": { "text": "{{team.count}} engineers", "variant": "perfect" },
        "coverage": { "value": "{{team.merged}} merged", "variant": "signal" },
        "table": {
          "from_rows": "team",
          "columns": [
            { "header": "Engineer", "field": "display_name" },
            { "header": "Merged", "field": "merged", "align": "right", "format": "int" }
          ]
        }
      }
    }
  ]
}
```

Inside a grouped iteration:

| Reference | Value |
| --- | --- |
| `{{team.key}}` | The group value |
| `{{team.count}}` | Number of rows in the group |
| `{{team.rows}}` | The group's rows (use with `from_rows`) |
| `{{team.<col>}}` | The value if it is the same on every row, otherwise the sum for numeric columns |
| `{{team.<col>_sum}}`, `_avg`, `_min`, `_max` | Explicit aggregates for numeric columns |

Keep `for_each` sources short (around 20 rows or fewer): every row becomes a section, and in presentation view a slide.

## CLI lifecycle

| Command | What it does |
| --- | --- |
| `solidafy report list [--q <search>]` | Lists reports in the active environment. |
| `solidafy report get <id\|slug>` | Prints a report as JSON. |
| `solidafy report pull [<id\|slug>] [--all]` | Writes reports to `environments/<env>/reports/<slug>.json`. |
| `solidafy report push <file> [--summary "..."]` | Creates the report (no `id` in the file) or updates it. On create the new `id` is written back into the file. |
| `solidafy report versions <id\|slug>` | Lists the version history. |
| `solidafy report restore <id\|slug> <version>` | Restores an older version. The current spec is saved as a version first, so a restore can itself be undone. |
| `solidafy report publish <id\|slug>` / `unpublish` | Marks the report published or draft. |
| `solidafy report share <id\|slug>` / `unshare` | Creates or revokes a share token. |
| `solidafy report delete <id\|slug>` | Deletes the report. History is kept. |

Every push that changes the spec creates a new version; `--summary` records what changed. A typical loop:

```bash
cp examples/report-full.json environments/sandbox/reports/q1-review.json
# edit the file
solidafy report push environments/sandbox/reports/q1-review.json --summary "First draft"
solidafy report versions q1-review
```

`share` prints a token and a public URL of the form `https://<api host>/api/v1/reports/shared/<token>`. Anyone with that URL can fetch the report's current spec without logging in: no version history and no organisation details are included. `unshare` makes the URL stop working.

AI agents connected through the Solidafy MCP server can do the same operations with the `list_reports`, `get_report`, `create_report`, `update_report`, `delete_report`, `list_report_versions`, `get_report_version`, `restore_report_version`, `publish_report`, `share_report` and `unshare_report` tools.

## Checklist before you push

- `layout` is `document` or `presentation`.
- `cover` has `report_type`, `title_line_1`, `client.name` and `date_string`.
- Every `{{...}}` points at a filter, variable, data source or `for_each` alias that exists. Unknown names silently become empty text.
- Every `for_each.source` and data-driven `from_rows` points at a data source with `"single_row": false` (or, for `from_rows`, a `for_each` alias).
- Every chart has an `id` and a DSL ending in `.chart(...)`, and uses `@time` rather than a fixed date, so the filter bar can control it.
- Numbers in the narrative come from data sources, not typed by hand.
- There is a `page_break` between major blocks, and a `footer` at the end.
