Files
Warren c28acd0512
Test / test (push) Has been cancelled
Test / build (push) Has been cancelled
feat: integrate CoreDoc documentation system
- Add CoreDoc maintenance documentation (8 files)
- Create route module for documentation serving
- Set up static file structure with symbolic links
- Support dual documentation systems (Legacy WASM + New Modular)

Documentation includes:
- README.md: System overview
- DIRECTORY_STRUCTURE.md: Complete directory mapping
- ARCHITECTURE.md: System design and data flow
- MAINTENANCE_GUIDE.md: Daily maintenance procedures
- INTEGRATION_GUIDE.md: Integration details
- API_REFERENCE.md: All API endpoints
- INTEGRATION_REPORT.md: Complete integration report
- QUICK_START.md: Quick reference for team

Route module: markbase-core/src/api/docs.rs
- /docs/legacy/* → Legacy WASM system
- /docs/api/* → API documentation
- /docs/cli/* → CLI documentation

Static files:
- static/docs/legacy -> momentry_core/docs_v1.0/doc_wasm/
- static/docs/api -> momentry_core/docs_v1.0/API_WORKSPACE/
- static/docs/cli -> momentry_core/docs_v1.0/CLI_WORKSPACE/

Pending: Manual route addition to server.rs
Team: Markbase team to complete integration
2026-10-25 23:17:56 +08:00

364 lines
20 KiB
Markdown

---
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) │ │
│ ├────────────────────────────────────────────────┤ │
│ │ <div class="sidebar"> │ │
│ │ <ul class="module-list"> │ │
│ │ <li>Module 001</li> │ │
│ │ <li>Module 002</li> │ │
│ │ </ul> │ │
│ │ </div> │ │
│ │ │ │
│ │ <div class="content"> │ │
│ │ <!-- WASM renders here --> │ │
│ │ </div> │ │
│ └────────────────────────────────────────────────┘ │
│ │
│ ┌────────────────────────────────────────────────┐ │
│ │ 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 |