Case study · 02 / 12
A monthly report deck should be rebuilt, never edited
A case study — deckforge
Summary
| Problem | A recurring status report was a PowerPoint deck assembled by hand each month: numbers copied from spreadsheets into charts and tables, long tables trimmed to fit, and no record of which figures a circulated deck was built from. |
|---|---|
| Constraint | The template belongs to the designer and the slides belong to whoever opened them. The system could own only the slides it generated, could not change a template's layout to fit the data, and had to run inside one SharePoint site with the narrowest permission Graph offers. |
| Solution | A .NET 8 composition engine that fills named shapes in a PowerPoint template from a JSON payload. It runs as an Azure Function behind Entra ID, with an SPFx control tower that runs the monthly cycle and a PowerPoint add-in that refreshes a downloaded deck in place. |
| Outcome | Deployed to a pilot site. The control tower is at release 1.8.1.0, and pilot use drove ten releases in one session. At session 13: 603 .NET tests, 341 control-tower and 69 add-in Jest tests. |
| Role | Product design, architecture, the engine, the Function host, the control tower, the add-in, deployment scripts and the documentation. Built over 26 recorded build sessions, each with what was built, verified and deviated. |
| Stack | .NET 8 · DocumentFormat.OpenXml 3.5.1 · Azure Functions (isolated worker) · Easy Auth · Microsoft Graph · Bicep · SPFx 1.21.1 · Fluent UI v9 · SheetJS (xlsx) · Office.js · webpack · xUnit · Jest · python-pptx (sample templates) |
1. The problem
A monthly status report is mostly last month's report with a few numbers moved. Doing it by hand is slow, but that is not the worst part. The worst part is what can't be checked afterwards. Nobody can tell which spreadsheet a chart came from. A table that ran off the slide gets quietly trimmed. A chart can show this month's bars while *Edit Data* still holds last month's numbers.
The usual fix is a live link: wire the charts to the data source and refresh. Live links break as soon as the deck leaves the network that hosts the data. They fail on a laptop, in an attachment and in a shared drive, and you can't reproduce what a circulated deck showed once the source has moved on.
The brief was a deck that could be produced, reproduced and audited. Section owners supply their figures, a run is generated when everyone has submitted, and the deck that goes out can be traced to the exact data it was built from.
2. The constraints
The designer owns the template. The look of the report is decided in PowerPoint by a person, not by code. The engine has to fill a template, not lay one out. If the data doesn't fit the slide the designer approved, the engine still can't redesign the slide.
People edit the decks. A generated deck gets downloaded, annotated, merged with other decks and presented. Anything that later updates it has to tell its own slides apart from everyone else's. It also has to handle a file holding slides from more than one month.
One site, and the narrowest permission available. Templates, datasets and decks live in libraries on a single SharePoint site. The repository records this in docs/decisions.md, *One site, Sites.Selected, and a write grant*:
Sites.Selectedgrants nothing on its own; the per-site grant is what opens access. The alternative,Sites.ReadWrite.All, is a tenant-wide capability for a job that touches two libraries.
No AI between the data and the slide. A report deck is a factual document. The decision is recorded as *No generative AI in the generation path*: "a generated sentence cannot be traced, cannot be reproduced across runs, and shifts the burden of checking onto the reader who is least able to do it."
3. Architecture
Four parts, with a JSON payload as the contract between them.
The template. An ordinary .pptx. Each fillable position is a shape whose name is set in PowerPoint's Selection Pane: text.summary, chart.budget, table.milestones. There are seven element types. The naming rule is executable: ShapeName.Pattern is a public regex, so the documentation and the code can't drift apart. A linter checks a template against it before any run.
The payload. A runId and a list of slides. Each slide names a template slide and maps element names to values. The engine reads only this. It never reads a database, a workbook or an API, so the gathering side can change without the engine knowing. Keep the payload and you can rebuild the deck.
The engine. A .NET 8 solution with three faces: a library (composer, element handlers, linter, payload model, storage), a CLI (deckforge lint | compose | dump) and an Azure Function host. The Function composes the deck and writes it to the Decks library. It never provisions the site and never writes the run list. It authenticates with a system-assigned managed identity holding Sites.Selected and a write grant on one site, and calls Graph over a raw HttpClient.
The control tower. An SPFx web part that runs the monthly cycle. It provisions the site from config/site-schema.json, the single source of every library, list and column name. It creates a run, collects each section from its owner and calls the Function as the signed-in user. A run moves Draft → Collecting → Locked → Generated → Published. Generate stays blocked until every section is submitted, and the last submit triggers it. Section owners can type values, paste grids from Excel, or import from a workbook. The workbook importer runs in the browser as the user and writes the same list the forms write.
The add-in. A PowerPoint task pane with one job: *pull the latest*. Someone who downloaded September's deck and added their own slides can bring the generated slides up to the current run version without losing their own work. It reuses the same API registration through Office single sign-on.
Deployment is a Bicep template plus three scripts: grant the site access, create the auth app registration, and build the add-in manifest.
4. The interesting decisions
4.1 Shapes are found by name, not by placeholder text
The obvious design is tokens: type {{projectName}} on the slide and replace it. The repository explains why not. PowerPoint splits a text run in the middle of a token whenever spell-check or formatting touches it, so the token stops matching for reasons the author can't see. Tokens also only work in text shapes, which rules out charts, tables and pictures.
A shape name is metadata. It survives formatting, it is unique, it can be checked before a run, and the same lookup reaches a chart or a table as easily as a paragraph. The cost is that names are set in a dialog rather than typed on the slide. That is why the linter exists and why docs/naming-convention.md is a document of its own.
4.2 A chart is filled, never rebuilt, and both copies of its data are written together
A PowerPoint chart stores its numbers twice: as cached values in the chart XML, which is what renders, and in an embedded workbook, which is what *Edit Data* opens. Writing only the cache gives a deck that looks right until someone clicks *Edit Data* and finds last quarter's figures. The repository calls this "the worst failure mode available, because it surfaces in front of" the audience. The handler always writes both.
It also never creates a chart part, never adds a series and never changes a chart type. It finds series by walking c:ser in the chart namespace, so one code path serves column, bar, line, area and pie charts. Payload series fill template series by position:
- Fewer series than the template: the extras are removed and the remaining
c:idx/c:ordervalues are renumbered. - More series than the template: the run fails, naming the element.
The cost is that a designer who wants four lines has to draw four lines. The alternative was inventing series styling, legend entries and label formats the engine had no basis for, which is design work that belongs to the designer.
4.3 Overflow repeats the slide instead of truncating the table
A table's body-row count is the slide's capacity. When a payload brings more rows, there were four options:
- Truncate. Loses data silently.
- Fail the run. Makes the deck depend on a row count nobody controls.
- Grow the table. Produces a layout the designer never approved.
- Clone the slide once per page. Each page gets its share of rows, and every other element on the slide (title, KPIs, chart) is filled identically.
The engine clones. Repeating the other elements rather than blanking them is deliberate: "a continuation slide with no title is a slide a reader cannot place." It is also what a person does by hand today.
The cost is that a payload's slide count can't be known from the payload alone. That pushed the service limits (200 slides per run, 500 rows per table element) into SlidePlanner. Only the planner knows the paginated total, and it runs before the template is copied, so a refused payload leaves nothing behind.
4.4 Generated decks are compared by a deterministic dump, not by bytes
Two runs over the same template and payload never produce byte-identical files: a .pptx is a zip, and every entry has a timestamp. Getting byte identity would mean rewriting the archive by hand. Instead, deckforge dump writes a JSON description of a deck: slides in order, their tags, and for every named shape its name, type, kind and text, plus chart categories and series and table rows. It contains no timestamps, part URIs or relationship IDs. The golden-file tests compare dumps, and the expected dumps are committed under samples/.
The cost is written down too. The dump only sees what it has been taught to describe. A picture is reported by name and kind only, so a change to its image is invisible to the comparison until an image handler exists. That handler is in the backlog, not shipped.
4.5 The deck carries its own configuration
A web part gets its API URL and client ID from a property pane. An Office add-in opening a .pptx has no page, no site context and nowhere to ask. The repository lists three options and rejects all of them:
- A settings list: another thing to provision and get wrong.
- One manifest per tenant: a redeploy to change a URL.
- Asking the user once: works per person and per document, so one mistyped value helps nobody.
The fourth option is that the file already knows. The Function stamps every deck with six presentation-level tags: the run, the template, the tag schema version, the run version it was built from, the host's base URL and the store's site. The add-in reads them and asks nothing.
The same tags settle ownership. A slide carrying a different run's DECKFORGE_RUN value is left alone, counted and reported ("2 slides in this presentation came from another run and were left where they are"), because a deck holding September's slides next to August's is someone building a quarter review. Ownership is decided by the tag's *value*, not by whether a tag is present.
4.6 The pull runs compose, plan, insert, delete — in that order and no other
Refreshing a deck in place means removing old slides and adding new ones, and either step can fail. The order is chosen so that every failure leaves a usable deck:
- A failed compose changes nothing, because nothing has been written yet.
- A failed insert changes nothing, because nothing has been deleted.
- A failed delete leaves both sets of slides in the deck. That is ugly but obvious, and the pane says so.
Deleting first and then failing to insert would leave the person with exactly the part they asked to update missing. The plan names the old slides by ID *before* the insert, because the incoming slides carry the same run tag as the ones they replace.
A smaller rule in the same spirit: decks composed before the control tower started sending a version have no version tag. The add-in reads that as unknown, never as zero. "This presentation was built from version 0" would describe a deck nobody has, so an unknown version can still be pulled but is offered without the "you are two versions behind" line.
4.7 The default authentication mode is the one that refuses
The Function's routes are anonymous at the host level, and middleware authenticates instead. That makes one setting the only thing between a caller and a compose. If Deckforge:Auth is absent, it means Easy Auth, not None: an unconfigured deployment answers 401 to everything except its health probe, "visibly broken, in the direction that cannot hurt anyone." Two configurations refuse to start at all:
- `ApiKey` with a key shorter than 32 characters.
- `None` outside the Development environment.
The cost is a host that fails to start when someone configures it carelessly, which is meant to happen.
5. Outcome
Deployed to a pilot site, and used. Session 13's write-up is mostly what the pilot found. It was planned as five sections and shipped as ten releases "because more than half of them came from somebody actually using the rest". Two examples:
- A chart paste that ate a series. Pasting a chart grid from Excel with its header row stored the header as a category, and
Number('Planned')becameNaNand then 0. Every chart pasted that way got a phantom leading point at zero. Tables survived the same paste because their cells are strings. The fix was found with a test first: the converters were lifted out of the view intocore/gridValues.ts, which gave the paste path a seam to test through. Series are now matched by label, not position, so columns in a different order no longer land in the wrong series. - A label that lied. A failed compose deliberately leaves a run in
Locked. The lifecycle strip drewLockedas *Generating*, in the brand colour, in the position of a progress indicator. A run whose compose had failed forty minutes earlier looked exactly like one being composed now. The strip now turns red and says *Generate failed*.
The same session removed a state. Approved was pressed by the same person a minute before Publish and differed in no permission, notification or route, so the lifecycle went from six states to five. As the decision record puts it, a state that only records that somebody clicked past it "is a step, not a state".
The capture model that became EMR Data Capture (record 20) started here. Session 16 added an *Enterprise Management Reporting — Data Capture* web part to this solution, and that capture work was later extracted into its own repository.
6. What is still open, stated plainly
- Two pilot faults are unresolved. The deck link still opens in the same tab: three fixes shipped and none worked. The session record says nothing more should ship until someone inspects the rendered link. A 500 on regenerate is undiagnosed. The leading guess (the deck is open in PowerPoint Online, so the overwrite meets a Graph 423) is recorded as a guess, with an instruction not to act on it without the log entry.
- A silent deployment gap, found late. The pilot site ran control-tower 1.0.0.0 through five releases. Every package reached the App Catalog and none reached the page, because replacing the package updates the catalog, not the site's app instance. The deployment guide now says to check
InstalledVersionrather than assume the upload was the deployment. - The runtime is on borrowed time. .NET 8 leaves support on 10 Nov 2026. A move to .NET 10 on the pilot's Linux Consumption plan failed: the container never started, and a host that never starts logs nothing. It was rolled back. The end-of-life warning is accepted for the pilot, and .NET 10 is re-scoped to move together with Flex Consumption.
- One site, not two. Splitting templates (read grant) from outputs (write grant) would stop a compromised Function from altering a template. It was considered and deliberately deferred until there is a production deployment to harden.
- Deferred scope, kept in writing.
docs/backlog.mdlists what was thought about and not built, each with a reason and a size: copy last month, a dataset diff between versions, notifications, Arabic and right-to-left localisation, the image handler, a fallback sign-in for the add-in. - The tests don't touch a tenant, by design. Session 13 counted that of the pilot's six reports, two were findable by a test and four weren't: "they are what a browser, a tenant and a spreadsheet do". The tests made a fix provable once its cause was known. The fixes reasoned from code without looking at the page didn't work.
7. What I'd take from this
Treat a generated document as a value, not a reference. Regenerating from a kept payload makes a deck reproducible and auditable, and the price — a correction is a new run, not a refresh — is the right one for something that is circulated and archived.
Decide in advance which slides you own, and own nothing else. Every safety rule in the add-in follows from that one sentence: compose before delete, leave other runs' slides alone, treat a missing version as unknown. Software that edits a user's file earns trust by the things it refuses to touch.
Write the failure order before the success path. The pull is safe because its four steps were ordered by what each one's failure leaves behind. There is no order that fails to nothing, so choose the one that fails to something a person can still use.
A state that nothing acts on is a step. If two states differ in no permission, no notification and no route, one of them is a button wearing a pill, and every table that has to carry it pays for it.