Repository navigation
Architecture and Extensibility
SWAGAT SOURAV DHAR edited this page Oct 31, 2026
·
1 revision
This document details the core architectural patterns, reactive state machine, and component extension guidelines for DocuMorph.
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)
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.
When extending DocuMorph, maintain these four fundamental invariants:
-
Node Data Typing: All node data must extend
Record<string, unknown>to ensure compatibility with@xyflow/reactv12. -
React 19 State Discipline: Prohibit synchronous
setStatecalls directly insideuseEffectbodies to prevent cascading re-render warnings. Pass entity IDs viakey={entity.id}to reinitialize component state naturally. -
Webpack Build Flag: Maintain
"build": "next build --webpack"inpackage.jsonto guarantee complete compatibility with external CSS loaders (@xyflow/react/dist/style.css). - Security & Sandbox Isolation: Never execute untrusted code or arbitrary scripts on the server. All simulated API responses run within the client-side browser sandbox.