ARCHITECTURAL PLAYBOOK THE 7 PILLARS

Engineering Standards for Chemical X

AI models do not just need more context; they need strictly bounded context. These 7 pillars eradicate context rot, prevent phantom imports, and keep Claude, Gemini, Antigravity, and Cursor fully reliable.

$npx chemx auditFree Local AST Audit • Zero Upload
STATIC ANALYSIS ENGINE · 7 PILLARS

The 7 Pillars of Molecular Architecture

Every AST hazard check executed locally in under 5 seconds by the Chemical X auditor. Guarantees single-purpose files, reduces context token burn, and eliminates LLM hallucinations.

Pillar 1: File Line Budget (< 500 LOC)

LINE_BUDGET_FILE

Calibrated 3-tier sliding scale: Warning (500-999), Severe (1000-1999), and Extreme (2000+) monoliths.

Hazard: Files > 500 lines
Decompose into crystalline domain capsules (< 100 LOC)

Pillar 1: Molecule Capsule Limit (< 100 LOC)

LINE_BUDGET_MOLECULE

Enforces strictly single-purpose UI capsules with declarative bindings and zero business logic bloat.

Hazard: Molecules > 100 lines
Split into focused sub-molecules or extract state to hook

Pillar 2: Two-Stage Atomic Booleans

CONTROL_FLOW_INLINE_BOOLEAN

Catches multi-clause inline logic: single-concept atomic booleans composed into unified decisions.

Hazard: > 2 logical operators inline
Stage 1 concepts -> Stage 2 unified computed decisions

Pillar 2: Zero Nested Ternaries

CONTROL_FLOW_NESTED_TERNARY

Eliminates nested conditional branches that cause AI hallucination and logical degradation.

Hazard: Nested ? : branches
Extract display states to computed descriptor objects

Pillar 3: Composable Destructuring Contract

HOOK_SATURATION

Limits hooks to 3-5 return properties; flags components importing more than 5 individual hooks.

Hazard: > 5 hooks in one scope
Group related state into dedicated domain composables

Pillar 4: Domain Type Co-Location

TYPE_COLOCATION

Prohibits type monoliths; mandates co-located types/*.d.ts capsules (< 100 LOC) per feature.

Hazard: Anonymous types > 3 fields or global dumps
Define co-located domain contracts in types/*.d.ts

Pillar 5: 4-Tier Zero-Inline-Style & Anti-Tailwind-Soup

RAW_INLINE_STYLE

Prohibits raw inline styles and long utility chains (> 4-5 classes); mandates Level 1 atom props or scoped classes via @apply or mixins.

Hazard: Inline styles or long utility soup
Decouple into Level 1 atom props or scoped classes with @apply

Pillar 6: Self-Cleaning Lifecycle Timers

TIMER_DISCIPLINE

Detects raw setInterval or setTimeout calls lacking automatic unmount disposal.

Hazard: Unmanaged intervals and timer leaks
Wrap timers in onScopeDispose self-cleaning hooks
CHAPTER SPECIFICATIONS

Explore the 7 Chapter Specifications

Expand each chapter below to inspect key architectural takeaways, clean molecular code patterns, and common monolith traps.

Every entity in the codebase has a single, indivisible molecular responsibility. Keep top-level views under 20 lines reading like a Table of Contents.

Quantum Architectural Rules & Code Locked

To protect our competitive edge, full code patterns and copyable AGENTS.md rules for Chapter 1 are reserved for Vault members.

PRODUCTION BLUEPRINTS & RULES

Unlock the Complete Vault & Agent Directives

Get unrestricted access to the complete 7-chapter specification, ready-to-use .cursorrules, AGENTS.md, CI pre-commit gates, and the private starter repository.

Book Live Onboarding ($150)
CORE MECHANISMS THE FOUR RUNTIME PRIMITIVES THAT ACTUALLY MATTER

Engineered for Machine Cognition

Deterministic architecture and runtime intelligence engineered for autonomous coding agents. Chemical X isolates the exact mechanical guardrails models need to operate without context rot or prompt fatigue.

PILLAR 01 Fast SQLite WAL Symbol Retrieval

AST Symbol-Index vs. Context Dumps

$ chemx q <symbol> --inspect

Don’t force LLMs to grep blindly or dump 600-line files into prompt windows. Chemical X builds an in-memory SQLite WAL index (.chemx/index.db). Agents resolve symbol signatures, export boundaries, and hook dependencies in sub-100ms for ~30 tokens.

  • ✓In-memory SQLite WAL mode indexation
  • ✓Sub-100ms symbol signature extraction
  • ✓Transitive caller & hook dependency graphs
// 28 Tokens Ingestion (vs 2,400 raw LOC)
$ chemx q useCheckout --inspect
Symbol: useCheckout (Composable)
Exports: [isUnlocked, openCheckout, lockAccess]
File: src/composables/useCheckout.ts (48 LOC)
Transitive Callers: [AppHeader, FunnelOfferSection]
PILLAR 02 AST Guardrails Against AI Code Decay

Syntactic AI Slop & Code Decay Detection

$ chemx audit --slop

Standard linters only check syntax; Chemical X detects when an LLM writes hallucinated or degrading code. Catches conversational chat residue, echo comments, shallow paranoia try/catches, and lazy truncation placeholders before they reach git.

  • ✓Flags conversational residue & chat preambles
  • ✓Catches shallow empty catch {} and echo comments
  • ✓Blocks lazy '// ...rest of code' truncation placeholders
// AST Slop Prevention in Pre-Commit
✖ AI Slop Detected in src/views/dashboard.vue:
  Line 42: Conversational residue comment
  Line 88: Lazy truncation placeholder "// ..."
  Line 114: Shallow empty try/catch block
Result: Commit blocked before hitting git.
PILLAR 03 Zero Prompt Fatigue for Autonomous Agents

Single-Permission MCP Master Gateway

$ chemx({ action, params })

Eliminate tool sprawl and continuous permission prompts. Instead of configuring 14 disparate MCP tools, Chemical X exposes AST queries, surgical line patching, and silent verification through a single consolidated tool gateway.

  • ✓1-time MCP approval for the entire agent toolchain
  • ✓Surgical line-bounded patching (chemx patch)
  • ✓Zero-config integration for Claude Code, Cursor & Cline
// Single Master Tool Gateway (Zero Permission Spam)
await mcp.callTool("chemx", {
  action: "patch",
  params: {
    path: "src/atoms/Button.vue",
    lines: "12-28",
    replacement: "<button :class='atomClasses'>..."
  }
});
PILLAR 04 99.7% Context Conservation in CI & Agents

Silent Closed-Loop Verification & Telemetry

$ chemx verify

Stop blasting 15,000+ tokens of raw compiler logs into agent context windows. Chemical X orchestrates AST validation, TypeScript typechecks, and tests into a token-budgeted 45-token receipt, surfacing failure diffs only when code breaks.

  • ✓Compacts 17,000 tokens of noisy logs down to ~45 tokens
  • ✓Automated PR token cost & telemetry tracking
  • ✓Isolated failure-diff injection on test breaks
// Silent Verification Receipt (45 Tokens vs 17,200)
$ chemx verify
✔ AST Architecture: Clean (0 hazards, Grade A)
✔ TypeScript Check: Clean (0 errors across 48 files)
✔ Vitest Suite: 18 passed (214ms)
Token Telemetry: 45 tokens ingested | $0.0001 est.
Status: Pipeline verified green.
AGENT INFRASTRUCTURE SWARM COORDINATION & PROTOCOL

Master MCP Gateway & SQLite Concurrency

Beyond search and passive memory: Chemical X provides active multi-agent concurrency leases and closed-loop verification for autonomous development teams.

SINGLE PERMISSION

Master MCP Gateway (chemx)

Eliminates per-tool confirmation prompts. A single chemx({ action, params }) call gives agents verified file patching, AST querying, line slicing, and test execution without prompt fatigue.

Zero context leaks • In-band RPC
SWARM SAFETY

SQLite Concurrency & File Leases

Dedicated file_leases and file_lock_queue SQLite tables in WAL mode prevent race conditions when multiple autonomous agents edit the same repository simultaneously.

Zero context leaks • In-band RPC
DEFEAT FAKE COMPLETION

Closed-Loop Gated Verification

When an agent reports a task 'Done', Chemical X automatically re-runs the rule against the AST. Completion is strictly rejected unless the violation is provably eliminated.

Zero context leaks • In-band RPC
SYSTEM ARCHITECTURE END-TO-END AGENT PROTOCOL

The 7 Layers of Chemical X

Chemical X is not a single CLI or scaffolder. It is an architecture-and-tooling protocol that makes software legible, bounded, and mechanically verifiable to AI coding agents.

Layer 1 of 7 FOUNDATION

Architecture Layer

The 7 Molecular Pillars
Core Thesis

Software shaped like small, independently understandable molecules rather than giant monoliths.

Enforces hard file bounds (<500 LOC), capsules (<100 LOC), TOC views (<20 LOC), and 2-stage atomic booleans.

Impact on AI Agents

Narrows the working context an agent holds in memory, eliminating hallucinated state mutations.

→ 7 Pillars Specification • .cursorrules • AGENTS.md

Mechanical Enforcements & Deliverables

  • ✓< 500 LOC file ceiling (< 100 LOC capsules)
  • ✓< 20 LOC top-level TOC views
  • ✓Two-stage atomic booleans with early guards
  • ✓Composables returning 3-5 properties max
  • ✓[data, error] = await toResult(...) tuples

How to Adopt Chemical X: The 3-Step Loop

Free Instant Audit → Agent MCP Loop → Full Vault Blueprint
1. Free AST Audit

Run npx chemx audit locally. Zero cloud code upload. Instant MHI score and hazard detection in 5s.

2. Wire Your Agent Loop

Equip Claude, Gemini, or Cursor with chemx:mcp. Query AST slices and verify edits deterministically.

3. Accelerate with Vault

Unlock the complete 7-chapter specification, ready-to-use .cursorrules, and CI pre-commit gates from $27.