--- title: CoreDoc Architecture version: 1.0.0 date: 2026-10-25 author: Momentry Core Team status: Active --- # CoreDoc Architecture ## Overview CoreDoc uses a dual-system architecture that maintains both legacy WASM-based documentation and new modular documentation formats, integrated into Markbase as a unified service. --- ## High-Level Architecture ``` ┌─────────────────────────────────────────────────────────┐ │ Markbase (Port 11438) │ ├─────────────────────────────────────────────────────────┤ │ │ │ ┌──────────────────────────────────────────────────┐ │ │ │ CoreDoc Integration Layer │ │ │ ├──────────────────────────────────────────────────┤ │ │ │ │ │ │ │ /docs/legacy/* → Legacy WASM System │ │ │ │ /docs/api/* → API Documentation │ │ │ │ /docs/cli/* → CLI Documentation │ │ │ │ │ │ │ └──────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────┘ │ │ Static Files ▼ ┌─────────────────────────────────────────────────────────┐ │ File System (Documentation Sources) │ ├─────────────────────────────────────────────────────────┤ │ │ │ ~/momentry_core/docs_v1.0/ │ │ ├── doc_wasm/ (Legacy WASM) │ │ │ ├── index.html │ │ │ ├── modules/ │ │ │ └── pkg/ (WASM binaries) │ │ │ │ │ ├── API_WORKSPACE/ (New API Docs) │ │ │ └── modules/ │ │ │ │ │ └── CLI_WORKSPACE/ (New CLI Docs) │ │ └── modules/ │ │ │ └─────────────────────────────────────────────────────────┘ ``` --- ## Component Architecture ### 1. HTTP Server Layer ``` ┌─────────────────────────────────────────────────────────┐ │ DocServer (Rust + axum) │ ├─────────────────────────────────────────────────────────┤ │ │ │ ┌────────────────┐ ┌────────────────┐ │ │ │ Auth Middleware│ │ CORS Middleware│ │ │ └────────────────┘ └────────────────┘ │ │ │ │ ┌────────────────────────────────────────────────┐ │ │ │ Router │ │ │ ├────────────────────────────────────────────────┤ │ │ │ GET / → index.html │ │ │ │ GET /modules/:name → Markdown file │ │ │ │ GET /pkg/* → WASM files │ │ │ │ GET /logout → logout.html │ │ │ └────────────────────────────────────────────────┘ │ │ │ │ ┌────────────────────────────────────────────────┐ │ │ │ Static File Handler (tower-http::ServeDir) │ │ │ └────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────┘ ``` **Server Configuration**: - Framework: axum 0.7 - Static Files: tower-http 0.5 - Authentication: HTTP Basic Auth - Port: 11438 (integrated into Markbase) --- ### 2. WASM Rendering Layer ``` ┌─────────────────────────────────────────────────────────┐ │ WASM Markdown Renderer │ ├─────────────────────────────────────────────────────────┤ │ │ │ ┌────────────────────────────────────────────────┐ │ │ │ Rust Source (md_wasm/src/lib.rs) │ │ │ ├────────────────────────────────────────────────┤ │ │ │ fn render(md: &str) -> String { │ │ │ │ // Parse Markdown with pulldown-cmark │ │ │ │ // Convert to HTML │ │ │ │ // Apply custom styling │ │ │ │ } │ │ │ └────────────────────────────────────────────────┘ │ │ │ │ ┌────────────────────────────────────────────────┐ │ │ │ Compilation Target │ │ │ ├────────────────────────────────────────────────┤ │ │ │ wasm32-unknown-unknown │ │ │ │ wasm-bindgen (JS bindings) │ │ │ └────────────────────────────────────────────────┘ │ │ │ │ ┌────────────────────────────────────────────────┐ │ │ │ Output │ │ │ ├────────────────────────────────────────────────┤ │ │ │ md_wasm_bg.wasm (291KB) │ │ │ │ md_wasm.js (7.2KB) │ │ │ └────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────┘ ``` **WASM Features**: - CommonMark compliant - GFM (GitHub Flavored Markdown) tables - HTML sanitization - Client-side rendering - Zero server load for rendering --- ### 3. Frontend Layer ``` ┌─────────────────────────────────────────────────────────┐ │ HTML/JavaScript Client │ ├─────────────────────────────────────────────────────────┤ │ │ │ ┌────────────────────────────────────────────────┐ │ │ │ index.html (432 lines) │ │ │ ├────────────────────────────────────────────────┤ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ └────────────────────────────────────────────────┘ │ │ │ │ ┌────────────────────────────────────────────────┐ │ │ │ JavaScript Integration │ │ │ ├────────────────────────────────────────────────┤ │ │ │ import init, { render } from './pkg/md_wasm.js'│ │ │ │ │ │ │ │ async function loadDoc(moduleName) { │ │ │ │ const md = await fetch(`/modules/${name}`) │ │ │ │ const html = render(md) │ │ │ │ document.getElementById('content').innerHTML = html │ │ │ } │ │ │ └────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────┘ ``` --- ### 4. Documentation Storage Layer ``` ┌─────────────────────────────────────────────────────────┐ │ Dual Documentation Systems │ ├─────────────────────────────────────────────────────────┤ │ │ │ ┌────────────────────────────────────────────────┐ │ │ │ Legacy System (Deprecated but Available) │ │ │ ├────────────────────────────────────────────────┤ │ │ │ Location: doc_wasm/modules/ │ │ │ │ Format: 3-digit numbered files │ │ │ │ Example: 001_Auth_v1.3.5.md │ │ │ │ Count: 68 modules │ │ │ │ Status: ⚠️ Deprecated │ │ │ └────────────────────────────────────────────────┘ │ │ │ │ ┌────────────────────────────────────────────────┐ │ │ │ New Modular System (Active) │ │ │ ├────────────────────────────────────────────────┤ │ │ │ API Workspace: │ │ │ │ Location: API_WORKSPACE/modules/ │ │ │ │ Format: Semantic naming │ │ │ │ Example: Auth_API.md │ │ │ │ │ │ │ │ CLI Workspace: │ │ │ │ Location: CLI_WORKSPACE/modules/ │ │ │ │ Format: Command-based naming │ │ │ │ Example: Register_CLI.md │ │ │ │ │ │ │ │ Status: ✅ Active │ │ │ └────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────┘ ``` --- ## Data Flow ### 1. Document Viewing Flow ``` User Browser │ ├─> HTTP Request (GET /docs/legacy/modules/001_Auth_v1.3.5.md) │ ▼ Markbase Server (Port 11438) │ ├─> Auth Middleware (verify HTTP Basic Auth) │ ├─> Route Handler (match /docs/legacy/*) │ └─> File Read (from ~/momentry_core/docs_v1.0/doc_wasm/modules/) │ ▼ Markdown Content │ └─> HTTP Response (text/markdown) │ ▼ Browser JavaScript │ ├─> WASM Module Load (md_wasm.js) │ ├─> WASM render() call │ └─> HTML Output │ ▼ DOM Update (rendered content) ``` --- ### 2. WASM Compilation Flow ``` Source Code (md_wasm/src/lib.rs) │ ├─> cargo build --target wasm32-unknown-unknown --release │ ▼ Compiled WASM (target/wasm32-unknown-unknown/release/md_wasm.wasm) │ ├─> wasm-bindgen --out-dir docs_v1.0/doc_wasm/pkg --target web │ ▼ Output Files ├── md_wasm_bg.wasm (binary, 291KB) └── md_wasm.js (JavaScript bindings, 7.2KB) ``` --- ## Security Architecture ``` ┌─────────────────────────────────────────────────────────┐ │ Security Layers │ ├─────────────────────────────────────────────────────────┤ │ │ │ Layer 1: Network Security │ │ └─> Port binding (localhost or specific IP) │ │ │ │ Layer 2: Authentication │ │ └─> HTTP Basic Auth (username/password) │ │ │ │ Layer 3: Authorization │ │ └─> All authenticated users have same access │ │ │ │ Layer 4: Input Validation │ │ └─> Path traversal prevention │ │ └─> File type restrictions │ │ │ │ Layer 5: WASM Sandboxing │ │ └─> Browser WASM sandbox │ │ └─> No file system access │ │ └─> No network access (except fetch) │ │ │ └─────────────────────────────────────────────────────────┘ ``` --- ## Performance Characteristics ### Server Performance | Operation | Time | Notes | |-----------|------|-------| | Auth verification | < 1ms | In-memory check | | File read (Markdown) | < 5ms | Small text files | | Static file serve | < 10ms | Direct file system | ### Client Performance | Operation | Time | Notes | |-----------|------|-------| | WASM load (first time) | ~200ms | 291KB download + compile | | WASM load (cached) | ~10ms | From browser cache | | Markdown render | < 50ms | Client-side processing | | DOM update | < 10ms | Single element replacement | ### Scalability - **Concurrent Users**: ~100 (limited by file I/O) - **Memory Usage**: ~50MB (server) + ~10MB per client (WASM) - **CPU Usage**: Low (static files + client-side rendering) --- ## Integration Points ### Markbase Integration ```rust // markbase-core/src/server.rs Router::new() .route("/docs/legacy/*path", get(serve_legacy_docs)) .route("/docs/api/*path", get(serve_api_docs)) .route("/docs/cli/*path", get(serve_cli_docs)) .layer(middleware::from_fn(auth_middleware)) ``` ### Authentication Integration - Shared with Markbase admin authentication - Uses same SQLite database (`data/auth.sqlite`) - JWT token validation (future enhancement) --- ## Related Documents - [Integration Guide](./INTEGRATION_GUIDE.md) - Detailed integration steps - [API Reference](./API_REFERENCE.md) - All endpoints - [Maintenance Guide](./MAINTENANCE_GUIDE.md) - Performance optimization --- ## Version History | Version | Date | Changes | |---------|------|---------| | 1.0.0 | 2026-10-25 | Initial architecture documentation |