Skip to content

Architecture and Extensibility

SWAGAT SOURAV DHAR edited this page Oct 31, 2026 · 1 revision

πŸ›οΈ Architecture & Extensibility Guide

This document details the core architectural patterns, reactive state machine, and component extension guidelines for DocuMorph.


1. Directory Structure

DocuMorph follows a strict Feature-Driven Architecture adhering to our engineering guidelines in GEMINI.md:

documorph/
β”œβ”€β”€ .agents/                    # Workspace-level AI agent rules & standards
β”œβ”€β”€ .github/                    # CI/CD Workflows, security scans & PR templates
β”‚   └── workflows/
β”‚       β”œβ”€β”€ ci.yml              # Node 22 + pnpm 11 build, lint & type-check
β”‚       └── security.yml        # pnpm audit + CodeQL static analysis
β”œβ”€β”€ docs/                       # Project documentation & GitHub Wiki
β”‚   └── wiki/                   # Complete Wiki chapters
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                    # Next.js App Router segements
β”‚   β”‚   β”œβ”€β”€ api/v1/ingest/      # Rate-limited GitHub AST Ingestion API
β”‚   β”‚   β”œβ”€β”€ layout.tsx          # Root layout & font definition
β”‚   β”‚   └── page.tsx            # Main workspace viewport
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ canvas/             # React Flow 2D Architecture Canvas & Studio
β”‚   β”‚   β”œβ”€β”€ canvas3d/           # Three.js 3D WebGL Hologram Constellation
β”‚   β”‚   β”œβ”€β”€ copilot/            # Multimodal AI Architecture Co-Pilot
β”‚   β”‚   β”œβ”€β”€ editor/             # Living Markdown Spec Editor
β”‚   β”‚   β”œβ”€β”€ header/             # Universal Navigation & View Switcher
β”‚   β”‚   β”œβ”€β”€ ingest/             # Code Link Ingest Modal
β”‚   β”‚   β”œβ”€β”€ inspector/          # Node Inspector & Endpoint Manager
β”‚   β”‚   β”œβ”€β”€ observability/      # Grafana Metrics & Waterfall Trace Viewer
β”‚   β”‚   β”œβ”€β”€ playground/         # Living API Sandbox with Monaco Editor
β”‚   β”‚   └── ui/                 # Reusable UI primitives (Card3DTilt, Buttons)
β”‚   β”œβ”€β”€ data/                   # Showcase Templates & Architecture Samples
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ ingest/             # GitHub Ingestion AST & Manifest Analyzer
β”‚   β”‚   └── security/           # Rate limiter, SSRF validator & Sanitizer
β”‚   β”œβ”€β”€ store/                  # Global Zustand State Machine
β”‚   └── types/                  # Strict TypeScript domain interfaces
β”œβ”€β”€ AGENTS.md                   # Autonomous agent guidelines & Graphify index
β”œβ”€β”€ ARCHITECTURE.md             # Subsystem technical architecture
β”œβ”€β”€ GEMINI.md                   # Master AI pair-programming rules & quality gates
β”œβ”€β”€ package.json                # Dependencies & scripts
└── pnpm-workspace.yaml         # Supply chain overrides (dompurify CVE patch)

2. Global State Machine (useDocuMorphStore)

Global state is managed using Zustand (src/store/useDocuMorphStore.ts):

  • Template Management: templates, activeTemplate, setActiveTemplate(), loadCustomTemplate().
  • Selection State: selectedNode, selectedEndpoint, setSelectedNode(), setSelectedEndpoint().
  • View Navigation: activeTab (diagram | hologram3d | playground | metrics | editor | copilot).
  • Architecture Creator Studio: addNode(), deleteNode(), updateNodeData(), addEdgeConnection(), deleteEdge(), exportToMermaid().
  • End-to-End Simulation: isSimulating, runEndpointSimulation(), traceEvents, spans.

3. Core Invariants (Must Be Preserved)

When extending DocuMorph, maintain these four fundamental invariants:

  1. Node Data Typing: All node data must extend Record<string, unknown> to ensure compatibility with @xyflow/react v12.
  2. React 19 State Discipline: Prohibit synchronous setState calls directly inside useEffect bodies to prevent cascading re-render warnings. Pass entity IDs via key={entity.id} to reinitialize component state naturally.
  3. Webpack Build Flag: Maintain "build": "next build --webpack" in package.json to guarantee complete compatibility with external CSS loaders (@xyflow/react/dist/style.css).
  4. Security & Sandbox Isolation: Never execute untrusted code or arbitrary scripts on the server. All simulated API responses run within the client-side browser sandbox.

Clone this wiki locally