From a222c9a52f6845b440b359759e044b8aefe18dd1 Mon Sep 17 00:00:00 2001 From: WrBug Date: Sun, 7 Dec 2025 18:01:11 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E9=87=8D=E6=9E=84=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E7=BB=93=E6=9E=84=EF=BC=8C=E4=BD=BF=E7=94=A8=20zh/=20=E5=92=8C?= =?UTF-8?q?=20en/=20=E7=9B=AE=E5=BD=95=E5=8C=BA=E5=88=86=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建 docs/zh/ 和 docs/en/ 目录结构 - 将所有中文文档移动到 docs/zh/ - 创建主要文档的英文版本: - DEPLOYMENT.md (651行) - DEVELOPMENT.md (514行) - VERSION_MANAGEMENT.md (已有) - 更新所有文档中的内部链接 - 更新 README.md 和 README_EN.md 中的文档链接 - 在文档中添加中英文版本互链 --- README.md | 20 +- README_EN.md | 14 +- docs/en/DEPLOYMENT.md | 652 ++++++++++++++++++ docs/en/DEVELOPMENT.md | 520 ++++++++++++++ .../VERSION_MANAGEMENT.md} | 2 + docs/en/nginx-reverse-proxy.conf | 170 +++++ docs/{ => zh}/DEPLOYMENT.md | 6 +- docs/{ => zh}/DEVELOPMENT.md | 5 +- docs/{ => zh}/VERSION_MANAGEMENT.md | 2 + .../copy-trading-frontend-requirements.md | 0 docs/{ => zh}/copy-trading-implementation.md | 0 .../copy-trading-order-tracking-design.md | 0 docs/{ => zh}/copy-trading-requirements.md | 0 .../github-api-rate-limit-alternatives.md | 0 docs/{ => zh}/github-token-setup.md | 0 docs/zh/nginx-reverse-proxy.conf | 170 +++++ docs/{ => zh}/position-sell-order-design.md | 0 docs/{ => zh}/ternary-market-orderbook.md | 0 .../{ => zh}/websocket-push-service-design.md | 0 19 files changed, 1541 insertions(+), 20 deletions(-) create mode 100644 docs/en/DEPLOYMENT.md create mode 100644 docs/en/DEVELOPMENT.md rename docs/{VERSION_MANAGEMENT_EN.md => en/VERSION_MANAGEMENT.md} (99%) create mode 100644 docs/en/nginx-reverse-proxy.conf rename docs/{ => zh}/DEPLOYMENT.md (98%) rename docs/{ => zh}/DEVELOPMENT.md (97%) rename docs/{ => zh}/VERSION_MANAGEMENT.md (99%) rename docs/{ => zh}/copy-trading-frontend-requirements.md (100%) rename docs/{ => zh}/copy-trading-implementation.md (100%) rename docs/{ => zh}/copy-trading-order-tracking-design.md (100%) rename docs/{ => zh}/copy-trading-requirements.md (100%) rename docs/{ => zh}/github-api-rate-limit-alternatives.md (100%) rename docs/{ => zh}/github-token-setup.md (100%) create mode 100644 docs/zh/nginx-reverse-proxy.conf rename docs/{ => zh}/position-sell-order-design.md (100%) rename docs/{ => zh}/ternary-market-orderbook.md (100%) rename docs/{ => zh}/websocket-push-service-design.md (100%) diff --git a/README.md b/README.md index a6f8642..b1b78dc 100644 --- a/README.md +++ b/README.md @@ -276,7 +276,7 @@ docker-compose down 在生产环境中,建议在 Docker 容器外部部署 Nginx 作为反向代理,用于 SSL/TLS 终止、域名绑定等。 -详细配置请参考:[部署文档 - Nginx 反向代理](docs/DEPLOYMENT.md#使用外部-nginx-反向代理生产环境推荐) +详细配置请参考:[部署文档 - Nginx 反向代理](docs/zh/DEPLOYMENT.md#使用外部-nginx-反向代理生产环境推荐) ### 📦 分别部署 @@ -332,7 +332,8 @@ cd frontend ### 📚 详细部署文档 -更多部署选项和详细说明,请参考:[部署文档](docs/DEPLOYMENT.md) +更多部署选项和详细说明,请参考: +- [部署文档(中文)](docs/zh/DEPLOYMENT.md) / [English](docs/en/DEPLOYMENT.md) 包括: - 一体化部署详细步骤 @@ -349,7 +350,8 @@ cd frontend - **自动删除**:删除 release 时自动删除对应的 Docker 镜像标签 - **版本号显示**:前端自动显示当前版本号 -详细说明请参考:[版本号管理文档](docs/VERSION_MANAGEMENT.md) +详细说明请参考: +- [版本号管理文档(中文)](docs/zh/VERSION_MANAGEMENT.md) / [English](docs/en/VERSION_MANAGEMENT.md) --- @@ -357,7 +359,7 @@ cd frontend 详细的开发指南、API 接口文档、代码规范等,请参考: -### 📖 [开发文档](docs/DEVELOPMENT.md) +### 📖 [开发文档](docs/zh/DEVELOPMENT.md) / [English](docs/en/DEVELOPMENT.md) 开发文档包含以下内容: @@ -372,11 +374,11 @@ cd frontend ### 📚 其他文档 -- [部署文档](docs/DEPLOYMENT.md) / [English](docs/DEPLOYMENT_EN.md) - 详细的部署指南(Java/Docker) -- [版本号管理文档](docs/VERSION_MANAGEMENT.md) / [English](docs/VERSION_MANAGEMENT_EN.md) - 版本号管理和自动构建 -- [开发文档](docs/DEVELOPMENT.md) / [English](docs/DEVELOPMENT_EN.md) - 开发指南 -- [跟单系统需求文档](docs/copy-trading-requirements.md) - 后端 API 接口文档 -- [前端需求文档](docs/copy-trading-frontend-requirements.md) - 前端功能文档 +- [部署文档(中文)](docs/zh/DEPLOYMENT.md) / [English](docs/en/DEPLOYMENT.md) - 详细的部署指南(Java/Docker) +- [版本号管理文档(中文)](docs/zh/VERSION_MANAGEMENT.md) / [English](docs/en/VERSION_MANAGEMENT.md) - 版本号管理和自动构建 +- [开发文档(中文)](docs/zh/DEVELOPMENT.md) / [English](docs/en/DEVELOPMENT.md) - 开发指南 +- [跟单系统需求文档](docs/zh/copy-trading-requirements.md) - 后端 API 接口文档 +- [前端需求文档](docs/zh/copy-trading-frontend-requirements.md) - 前端功能文档 ### 🤝 贡献指南 diff --git a/README_EN.md b/README_EN.md index cc5698c..1499e7d 100644 --- a/README_EN.md +++ b/README_EN.md @@ -276,7 +276,7 @@ docker-compose down In production environments, it is recommended to deploy Nginx as a reverse proxy outside the Docker container for SSL/TLS termination, domain binding, etc. -For detailed configuration, please refer to: [Deployment Documentation - Nginx Reverse Proxy](docs/DEPLOYMENT.md#使用外部-nginx-反向代理生产环境推荐) +For detailed configuration, please refer to: [Deployment Documentation - Nginx Reverse Proxy](docs/en/DEPLOYMENT.md#using-external-nginx-reverse-proxy-recommended-for-production) ### 📦 Separate Deployment @@ -357,7 +357,7 @@ For detailed instructions, please refer to: [Version Management Documentation](d For detailed development guides, API documentation, code standards, etc., please refer to: -### 📖 [Development Documentation](docs/DEVELOPMENT.md) +### 📖 [Development Documentation](docs/en/DEVELOPMENT.md) / [中文](docs/zh/DEVELOPMENT.md) The development documentation includes: @@ -372,11 +372,11 @@ The development documentation includes: ### 📚 Other Documentation -- [Deployment Documentation](docs/DEPLOYMENT.md) / [English](docs/DEPLOYMENT_EN.md) - Detailed deployment guide (Java/Docker) -- [Version Management Documentation](docs/VERSION_MANAGEMENT.md) / [English](docs/VERSION_MANAGEMENT_EN.md) - Version number management and auto-build -- [Development Documentation](docs/DEVELOPMENT.md) / [English](docs/DEVELOPMENT_EN.md) - Development guide -- [Copy Trading System Requirements](docs/copy-trading-requirements.md) - Backend API documentation -- [Frontend Requirements](docs/copy-trading-frontend-requirements.md) - Frontend feature documentation +- [Deployment Documentation (English)](docs/en/DEPLOYMENT.md) / [中文](docs/zh/DEPLOYMENT.md) - Detailed deployment guide (Java/Docker) +- [Version Management Documentation (English)](docs/en/VERSION_MANAGEMENT.md) / [中文](docs/zh/VERSION_MANAGEMENT.md) - Version number management and auto-build +- [Development Documentation (English)](docs/en/DEVELOPMENT.md) / [中文](docs/zh/DEVELOPMENT.md) - Development guide +- [Copy Trading System Requirements](docs/zh/copy-trading-requirements.md) - Backend API documentation +- [Frontend Requirements](docs/zh/copy-trading-frontend-requirements.md) - Frontend feature documentation ### 🤝 Contributing diff --git a/docs/en/DEPLOYMENT.md b/docs/en/DEPLOYMENT.md new file mode 100644 index 0000000..9318b4b --- /dev/null +++ b/docs/en/DEPLOYMENT.md @@ -0,0 +1,652 @@ +# PolyHermes Deployment Guide + +> 📖 **中文版本**: [部署文档(中文)](../zh/DEPLOYMENT.md) + +This document describes how to deploy the PolyHermes project, including different deployment methods for backend and frontend. + +## Table of Contents + +- [All-in-One Deployment (Recommended)](#all-in-one-deployment-recommended) + - [Using Docker Hub Images](#using-docker-hub-images-recommended-for-production) + - [Using External Nginx Reverse Proxy](#using-external-nginx-reverse-proxy-recommended-for-production) +- [Backend Deployment](#backend-deployment) + - [Java Direct Deployment](#java-direct-deployment) + - [Docker Deployment](#docker-deployment) +- [Frontend Deployment](#frontend-deployment) +- [Environment Configuration](#environment-configuration) +- [FAQ](#faq) + +## All-in-One Deployment (Recommended) + +Deploy both frontend and backend together in a single Docker container, using Nginx to serve frontend static files and proxy backend API. + +### Prerequisites + +- Docker 20.10+ +- Docker Compose 2.0+ + +### Deployment Steps + +1. **Using Docker Hub Images (Recommended, Production First Choice)** + +Use officially built Docker images, no local build required, fast deployment. + +**Method 1: Standalone Deployment (No code clone required, Recommended for Production)** + +Suitable for production environments, no need to download project code, only configuration files needed for deployment. + +```bash +# 1. Create deployment directory +mkdir polyhermes && cd polyhermes + +# 2. Download production environment configuration files +# Download docker-compose.prod.yml and docker-compose.prod.env.example from GitHub +curl -O https://raw.githubusercontent.com/WrBug/PolyHermes/main/docker-compose.prod.yml +curl -O https://raw.githubusercontent.com/WrBug/PolyHermes/main/docker-compose.prod.env.example + +# 3. Create configuration file +cp docker-compose.prod.env.example .env + +# 4. Edit .env file, modify the following required configurations: +# - DB_PASSWORD: Database password (recommended to use strong password) +# - JWT_SECRET: JWT secret key (generate using openssl rand -hex 64) +# - ADMIN_RESET_PASSWORD_KEY: Admin password reset key (generate using openssl rand -hex 32) +# +# Example of generating random keys: +# openssl rand -hex 64 # For JWT_SECRET +# openssl rand -hex 32 # For ADMIN_RESET_PASSWORD_KEY + +# 5. Start services +docker-compose -f docker-compose.prod.yml up -d + +# 6. View logs +docker-compose -f docker-compose.prod.yml logs -f + +# 7. Stop services +docker-compose -f docker-compose.prod.yml down +``` + +**Method 2: Using Deployment Script (Requires code clone)** + +```bash +# If you have already cloned the code +./deploy.sh --use-docker-hub +``` + +**Method 3: Modify Existing docker-compose.yml** + +```bash +# 1. Modify docker-compose.yml +# Uncomment: image: wrbug/polyhermes:latest +# Comment out build section + +# 2. Create .env file (see environment configuration below) + +# 3. Start services +docker-compose up -d +``` + +**Advantages**: +- ✅ No local build required, fast deployment +- ✅ No code clone required, only configuration files needed for deployment +- ✅ Uses officially built images with correct version numbers +- ✅ Supports multiple architectures (amd64, arm64), automatically selects matching architecture +- ✅ Recommended for production environments + +**Pull Specific Version**: + +```bash +# Modify image tag in docker-compose.prod.yml +# image: wrbug/polyhermes:v1.0.0 + +# Or use environment variable +export IMAGE_TAG=v1.0.0 +# In docker-compose.prod.yml use: image: wrbug/polyhermes:${IMAGE_TAG:-latest} +``` + +2. **Local Build Deployment (Development Environment)** + +Suitable for development environments or scenarios requiring custom builds. + +```bash +# Use deployment script +./deploy.sh +``` + +The script will automatically: +- Check Docker environment +- Create `.env` configuration file (if it doesn't exist) +- Build Docker image (including frontend and backend) +- Start services (application + MySQL) + +**Note**: Locally built version numbers will display as `dev`. + +3. **Manual Deployment** + +```bash +# Create .env file +cat > .env < .env < .env.production < + ServerName your-domain.com + DocumentRoot /path/to/frontend/dist + + # API proxy + ProxyPass /api http://localhost:8000/api + ProxyPassReverse /api http://localhost:8000/api + + # WebSocket proxy + ProxyPass /ws ws://localhost:8000/ws + ProxyPassReverse /ws ws://localhost:8000/ws + + # Frontend routing (SPA) + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + RewriteEngine On + RewriteBase / + RewriteRule ^index\.html$ - [L] + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule . /index.html [L] + + +``` + +#### Method 3: Using serve (Development/Testing) + +```bash +# Install serve +npm install -g serve + +# Start service +serve -s dist -l 3000 +``` + +## Environment Configuration + +### Backend Environment Variables + +| Variable Name | Description | Default Value | Required | +|---------------|-------------|---------------|----------| +| `SPRING_PROFILES_ACTIVE` | Spring Profile | `dev` | No | +| `DB_URL` | Database connection URL | - | Yes (Production) | +| `DB_USERNAME` | Database username | `root` | Yes (Production) | +| `DB_PASSWORD` | Database password | - | Yes (Production) | +| `SERVER_PORT` | Server port | `8000` | No | +| `POLYGON_RPC_URL` | Polygon RPC address | `https://polygon-rpc.com` | No | +| `JWT_SECRET` | JWT secret key | - | Yes (Production) | +| `ADMIN_RESET_PASSWORD_KEY` | Admin password reset key | - | Yes (Production) | + +### Frontend Environment Variables + +| Variable Name | Description | Default Value | +|---------------|-------------|---------------| +| `VITE_API_URL` | Backend API address | `http://127.0.0.1:8000` | +| `VITE_WS_URL` | WebSocket address | `ws://127.0.0.1:8000` | + +### Configuration File Description + +#### Backend Configuration Files + +- `application.properties` - Base configuration (shared by all environments) +- `application-dev.properties` - Development environment configuration +- `application-prod.properties` - Production environment configuration + +Switch environments via `--spring.profiles.active=prod` or environment variable `SPRING_PROFILES_ACTIVE=prod`. + +#### Frontend Environment Variables + +Vite uses `.env.production` file to inject environment variables during build. The build script will automatically create this file. + +## FAQ + +### 1. Database Connection Failed + +**Problem**: Backend cannot connect to database + +**Solution**: +- Check if database service is running +- Check if database connection URL, username, password are correct +- Check if firewall allows connection +- For Docker deployment, ensure using correct database address (`mysql` instead of `localhost`) + +### 2. Frontend Cannot Connect to Backend + +**Problem**: Frontend requests to backend API fail + +**Solution**: +- Check if backend service is running +- Check if `VITE_API_URL` configuration is correct +- Check CORS configuration (if cross-origin) +- Check network connection and firewall + +### 3. WebSocket Connection Failed + +**Problem**: WebSocket cannot establish connection + +**Solution**: +- Check if `VITE_WS_URL` configuration is correct +- Check WebSocket proxy configuration (Nginx/Apache) +- Check if firewall allows WebSocket connection +- Check if backend WebSocket service is normal + +### 4. Docker Container Cannot Access Database + +**Problem**: Backend in Docker container cannot connect to host database + +**Solution**: +- Use `host.docker.internal` as database address (Mac/Windows) +- Use Docker network connection (recommended to use docker-compose) +- Check if database allows remote connection + +### 5. Build Failed + +**Problem**: Frontend or backend build fails + +**Solution**: +- Check Node.js version (requires 18+) +- Check Java version (requires 17+) +- Clean cache and rebuild: + ```bash + # Frontend + rm -rf node_modules dist + npm install + npm run build + + # Backend + ./gradlew clean build + ``` + +## Production Environment Checklist + +- [ ] Modify all default passwords and keys (JWT_SECRET, ADMIN_RESET_PASSWORD_KEY, database password) +- [ ] Configure correct database connection (use SSL) +- [ ] Set correct Spring Profile (`prod`) +- [ ] Configure correct backend API address (frontend) +- [ ] Configure reverse proxy (Nginx/Apache) +- [ ] Configure HTTPS (recommended for production) +- [ ] Configure firewall rules +- [ ] Set up log rotation +- [ ] Configure monitoring and alerts +- [ ] Regular database backups + +## Performance Optimization Recommendations + +### Backend + +- Adjust JVM parameters (heap memory, GC strategy) +- Configure database connection pool size +- Enable HTTP compression +- Configure caching strategy + +### Frontend + +- Enable Gzip compression (Nginx) +- Configure static resource caching +- Use CDN acceleration +- Enable HTTP/2 + +## Security Recommendations + +- Use HTTPS (required for production) +- Configure CORS whitelist +- Regularly update dependencies +- Use strong passwords and keys +- Limit database access permissions +- Configure firewall rules +- Regular data backups +- Monitor abnormal access + +## Technical Support + +If you have any questions, please submit an Issue to [GitHub](https://github.com/WrBug/PolyHermes) or contact [Twitter](https://x.com/quant_tr). + diff --git a/docs/en/DEVELOPMENT.md b/docs/en/DEVELOPMENT.md new file mode 100644 index 0000000..86516d3 --- /dev/null +++ b/docs/en/DEVELOPMENT.md @@ -0,0 +1,520 @@ +# PolyHermes Development Guide + +> 📖 **中文版本**: [开发文档(中文)](../zh/DEVELOPMENT.md) + +This document describes the development guide for the PolyHermes project, including project structure, development environment setup, code standards, API interfaces, etc. + +## 📋 Table of Contents + +- [Project Structure](#project-structure) +- [Development Environment Setup](#development-environment-setup) +- [Code Standards](#code-standards) +- [API Documentation](#api-documentation) +- [Database Design](#database-design) +- [Frontend Development Guide](#frontend-development-guide) +- [Backend Development Guide](#backend-development-guide) +- [FAQ](#faq) + +## 📦 Project Structure + +``` +polyhermes/ +├── backend/ # Backend service +│ ├── src/main/kotlin/ +│ │ └── com/wrbug/polymarketbot/ +│ │ ├── api/ # API interface definitions (Retrofit) +│ │ ├── config/ # Configuration classes +│ │ ├── controller/ # REST controllers +│ │ ├── dto/ # Data Transfer Objects +│ │ ├── entity/ # Database entities +│ │ ├── repository/ # Data access layer +│ │ ├── service/ # Business logic services +│ │ ├── util/ # Utility classes +│ │ └── websocket/ # WebSocket handling +│ └── src/main/resources/ +│ ├── application.properties +│ └── db/migration/ # Flyway database migration scripts +├── frontend/ # Frontend application +│ ├── src/ +│ │ ├── components/ # Common components +│ │ ├── pages/ # Page components +│ │ ├── services/ # API services +│ │ ├── store/ # State management (Zustand) +│ │ ├── types/ # TypeScript type definitions +│ │ ├── utils/ # Utility functions +│ │ ├── hooks/ # React Hooks +│ │ ├── locales/ # Internationalization resources +│ │ └── styles/ # Style files +│ └── public/ # Static resources +├── docs/ # Documentation +│ ├── zh/ # Chinese documentation +│ │ ├── DEPLOYMENT.md # Deployment documentation +│ │ ├── VERSION_MANAGEMENT.md # Version management documentation +│ │ └── ... +│ ├── en/ # English documentation +│ │ ├── DEPLOYMENT.md # Deployment documentation +│ │ ├── VERSION_MANAGEMENT.md # Version management documentation +│ │ └── ... +│ └── copy-trading-requirements.md # Copy trading system requirements +├── .github/workflows/ # GitHub Actions workflows +└── README.md # Project description +``` + +## 🛠️ Development Environment Setup + +### Prerequisites + +- **JDK**: 17+ +- **Node.js**: 18+ +- **MySQL**: 8.0+ +- **Gradle**: 7.5+ (or use Gradle Wrapper) +- **Docker**: 20.10+ (optional, for containerized deployment) + +### Backend Development Environment + +1. **Clone Repository** + +```bash +git clone https://github.com/WrBug/PolyHermes.git +cd PolyHermes +``` + +2. **Configure Database** + +Create MySQL database: + +```sql +CREATE DATABASE polyhermes CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +``` + +3. **Configure Environment Variables** + +Edit `backend/src/main/resources/application.properties` or use environment variables: + +```properties +# Database configuration +spring.datasource.url=jdbc:mysql://localhost:3306/polyhermes?useSSL=false&serverTimezone=UTC&characterEncoding=utf8mb4 +spring.datasource.username=${DB_USERNAME:root} +spring.datasource.password=${DB_PASSWORD:password} + +# Server port +server.port=${SERVER_PORT:8000} + +# Polygon RPC +polygon.rpc.url=${POLYGON_RPC_URL:https://polygon-rpc.com} + +# JWT secret +jwt.secret=${JWT_SECRET:change-me-in-production} + +# Encryption key (for encrypting stored private keys and API Keys) +crypto.secret.key=${CRYPTO_SECRET_KEY:change-me-in-production} +``` + +4. **Start Backend Service** + +```bash +cd backend +./gradlew bootRun +``` + +Backend service will start at `http://localhost:8000`. + +### Frontend Development Environment + +1. **Install Dependencies** + +```bash +cd frontend +npm install +``` + +2. **Configure Environment Variables (Optional)** + +Create `.env` file: + +```env +VITE_API_URL=http://localhost:8000 +VITE_WS_URL=ws://localhost:8000 +``` + +3. **Start Development Server** + +```bash +npm run dev +``` + +Frontend application will start at `http://localhost:3000`. + +## 📝 Code Standards + +### Backend Development Standards + +For detailed standards, please refer to: [Backend Development Standards](.cursor/rules/backend.mdc) + +**Core Standards**: +- Follow Kotlin coding standards +- Controller methods **must not** use `suspend` +- Entity ID fields use `Long? = null` +- All time fields use `Long` timestamps (milliseconds) +- Use `BigDecimal` for numerical calculations +- Use `ErrorCode` enum to define error codes and messages +- **Do not** add TODO comments in code +- **Do not** directly return mock data + +### Frontend Development Standards + +For detailed standards, please refer to: [Frontend Development Standards](.cursor/rules/frontend.mdc) + +**Core Standards**: +- Use TypeScript type definitions +- Use functional components and Hooks +- **Do not** use `any` type +- **Must** use internationalization (i18n) for all text display +- **Must** use `formatUSDC` function to format USDC amounts +- **Must** support mobile and desktop +- **Do not** add TODO comments in code + +### Commit Standards + +Follow [Conventional Commits](https://www.conventionalcommits.org/) standards: + +- `feat`: New feature +- `fix`: Bug fix +- `docs`: Documentation update +- `style`: Code style adjustment +- `refactor`: Code refactoring +- `test`: Test related +- `chore`: Build/tool related + +Examples: +```bash +git commit -m "feat: Add version number display feature" +git commit -m "fix: Fix order status update issue" +``` + +## 📡 API Documentation + +### Unified Response Format + +All API interfaces use POST method uniformly, response format as follows: + +```json +{ + "code": 0, + "data": {}, + "msg": "" +} +``` + +- `code`: Response code, 0 means success, non-0 means failure +- `data`: Response data, can be any type +- `msg`: Response message, usually empty on success, contains error message on failure + +### Error Code Standards + +- `0`: Success +- `1001-1999`: Parameter error +- `2001-2999`: Authentication/permission error +- `3001-3999`: Resource not found +- `4001-4999`: Business logic error +- `5001-5999`: Server internal error + +### Main API Interfaces + +#### Account Management + +- `POST /api/accounts/list` - Get account list +- `POST /api/accounts/import` - Import account (via private key) +- `POST /api/accounts/detail` - Get account details +- `POST /api/accounts/edit` - Edit account +- `POST /api/accounts/delete` - Delete account +- `POST /api/accounts/balance` - Get account balance + +#### Leader Management + +- `POST /api/leaders/list` - Get Leader list +- `POST /api/leaders/add` - Add Leader +- `POST /api/leaders/edit` - Edit Leader +- `POST /api/leaders/delete` - Delete Leader + +#### Copy Trading Templates + +- `POST /api/templates/list` - Get template list +- `POST /api/templates/add` - Add template +- `POST /api/templates/edit` - Edit template +- `POST /api/templates/delete` - Delete template + +#### Copy Trading Configuration + +- `POST /api/copy-trading/list` - Get copy trading configuration list +- `POST /api/copy-trading/add` - Add copy trading configuration +- `POST /api/copy-trading/edit` - Edit copy trading configuration +- `POST /api/copy-trading/delete` - Delete copy trading configuration +- `POST /api/copy-trading/enable` - Enable copy trading +- `POST /api/copy-trading/disable` - Disable copy trading + +#### Order Management + +- `POST /api/copy-trading/orders/buy` - Get buy order list +- `POST /api/copy-trading/orders/sell` - Get sell order list +- `POST /api/copy-trading/orders/matched` - Get matched order list + +#### Statistical Analysis + +- `POST /api/statistics/global` - Get global statistics +- `POST /api/statistics/leader` - Get Leader statistics +- `POST /api/statistics/category` - Get category statistics +- `POST /api/copy-trading/statistics` - Get copy trading relationship statistics + +#### Position Management + +- `POST /api/positions/list` - Get position list +- `POST /api/positions/sell` - Sell position +- `POST /api/positions/redeem` - Redeem position + +#### System Management + +- `POST /api/system-settings/proxy` - Configure proxy +- `POST /api/system-settings/api-health` - Get API health status +- `POST /api/users/list` - Get user list +- `POST /api/users/add` - Add user +- `POST /api/users/edit` - Edit user +- `POST /api/users/delete` - Delete user + +For detailed API interface documentation, please refer to: [Copy Trading System Requirements](../zh/copy-trading-requirements.md) + +## 🗄️ Database Design + +### Main Data Tables + +- `accounts` - Account table +- `leaders` - Leader table +- `templates` - Copy trading template table +- `copy_trading` - Copy trading configuration table +- `copy_orders` - Copy trading order table +- `positions` - Position table +- `users` - User table +- `system_settings` - System settings table + +Database migration scripts are located at `backend/src/main/resources/db/migration/`, managed using Flyway. + +## 🎨 Frontend Development Guide + +### Project Structure + +``` +frontend/src/ +├── components/ # Common components +│ ├── Layout.tsx # Layout component (supports mobile) +│ └── Logo.tsx # Logo component +├── pages/ # Page components +│ ├── AccountList.tsx +│ ├── LeaderList.tsx +│ ├── CopyTradingList.tsx +│ └── ... +├── services/ # API services +│ ├── api.ts # API service definitions +│ └── websocket.ts # WebSocket service +├── store/ # State management (Zustand) +├── types/ # TypeScript type definitions +├── utils/ # Utility functions +│ ├── index.ts # Unified export +│ ├── ethers.ts # Ethereum related utilities +│ ├── auth.ts # Authentication related utilities +│ └── version.ts # Version number utilities +├── hooks/ # React Hooks +├── locales/ # Internationalization resources +│ ├── zh-CN/ +│ ├── zh-TW/ +│ └── en/ +└── styles/ # Style files +``` + +### Internationalization Support + +The project supports multiple languages (Simplified Chinese, Traditional Chinese, English), using `react-i18next`. + +**Adding New Translations**: +1. Add translations in `src/locales/{locale}/common.json` +2. Use `useTranslation` Hook in components: + +```typescript +import { useTranslation } from 'react-i18next' + +const MyComponent: React.FC = () => { + const { t } = useTranslation() + return
{t('key')}
+} +``` + +### Mobile Adaptation + +- Use `react-responsive` to detect device type +- Breakpoint settings: Mobile < 768px, Desktop >= 768px +- Use responsive layouts and components + +### Utility Functions + +**USDC Amount Formatting**: +```typescript +import { formatUSDC } from '../utils' + +const balance = formatUSDC('1.23456') // "1.2345" +``` + +**Ethereum Address Validation**: +```typescript +import { isValidWalletAddress } from '../utils' + +if (isValidWalletAddress(address)) { + // Address is valid +} +``` + +## ⚙️ Backend Development Guide + +### Project Structure + +``` +backend/src/main/kotlin/com/wrbug/polymarketbot/ +├── api/ # API interface definitions (Retrofit) +│ ├── PolymarketClobApi.kt +│ ├── PolymarketGammaApi.kt +│ └── GitHubApi.kt +├── controller/ # REST controllers +├── service/ # Business logic services +├── entity/ # Database entities +├── repository/ # Data access layer +├── dto/ # Data Transfer Objects +├── util/ # Utility classes +│ ├── CryptoUtils.kt # Encryption utilities +│ ├── RetrofitFactory.kt # Retrofit factory +│ └── ... +└── websocket/ # WebSocket handling +``` + +### Creating New API Interface + +1. **Define Retrofit Interface** (in `api/` directory): + +```kotlin +interface MyApi { + @POST("/endpoint") + suspend fun myMethod(@Body request: MyRequest): Response +} +``` + +2. **Create Service** (in `service/` directory): + +```kotlin +@Service +class MyService( + private val myApi: MyApi +) { + suspend fun doSomething(): Result { + // Business logic + } +} +``` + +3. **Create Controller** (in `controller/` directory): + +```kotlin +@RestController +@RequestMapping("/api/my") +class MyController( + private val myService: MyService, + private val messageSource: MessageSource +) { + @PostMapping("/list") + fun list(@RequestBody request: MyListRequest): ResponseEntity> { + return try { + val data = runBlocking { myService.getList(request) } + ResponseEntity.ok(ApiResponse.success(data)) + } catch (e: Exception) { + logger.error("Failed to get list", e) + ResponseEntity.ok(ApiResponse.error(ErrorCode.SERVER_ERROR, messageSource = messageSource)) + } + } +} +``` + +### Database Operations + +Using Spring Data JPA: + +```kotlin +@Repository +interface MyRepository : JpaRepository { + fun findByCode(code: String): MyEntity? + fun findByCategory(category: String): List +} +``` + +### Encrypted Storage + +Use `CryptoUtils` to encrypt sensitive data: + +```kotlin +@Autowired +private lateinit var cryptoUtils: CryptoUtils + +// Encrypt +val encrypted = cryptoUtils.encrypt("sensitive-data") + +// Decrypt +val decrypted = cryptoUtils.decrypt(encrypted) +``` + +## 🔧 FAQ + +### Q1: How to add a new page? + +1. Create page component in `frontend/src/pages/` +2. Add route in `frontend/src/App.tsx` +3. Add menu item in `frontend/src/components/Layout.tsx` (if needed) + +### Q2: How to add a new API interface? + +1. Create Controller in `backend/src/main/kotlin/.../controller/` +2. Create Service in `backend/src/main/kotlin/.../service/` +3. Add API call method in `frontend/src/services/api.ts` + +### Q3: How to add a database table? + +1. Create Entity class (in `entity/` directory) +2. Create Repository interface (in `repository/` directory) +3. Create Flyway migration script (in `resources/db/migration/`) + +### Q4: How to test WebSocket? + +Use browser console or WebSocket client tool to connect to `ws://localhost:8000/ws` + +### Q5: How to debug backend code? + +1. Use IDE's debugging feature (IntelliJ IDEA, VS Code, etc.) +2. Add logs in code: `logger.debug("Debug info")` +3. View log output: `./gradlew bootRun` or view log files + +## 📚 Related Documentation + +- [Deployment Documentation](../zh/DEPLOYMENT.md) / [English](../en/DEPLOYMENT.md) - Detailed deployment guide +- [Version Management Documentation](../zh/VERSION_MANAGEMENT.md) / [English](../en/VERSION_MANAGEMENT.md) - Version number management and auto-build +- [Copy Trading System Requirements](../zh/copy-trading-requirements.md) - Backend API interface documentation +- [Frontend Requirements](../zh/copy-trading-frontend-requirements.md) - Frontend feature documentation + +## 🤝 Contributing + +Contributions are welcome! Please follow these steps: + +1. Fork this repository +2. Create a feature branch (`git checkout -b feature/AmazingFeature`) +3. Follow code standards +4. Commit your changes (`git commit -m 'feat: Add some AmazingFeature'`) +5. Push to the branch (`git push origin feature/AmazingFeature`) +6. Open a Pull Request + +--- + +**Happy Coding! 🚀** + diff --git a/docs/VERSION_MANAGEMENT_EN.md b/docs/en/VERSION_MANAGEMENT.md similarity index 99% rename from docs/VERSION_MANAGEMENT_EN.md rename to docs/en/VERSION_MANAGEMENT.md index 36f9fba..2cf5cf7 100644 --- a/docs/VERSION_MANAGEMENT_EN.md +++ b/docs/en/VERSION_MANAGEMENT.md @@ -1,5 +1,7 @@ # Version Management Guide +> 📖 **中文版本**: [版本号管理说明(中文)](../zh/VERSION_MANAGEMENT.md) + ## Overview This project supports automatic version number management and display. When creating a release tag on GitHub, it automatically triggers GitHub Actions to build Docker images and push them to Docker Hub, while displaying the version number after the frontend title. diff --git a/docs/en/nginx-reverse-proxy.conf b/docs/en/nginx-reverse-proxy.conf new file mode 100644 index 0000000..92c39b0 --- /dev/null +++ b/docs/en/nginx-reverse-proxy.conf @@ -0,0 +1,170 @@ +# PolyHermes Nginx 反向代理配置示例 +# +# 适用于生产环境,在 Docker 容器外部部署 Nginx 作为反向代理 +# +# 使用场景: +# - SSL/TLS 终止(HTTPS) +# - 域名绑定 +# - 负载均衡 +# - 更灵活的配置 +# +# 部署步骤: +# 1. 将本文件复制到 /etc/nginx/sites-available/polyhermes +# 2. 创建软链接: ln -s /etc/nginx/sites-available/polyhermes /etc/nginx/sites-enabled/ +# 3. 修改配置中的域名和 SSL 证书路径 +# 4. 测试配置: nginx -t +# 5. 重载配置: systemctl reload nginx + +# HTTP 服务器(可选:用于重定向到 HTTPS) +server { + listen 80; + server_name your-domain.com www.your-domain.com; + + # 重定向到 HTTPS + return 301 https://$server_name$request_uri; +} + +# HTTPS 服务器 +server { + listen 443 ssl http2; + server_name your-domain.com www.your-domain.com; + + # SSL 证书配置(使用 Let's Encrypt 或其他证书) + ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem; + + # SSL 安全配置 + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384'; + ssl_prefer_server_ciphers on; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 10m; + + # 安全头 + add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-Content-Type-Options "nosniff" always; + add_header X-XSS-Protection "1; mode=block" always; + + # 日志 + access_log /var/log/nginx/polyhermes-access.log; + error_log /var/log/nginx/polyhermes-error.log; + + # 客户端最大上传大小 + client_max_body_size 10M; + + # 上游服务(Docker 容器) + # 如果使用 docker-compose,容器名是 polyhermes,端口是 80 + upstream polyhermes_backend { + server 127.0.0.1:80; + # 如果需要负载均衡,可以添加多个后端: + # server 127.0.0.1:8001; + # server 127.0.0.1:8002; + } + + # API 代理 + location /api { + proxy_pass http://polyhermes_backend; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + + # 超时设置 + proxy_connect_timeout 60s; + proxy_send_timeout 60s; + proxy_read_timeout 60s; + + # 缓冲设置 + proxy_buffering on; + proxy_buffer_size 4k; + proxy_buffers 8 4k; + proxy_busy_buffers_size 8k; + } + + # WebSocket 代理 + location /ws { + proxy_pass http://polyhermes_backend; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + + # WebSocket 超时设置(长连接) + proxy_connect_timeout 7d; + proxy_send_timeout 7d; + proxy_read_timeout 7d; + } + + # 前端静态文件代理 + location / { + proxy_pass http://polyhermes_backend; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + + # 静态资源缓存(由后端 Nginx 处理) + proxy_cache_valid 200 1y; + } + + # 健康检查(可选) + location /health { + proxy_pass http://polyhermes_backend; + access_log off; + } +} + +# 如果不需要 HTTPS,可以使用以下简化配置 +# server { +# listen 80; +# server_name your-domain.com www.your-domain.com; +# +# access_log /var/log/nginx/polyhermes-access.log; +# error_log /var/log/nginx/polyhermes-error.log; +# +# client_max_body_size 10M; +# +# upstream polyhermes_backend { +# server 127.0.0.1:80; +# } +# +# location /api { +# proxy_pass http://polyhermes_backend; +# proxy_set_header Host $host; +# proxy_set_header X-Real-IP $remote_addr; +# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +# proxy_set_header X-Forwarded-Proto $scheme; +# } +# +# location /ws { +# proxy_pass http://polyhermes_backend; +# proxy_http_version 1.1; +# proxy_set_header Upgrade $http_upgrade; +# proxy_set_header Connection "upgrade"; +# proxy_set_header Host $host; +# proxy_set_header X-Real-IP $remote_addr; +# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +# proxy_set_header X-Forwarded-Proto $scheme; +# proxy_read_timeout 86400; +# proxy_send_timeout 86400; +# } +# +# location / { +# proxy_pass http://polyhermes_backend; +# proxy_set_header Host $host; +# proxy_set_header X-Real-IP $remote_addr; +# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +# proxy_set_header X-Forwarded-Proto $scheme; +# } +# } + diff --git a/docs/DEPLOYMENT.md b/docs/zh/DEPLOYMENT.md similarity index 98% rename from docs/DEPLOYMENT.md rename to docs/zh/DEPLOYMENT.md index 6d5cdd9..686271c 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/zh/DEPLOYMENT.md @@ -206,7 +206,7 @@ docker-compose -f docker-compose.prod.yml up -d ```bash # 1. 下载 Nginx 配置示例 -curl -O https://raw.githubusercontent.com/WrBug/PolyHermes/main/docs/nginx-reverse-proxy.conf +curl -O https://raw.githubusercontent.com/WrBug/PolyHermes/main/docs/zh/nginx-reverse-proxy.conf # 2. 复制到 Nginx 配置目录 sudo cp nginx-reverse-proxy.conf /etc/nginx/sites-available/polyhermes @@ -254,7 +254,7 @@ ports: **Nginx 配置说明**: -- 配置文件位置:`docs/nginx-reverse-proxy.conf` +- 配置文件位置:`docs/zh/nginx-reverse-proxy.conf` - 支持 HTTPS(SSL/TLS) - 支持 WebSocket 代理 - 包含安全头设置 @@ -262,6 +262,8 @@ ports: 详细配置示例请参考:[Nginx 反向代理配置](nginx-reverse-proxy.conf) +> 📖 **English Version**: [Deployment Guide (English)](../en/DEPLOYMENT.md) + ## 后端部署 ### Java 直接部署 diff --git a/docs/DEVELOPMENT.md b/docs/zh/DEVELOPMENT.md similarity index 97% rename from docs/DEVELOPMENT.md rename to docs/zh/DEVELOPMENT.md index 8c146a9..a4e2771 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/zh/DEVELOPMENT.md @@ -491,8 +491,9 @@ val decrypted = cryptoUtils.decrypt(encrypted) ## 📚 相关文档 -- [部署文档](DEPLOYMENT.md) - 详细的部署指南 -- [版本号管理文档](VERSION_MANAGEMENT.md) - 版本号管理和自动构建 +- [部署文档](DEPLOYMENT.md) / [English](../en/DEPLOYMENT.md) - 详细的部署指南 +- [版本号管理文档](VERSION_MANAGEMENT.md) / [English](../en/VERSION_MANAGEMENT.md) - 版本号管理和自动构建 +- [开发文档](DEVELOPMENT.md) / [English](../en/DEVELOPMENT.md) - 开发指南 - [跟单系统需求文档](copy-trading-requirements.md) - 后端 API 接口文档 - [前端需求文档](copy-trading-frontend-requirements.md) - 前端功能文档 diff --git a/docs/VERSION_MANAGEMENT.md b/docs/zh/VERSION_MANAGEMENT.md similarity index 99% rename from docs/VERSION_MANAGEMENT.md rename to docs/zh/VERSION_MANAGEMENT.md index 904356e..d41bd1b 100644 --- a/docs/VERSION_MANAGEMENT.md +++ b/docs/zh/VERSION_MANAGEMENT.md @@ -1,5 +1,7 @@ # 版本号管理说明 +> 📖 **English Version**: [Version Management Guide (English)](../en/VERSION_MANAGEMENT.md) + ## 概述 本项目支持自动版本号管理和显示。当在 GitHub 创建 release tag 时,会自动触发 GitHub Actions 构建 Docker 镜像并推送到 Docker Hub,同时在前端标题后显示版本号。 diff --git a/docs/copy-trading-frontend-requirements.md b/docs/zh/copy-trading-frontend-requirements.md similarity index 100% rename from docs/copy-trading-frontend-requirements.md rename to docs/zh/copy-trading-frontend-requirements.md diff --git a/docs/copy-trading-implementation.md b/docs/zh/copy-trading-implementation.md similarity index 100% rename from docs/copy-trading-implementation.md rename to docs/zh/copy-trading-implementation.md diff --git a/docs/copy-trading-order-tracking-design.md b/docs/zh/copy-trading-order-tracking-design.md similarity index 100% rename from docs/copy-trading-order-tracking-design.md rename to docs/zh/copy-trading-order-tracking-design.md diff --git a/docs/copy-trading-requirements.md b/docs/zh/copy-trading-requirements.md similarity index 100% rename from docs/copy-trading-requirements.md rename to docs/zh/copy-trading-requirements.md diff --git a/docs/github-api-rate-limit-alternatives.md b/docs/zh/github-api-rate-limit-alternatives.md similarity index 100% rename from docs/github-api-rate-limit-alternatives.md rename to docs/zh/github-api-rate-limit-alternatives.md diff --git a/docs/github-token-setup.md b/docs/zh/github-token-setup.md similarity index 100% rename from docs/github-token-setup.md rename to docs/zh/github-token-setup.md diff --git a/docs/zh/nginx-reverse-proxy.conf b/docs/zh/nginx-reverse-proxy.conf new file mode 100644 index 0000000..92c39b0 --- /dev/null +++ b/docs/zh/nginx-reverse-proxy.conf @@ -0,0 +1,170 @@ +# PolyHermes Nginx 反向代理配置示例 +# +# 适用于生产环境,在 Docker 容器外部部署 Nginx 作为反向代理 +# +# 使用场景: +# - SSL/TLS 终止(HTTPS) +# - 域名绑定 +# - 负载均衡 +# - 更灵活的配置 +# +# 部署步骤: +# 1. 将本文件复制到 /etc/nginx/sites-available/polyhermes +# 2. 创建软链接: ln -s /etc/nginx/sites-available/polyhermes /etc/nginx/sites-enabled/ +# 3. 修改配置中的域名和 SSL 证书路径 +# 4. 测试配置: nginx -t +# 5. 重载配置: systemctl reload nginx + +# HTTP 服务器(可选:用于重定向到 HTTPS) +server { + listen 80; + server_name your-domain.com www.your-domain.com; + + # 重定向到 HTTPS + return 301 https://$server_name$request_uri; +} + +# HTTPS 服务器 +server { + listen 443 ssl http2; + server_name your-domain.com www.your-domain.com; + + # SSL 证书配置(使用 Let's Encrypt 或其他证书) + ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem; + + # SSL 安全配置 + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384'; + ssl_prefer_server_ciphers on; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 10m; + + # 安全头 + add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-Content-Type-Options "nosniff" always; + add_header X-XSS-Protection "1; mode=block" always; + + # 日志 + access_log /var/log/nginx/polyhermes-access.log; + error_log /var/log/nginx/polyhermes-error.log; + + # 客户端最大上传大小 + client_max_body_size 10M; + + # 上游服务(Docker 容器) + # 如果使用 docker-compose,容器名是 polyhermes,端口是 80 + upstream polyhermes_backend { + server 127.0.0.1:80; + # 如果需要负载均衡,可以添加多个后端: + # server 127.0.0.1:8001; + # server 127.0.0.1:8002; + } + + # API 代理 + location /api { + proxy_pass http://polyhermes_backend; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + + # 超时设置 + proxy_connect_timeout 60s; + proxy_send_timeout 60s; + proxy_read_timeout 60s; + + # 缓冲设置 + proxy_buffering on; + proxy_buffer_size 4k; + proxy_buffers 8 4k; + proxy_busy_buffers_size 8k; + } + + # WebSocket 代理 + location /ws { + proxy_pass http://polyhermes_backend; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + + # WebSocket 超时设置(长连接) + proxy_connect_timeout 7d; + proxy_send_timeout 7d; + proxy_read_timeout 7d; + } + + # 前端静态文件代理 + location / { + proxy_pass http://polyhermes_backend; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + + # 静态资源缓存(由后端 Nginx 处理) + proxy_cache_valid 200 1y; + } + + # 健康检查(可选) + location /health { + proxy_pass http://polyhermes_backend; + access_log off; + } +} + +# 如果不需要 HTTPS,可以使用以下简化配置 +# server { +# listen 80; +# server_name your-domain.com www.your-domain.com; +# +# access_log /var/log/nginx/polyhermes-access.log; +# error_log /var/log/nginx/polyhermes-error.log; +# +# client_max_body_size 10M; +# +# upstream polyhermes_backend { +# server 127.0.0.1:80; +# } +# +# location /api { +# proxy_pass http://polyhermes_backend; +# proxy_set_header Host $host; +# proxy_set_header X-Real-IP $remote_addr; +# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +# proxy_set_header X-Forwarded-Proto $scheme; +# } +# +# location /ws { +# proxy_pass http://polyhermes_backend; +# proxy_http_version 1.1; +# proxy_set_header Upgrade $http_upgrade; +# proxy_set_header Connection "upgrade"; +# proxy_set_header Host $host; +# proxy_set_header X-Real-IP $remote_addr; +# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +# proxy_set_header X-Forwarded-Proto $scheme; +# proxy_read_timeout 86400; +# proxy_send_timeout 86400; +# } +# +# location / { +# proxy_pass http://polyhermes_backend; +# proxy_set_header Host $host; +# proxy_set_header X-Real-IP $remote_addr; +# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +# proxy_set_header X-Forwarded-Proto $scheme; +# } +# } + diff --git a/docs/position-sell-order-design.md b/docs/zh/position-sell-order-design.md similarity index 100% rename from docs/position-sell-order-design.md rename to docs/zh/position-sell-order-design.md diff --git a/docs/ternary-market-orderbook.md b/docs/zh/ternary-market-orderbook.md similarity index 100% rename from docs/ternary-market-orderbook.md rename to docs/zh/ternary-market-orderbook.md diff --git a/docs/websocket-push-service-design.md b/docs/zh/websocket-push-service-design.md similarity index 100% rename from docs/websocket-push-service-design.md rename to docs/zh/websocket-push-service-design.md