Proprietary — Uued Viljapuuaiad OÜ / Code Zero Group — All Rights Reserved
Nexus — Engineering
v1.1.0 2026-03-25 Branch: feature/pfp-pyrometrix

Architecture

Core architectural tenets, table schema, runtime component diagram, multi-domain design, DataSource architecture, and known technical debt register. All tenets are derived from EDRv6 and are non-negotiable — violating them introduces state that cannot be versioned, audited, or switched at runtime.

6 Tenets 3 Active Domains 8 Open Debt Items
01 Core Tenets
Tenet 1 — Rules live in the database, not in files.

Rules are rows in _tbl_calcrule_rules, grouped by profile in _tbl_calcrule_profiles. JSON files under nexus/rules/ are the one-time migration seed only. Once imported they are not the source of truth.

  • Changing a rule means an UPDATE to _tbl_calcrule_rules, not editing a file.
  • Profiles are versioned rows; old profiles are never deleted, they are superseded by a new row with a higher version.
  • Derived from EDRv6: _tbl_sys_rules, _tbl_sys_classes, _tbl_sys_properties.
Tenet 2 — Active Profile is database state, not a code constant.

_tbl_calcrule_profiles.is_active = 1 is the single toggle within a domain. The Flask admin panel flips it; the FastAPI engine reads it on every request. Domain scope is mandatory — activating the EDR profile must not deactivate the TCO profile. The domain column enforces this isolation.

UPDATE _tbl_calcrule_profiles SET is_active = 0 WHERE domain = 'edr';



UPDATE _tbl_calcrule_profiles SET is_active = 1 WHERE id = <target>;
Tenet 3 — Table naming follows the EDRv6 convention.
LayerPrefixExample
Source rawsrc_src_excel_rules
Stagingstg_stg_calcrule_import
Master/Dimensiondim_dim_technology
System/Meta_tbl_<domain>_<entity>_tbl_calcrule_profiles
Tenet 4 — No mocking. No stubbing. No simulating.

Every component runs against the real database. Tests use a real SQLite file in a temp directory, not in-memory mocks. If a rule does not exist in the DB, it does not exist.

Tenet 5 — Runtimes are interchangeable consumers of the same profile API.

All runtimes (browser, Python standalone, Databricks, Snowflake) consume /api/profiles/active. They do not load rules independently. Any runtime that reads rules from a file is in violation of Tenet 1.

Tenet 6 — Authentication is mandatory on all compute and write endpoints.

Every endpoint that executes rules, reads profiles, writes rules, or accesses datasource connectors must require a valid X-API-Key header. There is no "internal" or "trusted" endpoint that bypasses authentication. Read-only GET profile endpoints tolerate unauthenticated access only in air-gapped local dev environments — never in any networked deployment.

Current implementation: require_api_key dependency in nexus/auth.py. Target: per-key RBAC with expiry and scope constraints (see GAP-02).

02 Table Schema Reference
CREATE TABLE _tbl_calcrule_profiles (



    id                  INTEGER PRIMARY KEY,



    slug                TEXT UNIQUE NOT NULL,          -- machine name e.g. tco-dc-cooling



    name                TEXT NOT NULL,                 -- display name



    description         TEXT,



    technology_variants TEXT DEFAULT '[]',             -- JSON array



    domain              TEXT NOT NULL DEFAULT 'tco',  -- bounded context: tco / edr / pfp



    is_active           INTEGER NOT NULL DEFAULT 0,   -- active within domain only



    version             TEXT DEFAULT '1.0.0',



    created_at          DATETIME,



    updated_at          DATETIME



);







CREATE TABLE _tbl_calcrule_rules (



    id             INTEGER PRIMARY KEY,



    profile_id     INTEGER NOT NULL REFERENCES _tbl_calcrule_profiles(id),



    rule_id        TEXT NOT NULL,                -- e.g. infra_001_servers_per_rack



    name           TEXT NOT NULL,



    formula        TEXT NOT NULL,



    output         TEXT,



    rule_type      TEXT,                         -- infrastructure / capex / opex / tco / scoring



    technology     TEXT,                         -- NULL = applies to all technologies



    priority       INTEGER DEFAULT 0,



    enabled        INTEGER NOT NULL DEFAULT 1,



    excel_source   TEXT,



    excel_baseline REAL,



    description    TEXT,



    created_at     DATETIME,



    updated_at     DATETIME,



    UNIQUE (profile_id, rule_id)



);

See Data Model for the full schema including target tables (_tbl_calcrule_rule_audit, _tbl_api_keys) and PFP rule JSON schema.

03 Runtime Architecture
Browser / Revit Plugin / CLI



  ├── GET  /ui/index.html       (SPA — Calc, Rules, Graph, Inspector tabs)



  ├── GET  /api/profiles/active ──────────────────────────────────────┐



  ├── POST /pfp/clearance                                              │



  ├── POST /pfp/select                                                 │



  ├── POST /api/profiles/{key}/run                                     │



  └── PATCH/DELETE /rules/{id}  (auth-gated write ops)                │



                                                                       │



FastAPI Engine (port 8010 prod / 8012 dev)                            │



  ├── nexus/api/app.py              (22 routes)                     │



  ├── nexus/api/routes_rule_editor.py (7 routes)                   │



  ├── nexus/core/profile_store.py   (SQLite read) ◄──────────────┘



  ├── nexus/core/pfp_pipeline.py    (formula pipeline)



  ├── nexus/core/pfp_table_pipeline.py (table pipeline)



  ├── nexus/core/dynamic_rule_engine.py (TCO/EDR)



  ├── nexus/core/edr_pipeline.py



  ├── nexus/core/ingestion_pipeline.py + datasource.py



  └── ui/index.html  (mounted at /ui/ as StaticFiles)







Flask Admin (port 8011)



  ├── admin/models.py   (Profile, CalculationRule SQLAlchemy models)



  ├── admin/admin.db    (SQLite — shared with FastAPI via filesystem)



  └── admin/seed_pfp.py (PFP profile seeder — import format only)







Dockerised stack (docker-compose.yml)



  ├── nexus-engine  → FastAPI (port 8010)



  └── nexus-admin   → Flask admin (port 8011)

The FastAPI engine reads the SQLite file directly (no Flask context required) via profile_store.py, which uses a plain sqlite3 connection. This avoids a circular dependency between the two services while keeping both pointing at the same DB file.

The SPA (ui/index.html) is a single-file Vanilla JS ES2020 application served as static files. It has no build pipeline. All JS modules (Settings, Profiles, Rules, Calc, Inspector, Graph, Tabs) are IIFE-scoped within the file.

04 Profile Switch Protocol
  1. Admin panel marks new profile active (flips is_active within domain).
  2. Activate route filters by domain: WHERE domain = ? before flipping flags.
  3. FastAPI reads the active profile by domain on every request: WHERE domain = ? AND is_active = 1.
  4. No server restart required.
  5. Old profile remains in DB for rollback.
05 Multi-Domain Architecture

Nexus is a multi-domain platform. Each domain is a bounded context with its own profile, connectors, entity types, and API execution endpoints. Profile is_active is scoped to domain — activating a PFP profile does not affect the TCO or EDR domains.

Domain: tco
Profiletco-dc-cooling — 229 rules post-cleanup, v2.4.0
ConnectorYAML baseline + Excel seed
EndpointsPOST /execute, POST /api/profiles/tco/run
EntityCalculationContext (server, rack, financial, technology)
Technologiestraditional, rdhx, dlc, grc
OutputCAPEX, OPEX, TCO by technology variant
Domain: edr
Profileedr-entity-validation — 19+ rules, v1.0.0
ConnectorAccess database → FACT tables (via datasource.py + ingestion_pipeline.py)
EndpointsPOST /edr/validate, POST /edr/validate/batch, POST /ingest
EntityEngineeringEntity (tag, class, attributes, properties)
Outputquality_tier, completeness_score, violations array
Domain: pfp — Added 2026-03 (feature/pfp-pyrometrix)
Profilespfp-clearance-hdb (535 formula rules), pfp-table (430 table rows)
Rule filesnexus/rules/pfp/clearance_hdb.json, clearance_fs.json, table_hdb.json, table_fs.json
EndpointsPOST /pfp/clearance, POST /pfp/select, POST /pfp/sza, POST /api/profiles/pfp_table/run
ClientPyrometrix Ltd (Revit plugin integration)
Tests62 dedicated PFP tests (24 formula + 38 table) — all passing
Outputclearance_mm, top_mm, side_mm, bottom_mm, error, product_code
06 DataSource Architecture

Two separate datasource systems exist in Nexus and do not currently interact.

System 1 — Connector Layer

nexus/core/datasource.py + ingestion_pipeline.py. Connects to external systems to extract entity rows for EDR validation. Supports: SQLite, CSV, JSON, Excel, Access (.accdb), PostgreSQL, ODBC, REST API. Configured via YAML files in nexus/config/datasources/. Fed through IngestionPipelineEDRPipeline. Not rule-aware.

System 2 — Rule Store

nexus/core/profile_store.py. Reads calculation rules from admin/admin.db (_tbl_calcrule_rules). Supplies rules to all execution pipelines (TCO, EDR, PFP). Uses plain sqlite3, not the connector layer.

Immutability Contract

  • DataSources supply immutable read snapshots to rule execution — they are never written to during a pipeline run.
  • Rule definitions are immutable at execution time — loaded once, applied, then discarded.
  • Rule outputs are variant and engine-mediated — they cannot be read from cache as if they were reference data.

Target Architecture

Bridge the two systems. profile_store.py gains a configurable backend; when the NEXUS_RULE_STORE env var points to a remote DB (or DeltaPrism graph engine), rules are sourced from there rather than the local SQLite. No changes to the rule execution engine or API surface required.

07 Known Architectural Debt
IDItemDescriptionStatus
AD-01is_active domain scopeSingle boolean across all profilesFixed M-03
AD-02Standalone HTMLnexus-tco-standalone.html baked ALL_RULESFixed 2026-03-24
AD-03BaseConnector informalYAML/JSON connector not a BaseConnector subclassOpen — M-03
AD-04Formula sandboxeval() in restricted namespace — not production-safe for cloudOpen — M-05
AD-05Auth gaps18 of 22 routes unauthenticatedP0 — GAP-01
AD-06Single shared keyNo RBAC, no expiry, no per-client identityP1 — GAP-02
AD-07Rule source driftJSON files and DB can drift; seeding may contaminateP1 — GAP-04
AD-08No audit trailPATCH/DELETE leave no history — critical in fire-safety domainP1 — GAP-05
AD-09SQLite not HAadmin.db on disk — instance termination loses all rule editsP2 — GAP-09
AD-10DeltaPrism migrationRules are graph nodes; SQLite flattens relationshipsFuture