Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
7.6 KiB
PRD — Invoice Template Transforms Designer
- Slug:
invoice-template-transforms-designer - Date:
2026-03-08 - Status: Draft
Summary
Add a first-class Transforms authoring surface to the invoice template editor so billing admins can shape invoice collection data before it is rendered. V1 is aggregation-first: support filter, sort, group, and aggregate on any collection binding, with live output preview and dynamic-table binding to transformed output. The current generated JSON code view remains read-only.
Problem
The invoice template AST already supports collection transforms, but the visual template editor cannot author or preserve them. Users who want aggregated invoice rows, grouped lists, or shaped output for tables have no supported path to create that behavior in the UI. Saving through the visual workspace currently drops templateAst.transforms, which makes the feature effectively unavailable to non-engineers and unsafe even for manually patched templates.
Goals
- Let template authors create transform pipelines visually without editing AST JSON.
- Preserve authored transforms through load, preview, save, and reopen flows.
- Support the main invoice use case of rolling up repeated line items into grouped or aggregated rows.
- Let layout components, especially dynamic tables, bind to transformed output collections.
- Show enough source/output data preview that users can understand what their pipeline is doing.
Non-goals
- Editable raw AST or editable full-code authoring in v1.
- Exposing every AST transform operation in v1.
- Introducing multiple independent transform pipelines per template.
- Redesigning the existing design canvas or authoritative preview pipeline beyond what is needed to support transforms.
- Adding observability, metrics, rollout flags, or operational tooling beyond normal error handling.
Users and Primary Flows
Primary user
- Billing admin or template author configuring invoice templates for tenant-specific invoice presentation.
Primary flows
- Open an existing template, switch to
Transforms, choose a source collection, and build a pipeline that groups and aggregates invoice items. - Inspect the transformed output preview, then switch back to
Designand point a dynamic table at the transform output binding. - Save the template, reopen it later, and continue editing without losing transform configuration.
- Use
Previewto verify the full rendered invoice honors the configured transforms.
UX / UI Notes
- Add a top-level
Transformstab besideDesignandPreview. - The transforms tab should have four areas:
- source data panel
- transform pipeline panel
- selected transform inspector
- output preview and table-binding summary
- Keep responsibilities separate:
Designedits layoutTransformsedits collection shapingPreviewverifies rendered output
- The code tab remains generated/read-only and should display the authored
transformsblock when present. - The source/output panels should prefer guided selection and previews over free-text path entry wherever practical.
Requirements
Functional Requirements
FR-001Add aTransformstab to the invoice template editor without regressing existingDesignandPreviewflows.FR-002Represent transform authoring state as first-class visual workspace data so it can be edited, exported, and saved.FR-003Import existingtemplateAst.transformsinto workspace state when loading a template.FR-004Export workspace transforms back intotemplateAst.transformswhen generating AST for preview and save.FR-005Preserve templates that have no transforms; opening and saving them must remain safe.FR-006Let the user select any collection binding as the source collection for the transform pipeline.FR-007Show source collection metadata including binding ID, row count, and discovered fields using sample preview data when available.FR-008Let the user add, reorder, duplicate, and delete transform operations within a single ordered pipeline.FR-009Support authoringfilteroperations.FR-010Support authoringsortoperations.FR-011Support authoringgroupoperations.FR-012Support authoringaggregateoperations.FR-013Let the user define an output binding ID for the transform pipeline.FR-014Show a live output preview that reflects the transformed binding shape, including grouped rows and aggregate values.FR-015Let dynamic-table layout nodes bind to the transformed output collection instead of only raw source collections.FR-016Expose transformed row paths in table column binding/mapping UI so grouped outputs can be rendered without manual path guesswork.FR-017Prevent or clearly reject illegal transform sequences in the UI before save where the AST evaluator would fail.FR-018Surface AST validation/evaluation issues in the transforms tab in a way that points to the offending transform.FR-019Ensure the authoritative preview path compiles and renders templates with transforms.FR-020Show the generatedtransformsblock in the read-only code tab.FR-021Preserve transforms through reopen/save round-trips so visual editing no longer strips the AST transform block.
Non-functional Requirements
NFR-001Export/import behavior must remain deterministic for stable round-trip tests.NFR-002Existing templates and previews must continue to work when no transforms are configured.NFR-003V1 must use the existing invoice template AST schema and evaluator contracts; no AST wire-format migration is required.NFR-004Transform authoring should favor guided controls over raw string editing for common operations.
Data / API / Integrations
- Use the existing
templateAst.transformsstructure already defined in the invoice template AST schema. - Extend the designer workspace/store snapshot to carry:
- source binding ID
- output binding ID
- ordered transform operations
- Reuse existing preview inputs and authoritative preview actions; do not introduce a new backend API for transform authoring.
- Dynamic-table authoring must be able to reference the transform output binding and transformed row paths.
Security / Permissions
- No new permission model is introduced.
- Existing invoice template edit permissions continue to govern access to
Design,Transforms,Preview, and save behavior.
Observability
- No new observability scope is included in v1 beyond normal client/server error surfacing in the editor and preview pipeline.
Rollout / Migration
- No data migration is required because the AST schema already supports transforms.
- Existing templates without transforms remain valid and unchanged.
- Templates that already contain
transformsshould begin round-tripping safely once import/export support lands.
Open Questions
- Future v2 question: whether to expose
computed-fieldandtotals-composein the GUI after the aggregation-first surface is stable. - Future v2 question: whether to add a limited advanced editor for the
transformsblock only.
Acceptance Criteria (Definition of Done)
- A template author can create a transform pipeline in the editor using guided UI controls.
- A template author can group and aggregate invoice rows and see the transformed output before saving.
- A dynamic table can bind to the transformed output binding and render grouped/aggregated rows in preview.
- Saving and reopening a transformed template preserves the authored transform pipeline.
- Existing non-transformed templates remain unaffected.
- The read-only code tab reflects the generated
transformsblock for transformed templates.