From 85ca5c4581032acd7fb9b422a8e7a7da8ecb422e Mon Sep 17 00:00:00 2001 From: Han Lap Date: Fri, 3 Jul 2026 13:23:46 +0000 Subject: [PATCH] =?UTF-8?q?docs:=20th=C3=AAm=20Gitea=20+=20Infrastructure?= =?UTF-8?q?=20v=C3=A0o=20ki=E1=BA=BFn=20tr=C3=BAc=20h=E1=BB=87=20th?= =?UTF-8?q?=E1=BB=91ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ARCHITECTURE.md | 72 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index c4a0a02..dba7d38 100755 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -8,15 +8,24 @@ ## 1. Tổng quan kiến trúc ``` -┌─────────────────────────────────────────────────────────┐ -│ TRADING PORTAL │ -├─────────────────┬─────────────────┬─────────────────────┤ -│ Frontend │ Backend API │ Backend Scheduler │ -│ (React/TS) │ (FastAPI) │ (Python async) │ -│ Port 3000 │ Port 8001 │ No HTTP port │ -├─────────────────┴─────────────────┴─────────────────────┤ -│ PostgreSQL 16 │ -└─────────────────────────────────────────────────────────┘ +┌──────────────────────────────────────────────────────────────────┐ +│ TRADING PORTAL │ +├───────────────────┬───────────────────┬──────────────────────────┤ +│ Frontend │ Backend API │ Backend Scheduler │ +│ (React/TS) │ (FastAPI) │ (Python async) │ +│ Port 3000 │ Port 8001 │ No HTTP port │ +├───────────────────┴───────────────────┴──────────────────────────┤ +│ PostgreSQL 16 │ +└──────────────────────────────────────────────────────────────────┘ + │ + ▼ +┌──────────────────────────────────────────────────────────────────┐ +│ INFRASTRUCTURE │ +├────────────┬──────────────┬─────────────────┬────────────────────┤ +│ nginx_proxy│ certbot_ssl │ Gitea (Git) │ Hermes Agent │ +│ :80/:443 │ auto-renew │ :8929 / SSH:2222│ host network │ +│ reverse │ Let's Encrypt│ git.dangloica │ AI assistant │ +└────────────┴──────────────┴─────────────────┴────────────────────┘ ``` ### Services @@ -27,6 +36,47 @@ | `backend-api` | FastAPI | 1G / 2 CPU | REST API, WebSocket, auth | | `backend-scheduler` | Python async | 2G / 3 CPU | Fetch candle, phân tích tín hiệu, quản lý trade | | `db` | PostgreSQL 16 | 2G | Lưu trữ toàn bộ dữ liệu | +| `nginx_proxy` | nginx:1.27-alpine | — | Reverse proxy SSL cho tất cả domain | +| `certbot_ssl` | certbot/certbot | — | Auto-renew Let's Encrypt mỗi 12h | +| `gitea` | gitea/gitea:latest | ~300MB | Git server tại git.dangloica.org | +| `hermes` | hermes-agent | — | AI assistant (Telegram, API, automation) | + +### Domains & SSL + +| Domain | SSL Cert | Backend | Ghi chú | +|--------|----------|---------|---------| +| `trading.dangloica.org` | Let's Encrypt (DNS-01) | frontend:3000 | Trading portal chính | +| `git.dangloica.org` | Let's Encrypt (DNS-01) | gitea:8929 | Git server riêng | +| `hermes.dangloica.org` | Let's Encrypt | hermes:9119 | Dashboard AI | + +> ⚠️ **Port 80 bị firewall cloud chặn** → HTTP challenge không dùng được. +> Cert mới phải dùng **DNS-01 challenge** + manual auth hook (TXT record trên PAVietnam DNS). + +### Git Workflow + +``` +Team push code → Gitea (git.dangloica.org) → Hermes pull + build + deploy +``` + +**Repo:** `hanlap/trading-portal` (Private 🔒) — `https://git.dangloica.org/hanlap/trading-portal` + +**Deploy command:** +```bash +cd /opt/data/trading-portal && git pull origin master +docker compose build backend-api backend-scheduler frontend +docker compose up -d backend-api backend-scheduler frontend +``` + +**Gitea users:** +| User | Role | Password | +|------|------|----------| +| `tien` | Admin | *riêng* | +| `hanlap` | Owner repo | `***REMOVED***` | +| `nguyendao` | Write | `***REMOVED***` | +| `tulinh` | Write | `***REMOVED***` | +| `namcunguyen` | Write | `***REMOVED***` | + +**Nginx config:** `/opt/ai-agent/nginx/conf.d/hermes.conf` (bind mount vào nginx_proxy) ### Nguyên tắc thiết kế @@ -296,7 +346,9 @@ Script `/opt/data/scripts/health_check.py`: | Date | Change | Author | |------|--------|--------| -| 2026-07-02 | **Audit toàn hệ thống**: fix 2 critical (real_trades PnL NULL + stale close) + 6 medium (API 404/405, Health tab, sessions, mobile nav, DB vacuum) | Hermes | +| 2026-07-03 | **Gitea setup**: git.dangloica.org, SSL DNS-01, 5 users, repo trading-portal | Hermes | +| 2026-07-03 | **Infrastructure doc**: thêm nginx_proxy, certbot, Gitea, Hermes vào kiến trúc | Hermes | +| 2026-07-02 | **Audit toàn hệ thống**: fix 2 critical (real_trades PnL NULL + stale close) + 6 medium | Hermes | | 2026-07-02 | **Tách Signal ↔ Trade**: tạo `trade_executor.py`, signal chỉ để monitoring | Hermes | | 2026-07-02 | **PnL filter**: `ABS(pnl_percent) < 100` trong tất cả queries | Hermes | | 2026-07-02 | **Win-rate decay**: exponential λ=0.05, MIN_TRADES=15 | Hermes |