Documents

Document templates and document requests for building renovations. Admins define reusable templates organized by labels and categories; document requests track which documents are needed for a specific project or building.

Source Files

LayerPath
Schemabackend/src/db/schema.ts
Request Routesbackend/src/routes/document-requests.ts
Template Routesbackend/src/routes/admin/document-templates.ts, template-labels.ts, label-categories.ts, priority-rules.ts, template-files.ts
Request Servicebackend/src/services/document-request-service.ts
Template Servicebackend/src/services/document-template-service.ts + backend/src/services/document-template/

Database Tables

TablePurpose
documentRequestsTracks individual document needs per project (status, assignee, due date)
documentTemplatesReusable definitions of document types — key, bilingual name/description/notes (LocalizedText jsonb), optional formId (Forms) and flowDefinitionId
flowDefinitionsStandard flow types a template can use (default modal configuration)
documentTemplateLabelsTags/labels for organizing templates
documentTemplateLabelCategoriesGroupings for labels (e.g., “Building Type”, “Funding Body”)
documentTemplateToLabelsTemplate ↔ label junction (m:n)
documentTemplatePriorityRulesPriority matrix — priority per parameter value, optionally scoped to a workflow template/task
documentTemplateFilesMetadataSupporting files attached to a template (CAS fileIdFiles; replaceable/downloadable/required flags)

Key Concepts

  • Templates define what a document is (e.g., “Energy Certificate”, “Floor Plan”). Admins manage templates, labels, categories, priority rules, and template files via the admin panel. Bilingual fields use the LocalizedText jsonb pattern.
  • Requests are instances tied to a project: “We need document X for project Y.” Each request tracks status, assignee, and fulfillment.
  • Labels & categories provide a two-level taxonomy so templates can be filtered and grouped in the UI.
  • Template files go through CAS (Files); per-request overrides live in documentObtainingRequestFiles (see Document Obtaining).

Config data, not mocks: document templates, priority rules/filters, and forms were baselined from staging into local/preview/development via an Atlas migration (PR#1789). They are config data shipped by migration — the mock loader no longer touches them.

Relationships

DocumentTemplate 1──* DocumentRequests
DocumentTemplate *──* DocumentTemplateLabels (via documentTemplateToLabels)
DocumentTemplateLabel *──1 DocumentTemplateLabelCategory
DocumentTemplate 1──* DocumentTemplatePriorityRules
DocumentTemplate 1──* DocumentTemplateFilesMetadata ──1 Files
DocumentTemplate *──1 Form (optional)
DocumentRequest *──1 Project

Workflow

  1. Admin creates templates, labels, and priority rules in the admin panel
  2. When a project starts, relevant document requests are created (manually or via Document Obtaining / the workflow task factory)
  3. Requests are assigned to team members or sent to customers via Portal
  4. Customers or staff upload Files to fulfill the request (canonical collection chain, PR#2005)
  5. Fulfilled documents go through Document Review

Frontend

Document requests appear on the project detail page and inside the Document Obtaining dashboard. The admin template management lives at frontend/src/pages/admin/ alongside Forms and other configuration pages.

Document Obtaining | Document Review | Files | Portal | Forms | Projects | Buildings | Admin Dashboard | Service Layer Pattern