Architecture — Four Pillars

Constraint-driven extraction. Consent-based trust. Platform northstar. Tactical execution.

Source: MHS_PLATFORM_ARCHITECTURE_SPEC_v2.md (49KB) · CE_NOTE_2026-0210_ConsentaPlatformBrainstorm.json · CH-2026-0129-SOVEREIGNTY-001 · 42 D1 migrations

← Back to Consulting Handoff
Pillar I

Constraint-Based Architecture

The extraction engine doesn't use hardcoded prompts. It resolves constraints from a database, layered by scope. Adding a new extraction field or changing how a field is extracted requires zero code changes — only a row in prompt_specifications.

The Three-Tier Resolution

Every extraction prompt is assembled at runtime from constraints stored in the prompt_specifications table. Constraints resolve in a strict hierarchy:

Constraint Resolution Order
GLOBAL constraints        ← Platform-wide defaults (every tenant gets these)
  ↓ override / extend / disable
INDUSTRY constraints      ← Vertical-specific (construction, financial, CRM)
  ↓ override / extend / disable
TENANT constraints        ← Per-customer customization (PAD's specific fields)
  ↓
RESOLVED CONSTRAINT SET   → Passed to buildPromptFromConstraints()
  ↓                        → Generates Claude Vision API prompt
EXTRACTION RESULT         → Structured JSON matching the resolved fields

Each constraint row defines a field with its group (component, group, page, keying), data type, extraction instructions, validation rules, and sort order. Higher scopes can replace individual fields, add new ones, or disable inherited ones.

Why this matters

Traditional document extraction products hardcode their prompts. When a customer needs a new field (e.g., "panic hardware rating"), it's a code change, a deploy, and a prayer. In this architecture, it's an INSERT into prompt_specifications. The extraction engine resolves it automatically on the next run.

This is also the bridge to multi-vertical: construction fields live at industry scope. CRM fields live at a different industry scope. The engine is identical — only the constraints differ.

Implementation: resolveConstraints()

Located at hardware-schedule-extractor.js:2871. The function:

  1. Loads all scope_level = 'global' constraints from prompt_specifications
  2. Resolves industry_id from the tenant (if not explicitly provided)
  3. Applies scope_level = 'industry' overrides — merge, replace, or delete fields
  4. Applies scope_level = 'tenant' overrides — same merge logic
  5. Sorts by field_group and sort_order
  6. Returns the resolved constraint set with spec_version, scope_chain, and resolved_at

The resolved set is then passed to buildPromptFromConstraints() (:2983), which generates the Claude Vision API prompt. Every extraction is audited in constraint_executions with the prompt hash and input/output hashes for reproducibility.

The Schema: prompt_specifications

prompt_specifications (migration 022)
id TEXT PRIMARY KEY
spec_version TEXT NOT NULL         -- Schema version for backward compat
scope_level TEXT NOT NULL           -- 'global' | 'industry' | 'tenant'
  DEFAULT 'global'
industry_id TEXT                    -- NULL for global, industry code for industry scope
tenant_id TEXT                      -- NULL for global/industry, tenant ID for tenant scope
field_group TEXT NOT NULL           -- 'component' | 'group' | 'page' | 'keying'
field_name TEXT NOT NULL            -- e.g., 'manufacturer', 'fire_rating', 'panic'
field_type TEXT DEFAULT 'string'    -- Data type hint for extraction
extraction_instruction TEXT         -- Natural language instruction for the AI
validation_rule TEXT                -- Optional validation regex/rule
sort_order INTEGER DEFAULT 0        -- Ordering within group
active INTEGER DEFAULT 1            -- Soft delete
field_aliases TEXT                   -- Alternative names (migration 033)

SCHEDULE_TYPE_REGISTRY

The constraint architecture extends to schedule type routing. SCHEDULE_TYPE_REGISTRY in hardware-schedule-extractor.js maps detected document types to extraction functions, target tables, and constraint scopes. Adding a new document type is one registry entry plus the constraint rows for its fields.

Schedule TypeExtraction FunctionTarget TableStatus
hardware_scheduleextractFromPageImage()hardware_page_extractionsDEPLOYED
door_scheduleextractDoorSchedule()door_schedule_entriesDEPLOYED
electrical_panelextractGenericSchedule()hardware_page_extractionsEXTENSIBLE

Zero-Code Extensibility in Practice

Want to...Do thisCode changes?
Add a field to all extractionsINSERT into prompt_specifications with scope_level='global'Zero
Add a construction-specific fieldINSERT with scope_level='industry', industry_id='construction'Zero
Override a field for one customerINSERT with scope_level='tenant', tenant_id=customer's IDZero
Disable a field for one customerINSERT with active=0 at tenant scope (overrides global)Zero
Add a new document typeAdd entry to SCHEDULE_TYPE_REGISTRY + constraint rowsOne registry entry
↓ The constraint engine extracts data. The consent engine ensures nothing reaches production until a human agrees. ↓
↓ Constraints drive extraction. Consent governs trust. Together they form the substrate for a multi-vertical platform. ↓
Pillar III

Platform Northstar

MHS operates a B2B platform serving businesses across verticals. SubmittalExpress is the first product, skinned for construction. Consenta is the second, skinned for CRM/ERP. The platform underneath is the same — and it's 70% domain-agnostic.

Corporate Structure

MHS Holding Company
MHS (Holding Company)
├── WeylandAI (Construction Vertical)
│   ├── SubmittalExpress (Product — PAD customer)
│   └── TakeoffExpress (Product — quoting engine)
│
├── Consenta (CRM/ERP — Agreement Lifecycle)
│   ├── Consenta Docs ("Upload anything. Extract everything. Trust what matters.")
│   ├── Consenta Flow ("Approval workflows that remember everything.")
│   ├── Consenta Forge ("Beautiful documents from messy data.")
│   └── Consenta CRM ("The CRM that reads your documents.")
│
└── Quanticfork (RIA/Financial Vertical — future)

The Platform Audit: 70/15/15

An audit of weyland-worker.js (~14K lines) revealed the portability split:

Tier%WhatExamples
Direct carry70%Auth, projects, quotes, line items, audit log, templates, telemetryusers, projects, vendor_profile, takeoff_quotes, affirm_audit_log
Rename only15%Generic patterns with construction nameshardware_extraction_sessions → document_sessions, submittals → deliverables
Domain replace15%Construction-specific entities → CRM entitiesdoor_schedule_entries → extracted_entries, hardware_sets → entity_groups

Consenta: The Fork in Practice

Consenta (consenta.cc) is a 1:1 fork of Weyland with the construction skin replaced. Phase 1 (generic rename) is COMPLETE. Phase 2 (registry swap) is COMPLETE.

Weyland NameConsenta NameWhat It Actually Is
HGSEAIDE (AI Document Extraction)Upload → detect → affirm → extract → review → materialize
Affirmation BoundaryConsent EngineSeven-level hierarchical approval with immutable audit
Submittal AssemblerDocument ForgeAffirmed data + templates → branded PDF packages
CPS + Cut Sheet DiscoveryKnowledge BaseFTS5 reference library with AI-powered matching
Takeoff ExpressPricing & Quoting EngineMulti-source line items → grouped pricing → branded quotes
3-tier constraintsEnterprise Platform LayerGlobal → industry → tenant configuration without code
The brand thesis

Consenta (Latin "consentire" — to agree, to feel together). The Weyland platform's core innovation IS the affirmation boundary — nothing enters production until a human consents. This isn't a construction feature being dragged into CRM. It's a trust substrate that happens to be skinned as construction. Consenta makes the trust substrate the PRODUCT.

Viral Growth Model

The freemium sub-tenant model creates network effects:

Growth Flywheel
PAD (paying)  ——shares submittal——>  Smith GC (freemium sub-tenant)
                                            ↓
                                     experiences value
                                            ↓
                                       CONVERTS to paying
                                            ↓
Smith GC (paying) —shares submittal—> Jones Masonry (freemium sub-tenant)
                                            ↓
                                        [repeats]

Sub-tenants convert to peer clients with operational continuity — shared spaces and consent records persist across conversion. The business relationship encoded in data survives the commercial relationship change.

10 CRM Document Types (Consenta Phase 2)

The SCHEDULE_TYPE_REGISTRY pattern extends from 3 construction types to 10 CRM document types with zero extraction engine changes:

Document TypeExtracted FieldsStatus
invoicevendor, amounts, line items, dates, payment termsDEPLOYED
purchase_orderbuyer, seller, items, quantities, deliveryDEPLOYED
contractparties, terms, obligations, dates, amountsDEPLOYED
receiptmerchant, items, total, date, payment methodDEPLOYED
resumename, contact, skills, experience, educationDEPLOYED
business_cardname, title, company, phone, email, addressDEPLOYED
compliance_certissuer, holder, type, dates, scopeDEPLOYED
tax_formform type, TIN, amounts, period, filing statusDEPLOYED
shipping_manifestorigin, destination, items, weights, carrierDEPLOYED
insurance_policyinsurer, holder, coverage, limits, datesDEPLOYED

Each type uses the same constraint-driven extraction via extractWithConstraints, with 87 prompt_specifications rows defining the fields per document type. The extraction engine, affirmation boundary, materialization bridge, and document assembly pipeline are all reused without modification.

↓ The northstar is clear. What ships today? ↓
Pillar IV

Tactical Vision

"We built a telescope lens by lens, but never assembled the tube — the light never reaches the eyepiece." The pipeline works. The plumbing works. The critical path is connecting the data flows end-to-end for a customer demo.

What's Deployed Today

CapabilityTicketStatus
Project data model with billing metadata26GDEPLOYED
Vendor profile with branding26HDEPLOYED
Hardware set page generator26IDEPLOYED
Quote persistence + server-side PDF + line item edit26JDEPLOYED
Materialization bridge (DSE → hardware sets)26KDEPLOYED
Re-extraction with dual-card interlock26LDEPLOYED
Card-level re-extraction via region pipeline26MDEPLOYED
Quote HTML engine (CAPT pivot from pdf-lib)26NDEPLOYED
Shareable quote links with access tokens26ODEPLOYED
Project-scoped takeoff (cross-session aggregation)Pipeline Phase 1DEPLOYED
Bulk session link + backfill bridge + auto-linkPipeline Phase 2DEPLOYED
Project-scoped quote generationPipeline Phase 3DEPLOYED
CPS price-informed takeoff with pricing optionsCPS IntegrationDEPLOYED

The Pipeline End-to-End

Customer Workflow: PDF to Quote
UPLOAD              User uploads hardware schedule PDF
  ↓
DETECT              System detects schedule pages, creates extraction session
  ↓                (auto-links to project if name matches)
EXTRACT             Claude Vision API extracts per-page data using resolved constraints
  ↓
REVIEW              Frontend shows card-by-card extraction results
  ↓                (re-extract individual cards if needed — 26M)
AFFIRM              User affirms groups → materializes to hardware_sets/components
  ↓                (audit logged with entity snapshots)
DISCOVER            CPS catalogue + web search finds cut sheet PDFs
  ↓                (user affirms or rejects matches)
PRICE               Auto-pricing from CPS catalogue, user overrides, per-set pricing
  ↓
QUOTE               Generate branded HTML quote → headless Chrome → PDF
  ↓                (shareable link with access token — 26O)
ASSEMBLE            Submittal package: cover + TOC + schedule + set pages + cut sheets
  ↓
DELIVER             R2-stored PDF, download endpoint, quote history

Revenue Context

Business model

PAD paid $15K for the buildout. Customers lined up for monthly seat demos. $2K/month/seat validated by Andrew (PAD). The critical path is demo-ready: a customer uploads a hardware schedule, the system extracts → affirms → prices → generates a branded quote with cut sheets, all in one flow.

Production Data Status

ProjectSessionsDSE EntriesHW SetsQuotesStatus
One Camino Real (OCC)9 linked4217 (with pricing)#3 ($18,787), #8 ($24,787 project-scope)Demo-ready
Kaiser Sunset47 (35 door, 7 hardware)0 (never persisted)2 skeletal#1, #2 ($0)Needs session linking + backfill

What Ships Next

ItemWhyStatus
Extraction flow unification (Family 29)Three extraction paths (A, B, C) need unified entry point and consistent behaviorSPECIFIED
Orphan merge (29B)Cross-page continuation detection — hardware groups split across pagesSPECIFIED
Kaiser data recovery47 sessions with extraction data that never hit door_schedule_entriesNeeds investigation
Stripe integrationPayment as consent mechanism, sub-tenant conversion triggerPENDING
Sovereignty schema foundationuser_spheres + access_grants + consent_events tablesPENDING

Infrastructure

ComponentServiceDetails
WorkerCloudflare Workersweyland-worker.js (~14K lines), routes at api.weylandai.com
FrontendCloudflare Pagessubx.html (~1.1MB SPA), serves at subx.weylandai.com
DatabaseCloudflare D1weyland_db, 88+ tables, 42 migrations applied
StorageCloudflare R2Uploaded PDFs, generated submittals, quote PDFs, region renders
BrowserCloudflare Browser RenderingHeadless Chromium for quote HTML → PDF conversion
QueueCloudflare QueuesCut sheet discovery queue consumer
AIAnthropic API (Claude)Vision API for document extraction, constraint-driven prompts
Dev toolingHASCOM17 providers, 166 capabilities, 3,637 symbols, source reference
Reference

Source Documents

DocumentLocationCovers
Platform Architecture Spec v2.0Entity model, mutual consent, shared spaces, subscription tiers, compliance, viral growth
Consenta Platform BrainstormEngine abstraction map, product lines, fork plan, 10 CRM document types
Sovereignty Schema Foundationuser_spheres, access_grants, consent_events, default denial, payment as consent
Pipeline Unification StrategyThree disconnected data streams, project-scoped aggregation, 4-phase execution
Extraction Pipeline Sourceweylandai.com/handoff-product-sourceAll 5 pipeline files with exports and flow diagram
HASCOM Toolkit Sourceweylandai.com/handoff-hascom-sourceDeveloper tooling: core.py, analyzers.py, UAT framework
Infrastructure Configweylandai.com/handoff-infrastructurewrangler.toml, deployment routing, Cloudflare bindings