Clause Engine Core
Relevant source files
The following files were used as context for generating this wiki page:
The Clause Engine Core is the central logic hub of Comply-Quick, responsible for evaluating technical stack inputs and mapping them to protective legal text. It functions as a conditional evaluation matrix that consumes user-provided data regarding tech frameworks, tracking pixels, and target jurisdictions to generate a comprehensive "Compliance Package."
The engine's scope includes generating liability-shifting contract shields, consumer-facing privacy addendums, and engineering pre-launch checklists. It also integrates with enterprise-grade compliance modules to provide advanced coverage for regulated industries such as healthcare and finance.
Sources: src/components/ClauseEngine.tsx:1-10, src/app/page.tsx:120-140
Architecture and Data Flow
The Clause Engine operates as a pure functional pipeline within generateCompliancePackage. It takes a ComplianceInput object and executes a series of transformations to produce a CompliancePackage.
Core Data Structures
| Type | Description | Key Fields |
|---|---|---|
ComplianceInput | Input parameters from the UI wizard or API. | userType, framework, trackingPixels, targetRegions, complianceModules |
InwardContractShield | Legal clauses shifting liability between parties. | preamble, clauses |
PrivacyPolicyAddendum | Technical disclosures for consumers. | header, scriptDeclarations, regionalDisclosures |
CompliancePackage | The final aggregate output object. | inwardContractShield, consumerPrivacyPolicyAddendum, developerPreLaunchChecklist, complianceScore |
Sources: src/components/ClauseEngine.tsx:18-63
Generation Logic Flow
The following diagram illustrates how input data is processed through the engine's internal mapping blocks.
The engine utilizes a deterministic mapping strategy, where specific constants (e.g., FRAMEWORK_LIABILITY_CLAUSES, PIXEL_SCRIPT_DECLARATIONS) act as the source of truth for generated text based on keys derived from the input.
Sources: src/components/ClauseEngine.tsx:325-365, src/lib/autopilot/pipeline.ts:77-85
Functional Components
Inward Contract Shielding
This component generates a legal agreement between a Developer and a Merchant. It selects a preamble based on the userType to define the relationship and injects framework-specific liability clauses (e.g., "Platform Dependency Disclaimer" for Shopify or "Plugin Ecosystem Liability Exclusion" for WordPress).
Sources: src/components/ClauseEngine.tsx:67-150
Consumer Privacy Addendum
Maps active tracking pixels to standardized script declarations. For example, selecting the meta pixel triggers a declaration regarding fbevents.js and cross-platform profiling. It also appends regional disclosures for jurisdictions like eu_gdpr (GDPR) or california_ccpa (CCPA).
Sources: src/components/ClauseEngine.tsx:180-215
Compliance Scoring Engine
The calculateComplianceScore function produces a weighted average across four categories to determine the overall package strength:
- Contract Protection (25%): Based on the density of liability clauses.
- Privacy Coverage (25%): Evaluates pixel declarations and module depth.
- Pre-Launch Readiness (25%): Measures checklist comprehensiveness.
- Regulatory Breadth (25%): Scores the number of covered jurisdictions.
Sources: src/components/ClauseEngine.tsx:369-405, src/tests/ClauseEngine.test.ts:167-200
Enterprise Integration
The engine optionally consumes ComplianceModule identifiers to trigger the generateModuleOutputs function in EnterpriseModules.tsx. These modules provide deep-domain coverage for specific regulatory frameworks.
| Module | Purpose | Key Content |
|---|---|---|
hipaa | Healthcare Protection | BAA requirements, PHI encryption standards, audit logging. |
pci_dss | Payment Security | CDE scope limitation, PAN tokenization, vulnerability management. |
ada_wcag | Web Accessibility | WCAG 2.2 AA conformance, Assistive Tech compatibility. |
soc2 | Security Controls | Logical access, change management, system operations. |
Sources: src/components/EnterpriseModules.tsx:12-150, src/tests/EnterpriseModules.test.ts:7-40
Implementation Details
Validation Logic
Before processing, the engine validates all inputs against VALID_USER_TYPES, VALID_FRAMEWORKS, VALID_PIXELS, and VALID_REGIONS. If an unsupported value is detected, it throws an error to prevent malformed package generation.
Sources: src/components/ClauseEngine.tsx:298-323
Exporting and Serialization
The engine provides an exportToMarkdown utility that converts the CompliancePackage object into a formatted Markdown report. This report includes:
- An overall compliance score.
- The mandatory legal disclaimer: "This package is informational only. Consult a legal professional before deployment."
- Structured sections for the Shield, Addendum, and Checklist.
- A score breakdown table.
Sources: src/components/ClauseEngine.tsx:431-505, src/lib/legal.ts:12-15
Conclusion
The Clause Engine Core serves as the technical foundation for the Comply-Quick platform. By decoupling legal content into a structured mapping matrix and providing a deterministic scoring mechanism, it allows the application to scale support for new frameworks and regulations without modifying the core generation pipeline. Its strict adherence to TypeScript types and modular design ensures that compliance packages remain consistent and technically accurate across different deployment environments.