ADR-019: One View File per DB Model, One File per Report¶
Status: Accepted Date: 2026-08-27
Context¶
Every module's frontend contribution had grown into a single monolithic <Module>Views.ts file — sale/views/SaleViews.ts reached 892 lines covering four entities and two printable reports; propertymanagement's reached 708 lines covering six entities. Finding "the quote workflow" or "the rent receipt report" meant scrolling one large file mixing unrelated entities, with no filesystem structure mirroring the actual data model.
A real engine constraint surfaced first: ModuleRegistry.register() is idempotent by module name — a second register() call under an already-seen name is silently skipped, not merged. A naive split (each entity's file independently calling register() under the same module name) would silently drop every entity past the first discovered.
Decision¶
- One
<model>_views.tsper owned entity, onereports/<name>_report.tsper report. Each entity file holds its TypeScript interface,ViewDescriptors, and anyregister*side-effect calls. Reports live in areports/folder that is a sibling ofviews/, at the same leveli18n/already sits. - Exactly one file per module still default-exports the
FrontModule— a thin assembler,<module>_views.ts, importing routes/pieces each entity file exports and combining them into the single objectmodule.json'sstatic_files.viewslists. This is the only file the discovery script ever imports for that module; every entity file is reached from there by an ordinary import, invisible to discovery. This solves the registry-idempotency constraint with zero engine changes. - Two naming resolutions, applied consistently: a module with exactly one owned entity (e.g.
crm,contact) skips the separate assembler — its one file both declares the entity's pieces and default-exports theFrontModule. A module whose name collides with one of its own entities (e.g.cron'scronentity alongsidecron_history) lets that entity's file double as the assembler. A module owning zero entities (crminheritdemo, pure view-extension) names its one file after the module itself. - Route order across files must reconstruct the original order exactly — a module's landing tile opens
routes[0].path, and tile/menu ordering readsroutesin declaration order. Every assembler pulls the dashboard route into its own export (forced first) and preserves each entity's original relative order.
Consequences¶
- A new entity added to an existing module is a new file plus one import line in the assembler — never appended to a growing shared file.
module.json'sstatic_files.viewsnames only the assembler; adding an entity/report file never touches it.- Each module's test file stays one combined
<assembler>_views.test.ts— the split applies to source structure, not test structure. - A new module scaffolded by
tools/eerp-init-modulestarts in this shape directly.
Reference Implementation¶
core/modules/sale/views/sale_views.ts (assembler) + invoice_views.ts/sale_line_views.ts/ quote_views.ts/quote_line_views.ts + reports/invoice_report.ts/reports/quote_report.ts — applied identically across crm, contact, appstore, crminheritdemo, cron, propertymanagement, warehouse. core-front/packages/core-front/src/registry/registry.ts (ModuleRegistry.register()'s idempotent-by-name contract). See View Engine → Field Widgets, Creating a Frontend Module.