--- title: CoreDoc Integration Guide version: 1.0.0 date: 2026-10-25 author: Momentry Core Team status: Active --- # CoreDoc Integration Guide ## Overview This guide explains how CoreDoc is integrated into Markbase, including route configuration, static file serving, and the dual documentation system architecture. --- ## Integration Architecture ``` Markbase Server (Port 11438) │ ├── /docs/legacy/* → Legacy WASM documentation ├── /docs/api/* → API documentation (new system) ├── /docs/cli/* → CLI documentation (new system) │ ├── Authentication → HTTP Basic Auth (shared with Markbase admin) └── Static Files → Served from ~/momentry_core/docs_v1.0/ ``` --- ## Route Configuration ### Markbase Router Setup **File**: `/Users/accusys/markbase/markbase-core/src/server.rs` ```rust use axum::Router; use tower_http::services::ServeDir; // CoreDoc routes let docs_router = Router::new() // Legacy WASM system .nest_service("/legacy", ServeDir::new("/Users/accusys/momentry_core/docs_v1.0/doc_wasm")) // API documentation (new system) .nest_service("/api", ServeDir::new("/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE")) // CLI documentation (new system) .nest_service("/cli", ServeDir::new("/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE")); // Integrate into main router Router::new() .nest("/docs", docs_router) // ... other routes .layer(middleware::from_fn(auth_middleware)) ``` --- ## Static File Serving ### Directory Mapping | URL Path | File System Path | Content | |----------|------------------|---------| | `/docs/legacy/` | `~/momentry_core/docs_v1.0/doc_wasm/` | Legacy WASM system | | `/docs/legacy/modules/` | `~/momentry_core/docs_v1.0/doc_wasm/modules/` | Documentation modules | | `/docs/legacy/pkg/` | `~/momentry_core/docs_v1.0/doc_wasm/pkg/` | WASM binaries | | `/docs/api/` | `~/momentry_core/docs_v1.0/API_WORKSPACE/` | API documentation | | `/docs/cli/` | `~/momentry_core/docs_v1.0/CLI_WORKSPACE/` | CLI documentation | ### Serve Configuration ```rust // Static file service configuration let serve_options = ServeDir::new(docs_path) .precompressed_gzip() // Enable gzip .fallback(ServeFile::new("index.html")); // Fallback to index.html ``` --- ## Authentication Integration ### Shared Authentication CoreDoc uses the same authentication system as Markbase admin: **Database**: `data/auth.sqlite` (shared) **Table**: `sftpgo_users` **Mechanism**: HTTP Basic Auth **Implementation**: ```rust // Shared auth middleware async fn auth_middleware( headers: HeaderMap, state: State, ) -> Result<(), impl IntoResponse> { let auth_header = headers .get("Authorization") .and_then(|v| v.to_str().ok()) .and_then(|v| v.strip_prefix("Basic ")); if let Some(credentials) = auth_header { // Validate against SQLite database if state.auth.verify_admin_token(credentials).is_some() { return Ok(()); } } Err(( StatusCode::UNAUTHORIZED, [("WWW-Authenticate", "Basic realm=\"CoreDoc\"")], "Unauthorized", )) } ``` ### User Management Users are managed through Markbase user management API: ```bash # List users curl -u admin:admin123 http://localhost:11438/api/v2/admin/users # Create user curl -u admin:admin123 -X POST \ -H "Content-Type: application/json" \ -d '{"username":"docuser","password":"docpass123"}' \ http://localhost:11438/api/v2/admin/users ``` --- ## WASM Integration ### Client-Side Setup **HTML**: `/docs/legacy/index.html` ```html CoreDoc
``` ### WASM Loading Strategy **Lazy Loading** (Recommended): ```javascript // Load WASM only when needed let wasmModule = null; async function getWasm() { if (!wasmModule) { const module = await import('/docs/legacy/pkg/md_wasm.js'); await module.default(); wasmModule = module; } return wasmModule; } // Use const wasm = await getWasm(); const html = wasm.render(markdown); ``` **Benefits**: - Reduces initial page load - Saves memory if documentation not accessed - Improves overall performance --- ## New Documentation System Integration ### API Documentation **Location**: `~/momentry_core/docs_v1.0/API_WORKSPACE/` **Structure**: ``` API_WORKSPACE/ ├── modules/ │ ├── 001_Auth_API.md │ ├── 002_Health_API.md │ └── ... ├── README.md └── Makefile ``` **Access**: `http://localhost:11438/docs/api/modules/001_Auth_API.md` ### CLI Documentation **Location**: `~/momentry_core/docs_v1.0/CLI_WORKSPACE/` **Structure**: ``` CLI_WORKSPACE/ ├── modules/ │ ├── 101_Register_CLI.md │ ├── 102_Lookup_CLI.md │ └── ... └── README.md ``` **Access**: `http://localhost:11438/docs/cli/modules/101_Register_CLI.md` --- ## Migration from Port 8000 to Markbase ### Step 1: Update Routes **Old** (port 8000): ```rust Router::new() .route("/", get(index_handler)) .route("/modules/:name", get(module_handler)) ``` **New** (port 11438): ```rust Router::new() .nest("/docs/legacy", legacy_docs_routes()) .nest("/docs/api", api_docs_routes()) .nest("/docs/cli", cli_docs_routes()) ``` ### Step 2: Update HTML **Old**: ```html ``` **New**: ```html ``` ### Step 3: Update Client Code **Old**: ```javascript fetch('/modules/001_Auth_v1.3.5.md') ``` **New**: ```javascript fetch('/docs/legacy/modules/001_Auth_v1.3.5.md') ``` ### Step 4: Close Port 8000 ```bash # Stop old server lsof -ti :8000 | xargs kill -9 # Verify port is free lsof -i :8000 ``` --- ## Environment Configuration ### Markbase Environment **File**: `markbase/config/markbase.toml` ```toml [documentation] enabled = true [documentation.legacy] path = "/Users/accusys/momentry_core/docs_v1.0/doc_wasm" url_prefix = "/docs/legacy" [documentation.api] path = "/Users/accusys/momentry_core/docs_v1.0/API_WORKSPACE" url_prefix = "/docs/api" [documentation.cli] path = "/Users/accusys/momentry_core/docs_v1.0/CLI_WORKSPACE" url_prefix = "/docs/cli" ``` --- ## Testing Integration ### Test Routes ```bash # Test legacy system curl -u admin:admin123 http://localhost:11438/docs/legacy/ curl -u admin:admin123 http://localhost:11438/docs/legacy/modules/000_Welcome.md curl -u admin:admin123 http://localhost:11438/docs/legacy/pkg/md_wasm_bg.wasm # Test API documentation curl -u admin:admin123 http://localhost:11438/docs/api/modules/001_Auth_API.md # Test CLI documentation curl -u admin:admin123 http://localhost:11438/docs/cli/modules/101_Register_CLI.md # Test authentication curl http://localhost:11438/docs/ # Should fail with 401 curl -u admin:wrongpassword http://localhost:11438/docs/ # Should fail with 401 curl -u admin:admin123 http://localhost:11438/docs/ # Should succeed ``` ### Integration Checklist - [ ] Routes configured in `server.rs` - [ ] Static files accessible - [ ] Authentication working - [ ] WASM loading correctly - [ ] Documentation content accessible - [ ] All three systems (legacy/api/cli) working - [ ] Port 8000 closed - [ ] No conflicts with other Markbase routes --- ## Performance Considerations ### Caching Strategy **Browser Caching**: ```rust // Add cache headers .headers([ ("Cache-Control", "public, max-age=3600"), // 1 hour ("ETag", file_hash), ]) ``` **CDN Integration** (Future): ``` /docs/legacy/pkg/* → CDN (long cache) /docs/legacy/modules/* → CDN (short cache) ``` ### Load Balancing For high traffic: - Use multiple instances behind load balancer - Share static files via network storage - Enable gzip compression --- ## Troubleshooting Integration Issues ### Issue: Routes Not Working **Symptoms**: 404 errors on /docs/* routes **Solutions**: 1. Check route order in `server.rs` (specific routes before wildcards) 2. Verify static file paths exist 3. Check file permissions ### Issue: WASM Not Loading **Symptoms**: JavaScript errors, module not found **Solutions**: 1. Verify WASM files exist in correct location 2. Check MIME types (application/wasm) 3. Verify CORS headers ### Issue: Authentication Loop **Symptoms**: Repeated login prompts **Solutions**: 1. Check auth middleware configuration 2. Verify database connection 3. Check password encoding --- ## Related Documents - [Architecture](./ARCHITECTURE.md) - System design - [API Reference](./API_REFERENCE.md) - All endpoints - [Maintenance Guide](./MAINTENANCE_GUIDE.md) - Daily operations --- ## Version History | Version | Date | Changes | |---------|------|---------| | 1.0.0 | 2026-10-25 | Initial integration guide |