Commits

Templates in the database: Auto Magazine’s first post-MVP improvement

First day of post-MVP improvements: PDF templates move from the filesystem to the database, and the dashboard gains complete CRUD support, verified in production.

On Monday I started the first post-MVP improvement: a Templates section in the dashboard. Until now, PDF templates could only be modified through the filesystem, and the folder was carried along in the Docker image: any edit made from the dashboard would have been lost on the next docker compose up --build. The central decision, settled through the grilling process (ADR 0002), was that the database rows should become the source of truth.

Before touching code

The morning was spent preparing the groundwork. I installed mattpocock’s skills pack and defined how the agent would work: the tracker would be GitHub Issues, with triage labels for defects (needs-triage, needs-info, ready-for-agent, ready-for-human), and domain decisions would be read from the glossary and ADRs before exploring anything. The glossary changed both its name (CONTEXT.md → GLOSSARY.md) and its content: Edition is now the canonical piece—the document predated the move to multiple editions and had drifted from the product, with Number serving as its correlating element—and Header is now the master brand, alongside the Skeleton and master Stylesheet.

I also made three process corrections in a single session: the grilling must ask questions interactively (the recommendation is a selected option, not the answer), the spec and tickets are separate steps requiring individual approval—I published six issues before obtaining sign-off on the spec—and when the pack includes a skill for a step, it must be followed to the letter: the audit found that the spec lacked the required format and that the tickets had been sliced by layers instead of into vertical tracer bullets.

Four tickets in one day

The first tracer bullet (issue #2, TDD, a suite of 171 tests all green) moved the templates into the database: an idempotent seed on startup imports the seven missing factory templates without altering anything, rendering materializes the rows into a temporary directory for WeasyPrint, and a sealed mockup signature records the hash of the rows. The dashboard gained the "07 Templates" section, with a listing by role and a complete detail view, and was deployed to production (commit 1b97e3e). It was verified against the actual database in the datos/ volume: the seven factory templates and two existing editions remained intact.

Meanwhile, I found a bug myself while testing the ticket: the detail view’s content overflowed the card (a pre element measuring 1,989 px against 954 px available). I fixed it globally in the design system (pre-wrap, overflow-wrap: anywhere) and increased the font size to 1rem so the code could be read.

Next came the rest of the family: the template editor with variable references, Jinja errors showing the file and line, and CSS syntax errors detected with tinycss2 and displayed in the dashboard (commit 6aeb386); the "Restore original" button on factory-template records, providing a way for an update’s improvements to reach an edition that had already been assembled (fe1f687); and free-form templates with deletion in Cleanup (26b0c38). The code review of the last one caught three underlying bugs: the seed reimported a factory template that had been deleted, leaving its trash entry stuck; a free-form template could take the name of a factory template that the engine selects by its fixed name; and any free-form template invalidated the mockup without changing the PDF, because the signature sealed all the rows rather than only those used by the engine.

End-to-end verification

The final ticket covered the complete flow in Chromium, with a visual report and screenshots. Docker is not available on the local machine, so the flow was run over HTTP using temporary data (creating the Edition, uploading a .docx file, extracting it, and laying it out), and the critical test—that a rebuild would not lose anything that had been edited—was run on fxserver: the portada.html row was compared with the factory file, a test edit was made, the image was rebuilt, the row remained intact, and production was restored to its previous state. The complete Templates CRUD is now verified and live in production, backed by a source of truth that is no longer lost during rebuilds.