Organisation Field Config Loader
Component Detail
Description
Fetches and parses the JSON field configuration stored in Supabase that defines org-specific form fields. Supports adding custom fields per organisation without a code change by treating the JSON config as the sole source of field definitions. Shared with the Activity Type Configuration feature.
org-field-config-loader
Summaries
The Organisation Field Config Loader is a foundational capability that allows the platform to serve multiple client organizations with different data collection requirements without requiring a software release for each customization. When an organization needs an additional field on a report or activity form — a regulatory requirement, an internal audit field, or a client-specific attribute — the change is made in configuration data stored in Supabase, not in the application codebase. This dramatically reduces the cost and lead time of onboarding new clients or adapting to evolving compliance requirements. It also reduces operational risk by keeping custom form logic out of the core application, making the platform easier to maintain and less prone to regressions when new organizations are added.
The Organisation Field Config Loader is a shared dependency used by both the core reporting workflow and the Activity Type Configuration feature, meaning its stability and schema contract must be locked down early in the project timeline. Delivery risk is moderate: the primary complexity lies in agreeing on and validating the JSON schema for field definitions, as any ambiguity here will propagate into both consuming features. A formal field definition schema and validation suite should be delivered as part of this component's acceptance criteria before dependent features enter development. Testing must cover malformed JSON, missing org configs, and network failures — all of which require graceful fallback to default configurations.
Backend deployment of the Supabase config table structure should be coordinated with this component's delivery, as the loader cannot be integration-tested without it.
Organisation Field Config Loader abstracts the Supabase config table behind a typed interface with three entry points: `loadConfig(orgId, formType)` performs the authenticated fetch and returns a parsed field definition array, `parseFieldDefinitions(json)` handles deserialization and type coercion of raw JSON into strongly-typed field descriptor objects, and `getDefaultConfig(formType)` provides a hard-coded fallback when the remote config is absent or invalid. The component is registered as shared across mobile and backend execution contexts, meaning the same interface contract must be satisfied in both environments — consider an abstract base or interface type with platform-specific transport implementations. Caching fetched configs for the session duration is strongly recommended to avoid redundant Supabase reads on every form render. The `report-field-schema` data model is the authoritative schema for field definition shape; any changes to that model must be reflected here.
Consumers should treat the returned field array as read-only and never mutate it, as the loader may return a cached reference.
Responsibilities
- Fetch JSON config from Supabase config table by org ID and form type
- Parse and return typed field definition array
- Handle missing or malformed config gracefully with fallback defaults
Interfaces
loadConfig(orgId, formType)
parseFieldDefinitions(json)
getDefaultConfig(formType)
Relationships
Dependents (2)
Components that depend on this component
Related Data Entities (1)
Data entities managed by this component