Files

102 lines
4.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Momentry 真實系統架構
## 為什麼使用 serve_frontend.py?
### momentry-proxy 的限制
`momentry-proxy` (8 MB, Rust) 是 Tauri 桌面應用的後端:
- **設計用途**: 在 Tauri app 內為 Vue3 webview 提供 API proxy
- **Tauri 架構**: Webview 直接存取本地檔案系統,不需要 static file server
- **獨立運行時**: 只做 API proxy (`/api/*` → `:3002`)
- **不支援**: 靜態檔案服務、SPA fallback
### momentry server 的限制
`momentry server` (47 MB, Rust/Axum) 是純 API server:
- **沒有** static file handler
- **沒有** SPA fallback 機制
- **專注於**: 131+ API routes
### 為什麼不用 Caddy?
- Caddy 只在 **m4mini** 上安裝
- **m5max128** (runtime machine) 沒有安裝 Caddy
- 安裝 Caddy 需要額外的系統配置
### serve_frontend.py 的優勢
| 特性 | 說明 |
|------|------|
| ✅ Python 3.11 已安裝 | 無需額外安裝 |
| ✅ 零依賴 | 只用 Python 標準庫 |
| ✅ 靜態檔案 + API proxy | 單一進程處理所有 |
| ✅ SPA fallback | 未知路徑 → index.html |
| ✅ 全 HTTP 方法 | GET/POST/PUT/DELETE/PATCH |
| ✅ 輕量 | 單一檔案 (~70 行) |
| ❌ 非生產級 | 無並發優化、無 HTTPS |
## 完整系統架構
```
Internet (1.162.47.23:443)
│ HTTPS
▼
┌─────────────────────────────────────────────────┐
│ m4mini (192.168.110.210) │
│ │
│ Caddy (:80/:443) │
│ ├─ nextorage.ddns.net → 192.168.110.200:8888 │
│ ├─ api.ddns.net → localhost:3002 │
│ ├─ qdrant.ddns.net → localhost:6333 │
│ └─ 30+ subdomains │
│ │
│ Gitea (:3000) PostgreSQL (:5432) │
│ Redis (:6379) Qdrant (:6333) │
└────────────────────┬────────────────────────────┘
│ HTTP :8888
▼
┌─────────────────────────────────────────────────┐
│ m5max128 (192.168.110.200 / 10.10.10.88) │
│ │
│ serve_frontend.py (:8888) │
│ ├─ Static: ~/momentry/dist/* │
│ ├─ SPA: /* → index.html │
│ └─ Proxy: /api/* → localhost:3002 │
│ │
│ momentry server (:3002) ── 核心 API (131 routes)│
│ momentry worker ── 背景處理器 │
│ markbase-core (:11438) ── 檔案管理 │
│ markbaseengine (:8082) ── LLM wrapper │
│ llama-server (:8080) ── Chat LLM │
│ embeddinggemma (:11436)── Embedding │
│ SFTPGo (:2022/:8081) ── 檔案上傳 │
└─────────────────────────────────────────────────┘
```
## 請求流程
```
Browser → https://nextorage.momentry.ddns.net/library
→ Caddy (m4mini) 反向代理
→ serve_frontend.py (m5max128:8888)
→ SPA fallback → dist/index.html
→ Vue3 SPA 載入
→ POST /api/v1/auth/login
→ serve_frontend.py proxy → localhost:3002
→ momentry server 驗證 → 返回 JWT
→ Browser 登入成功
```
## 服務總覽 (m5max128)
| 服務 | Port | Binary | 說明 |
|------|------|--------|------|
| serve_frontend.py | 8888 | Python | SPA + API proxy |
| momentry server | 3002 | Rust/Axum | 核心 API |
| momentry worker | — | Rust | 背景處理 |
| markbase-core | 11438 | Rust | 檔案管理 |
| markbaseengine | 8082 | Rust | LLM wrapper |
| llama-server | 8080 | C++ | Chat LLM |
| embeddinggemma | 11436 | Python | Embedding |
| SFTPGo | 2022/8081 | Go | 檔案上傳 |