Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .claudeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# .claudeignore - Claude Code 上下文排除规则
# 本文件定义了在 AI 上下文分析时应该忽略的文件和目录

# ==================== Python 相关 ====================
# Python 编译缓存
__pycache__/
*.py[cod]
*$py.class
*.so

# 虚拟环境目录
venv/
ENV/
env/
.venv

# 测试和覆盖率
.pytest_cache/
.coverage
htmlcov/
*.cover
.hypothesis/

# ==================== 环境变量和敏感信息 ====================
# 环境变量文件(保留 .env.example 作为模板参考)
.env
.env.local
.env.*.local

# 自定义请求头配置(可能包含敏感信息)
env/.env.headers.json

# ==================== Docker 相关 ====================
# Docker 数据目录
docker-data/
volumes/

# ==================== IDE 和编辑器 ====================
# VS Code
.vscode/
*.code-workspace

# JetBrains IDEs
.idea/
*.iml

# Vim
*.swp
*.swo
*~

# macOS
.DS_Store
.AppleDouble
.LSOverride

# ==================== 日志和临时文件 ====================
# 日志文件
*.log
logs/
*.log.*

# 临时文件
*.tmp
*.temp
.cache/

# ==================== 构建和分发 ====================
# 构建产物
dist/
build/
*.egg-info/

# ==================== 规范工作流(可选) ====================
# 如果不希望 AI 分析规范文档,可以取消下面的注释
# .spec-workflow/

# ==================== Git 相关 ====================
.git/
.gitignore

# ==================== 其他 ====================
# Node.js (如果未来添加前端)
node_modules/
package-lock.json
yarn.lock

# 压缩文件
*.zip
*.tar.gz
*.rar
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ __pycache__
.venv
venv/
ENV/
env/
# env/ - 注释掉,因为我们需要 env/ 配置目录
*.egg-info
dist/
build/
Expand Down
18 changes: 17 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# 后端 API 配置
API_BASE_URL=https://anyrouter.top

# System Prompt 配置
Expand All @@ -16,4 +17,19 @@ SYSTEM_PROMPT_BLOCK_INSERT_IF_NOT_EXIST=false
DEBUG_MODE=false

# 服务端口配置:默认 8088
PORT=8088
PORT=8088

# ==========================================
# Web 管理面板配置
# ==========================================

# 启用管理面板
ENABLE_DASHBOARD=true

# 管理面板 API Key(用于保护管理面板)
# 请修改为强密码,格式:Bearer Token 可以是任意字符串
DASHBOARD_API_KEY=your-secret-api-key-change-me-please

# 生产环境建议使用更强的密码:
# DASHBOARD_API_KEY=$(openssl rand -hex 32) # Linux/macOS
# DASHBOARD_API_KEY=[Random-PowerShell-Command] # Windows PowerShell
209 changes: 209 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
name: CI/CD Pipeline

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
workflow_dispatch:

env:
NODE_VERSION: '20'
PYTHON_VERSION: '3.12'

jobs:
# 代码质量检查
lint-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: frontend/package-lock.json

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: requirements.txt

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest flake8

- name: Lint Python code
run: |
flake8 app.py --max-line-length=120 --ignore=E203,W503

- name: Install frontend dependencies
working-directory: ./frontend
run: npm ci

- name: Type check frontend
working-directory: ./frontend
run: npm run type-check

- name: Lint frontend
working-directory: ./frontend
run: npm run lint || true # 允许 lint 失败

- name: Test backend
run: |
# 这里添加后端测试命令
echo "Backend tests would run here"

- name: Test frontend
working-directory: ./frontend
run: |
# 这里添加前端测试命令
npm run test:unit || true # 允许测试失败

# 构建应用
build:
runs-on: ubuntu-latest
needs: lint-and-test

strategy:
matrix:
build_mode: [production, development]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: frontend/package-lock.json

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: requirements.txt

- name: Make scripts executable
run: |
chmod +x scripts/*.sh

- name: Build application
run: |
./scripts/build.sh --${{ matrix.build_mode }}

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: build-${{ matrix.build_mode }}
path: "*.tar.gz"
retention-days: 30

# 构建和测试 Docker 镜像
docker:
runs-on: ubuntu-latest
needs: lint-and-test
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: anyrouter-proxy:test
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Test Docker image
run: |
# 启动容器进行基本测试
docker run -d --name test-container \
-e PORT=8088 \
-e ENABLE_DASHBOARD=true \
-e DASHBOARD_API_KEY=test-key \
-p 8088:8088 \
anyrouter-proxy:test

# 等待容器启动
sleep 10

# 健康检查
curl -f http://localhost:8088/health || exit 1

# 清理
docker stop test-container
docker rm test-container

# 发布镜像(仅在 main 分支)
publish:
runs-on: ubuntu-latest
needs: [build, docker]
if: github.ref == 'refs/heads/main' && github.repository_owner == 'your-username'
environment: production

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: your-username/anyrouter-transparent-proxy
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# 部署(可选)
deploy:
runs-on: ubuntu-latest
needs: publish
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
environment: production

steps:
- name: Deploy to production
run: |
# 这里添加部署脚本
echo "Deploy to production server"
# 例如:
# ssh ${{ secrets.DEPLOY_HOST }} "cd /app && docker-compose pull && docker-compose up -d"
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,17 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# NodeJS
node_modules/

# !CLAUDE.md
# !AGENT.md
# !README*.md
# Claude Code 个人配置
.claude/

# Spec Workflow 审批临时数据
.spec-workflow/approvals/

# 前端构建产物(由 Docker 构建时生成)
static/
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"filePath": ".spec-workflow/steering/product.md",
"currentVersion": 1,
"snapshots": [
{
"version": 1,
"filename": "snapshot-001.json",
"timestamp": "2025-12-09T15:16:44.711Z",
"trigger": "initial",
"approvalId": "approval_1765293404707_duz45tifp",
"approvalTitle": "Product 文档审批"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "snapshot_1765293404711_sa7fmc0mr",
"approvalId": "approval_1765293404707_duz45tifp",
"approvalTitle": "Product 文档审批",
"version": 1,
"timestamp": "2025-12-09T15:16:44.711Z",
"trigger": "initial",
"status": "pending",
"content": "# Product Overview\n\n## Product Purpose\nAnyRouter Transparent Proxy 是一个专为解决 AnyRouter 的 Anthropic API 在 Claude Code for VS Code 插件中报错 500 问题而设计的轻量级透明 HTTP 代理服务。该产品提供完全透明的 API 代理能力,使开发者能够无缝集成 Claude AI 服务,同时解决网络兼容性和访问限制问题。\n\n## Target Users\n### 主要用户群体\n- **Claude Code 用户**: 使用 VS Code Claude Code 插件的开发者,遇到 AnyRouter API 500 错误问题\n- **企业开发者**: 需要在受限网络环境中使用 Anthropic API 的开发团队\n- **独立开发者**: 寻求稳定、高性能 AI API 代理解决方案的个人开发者\n- **DevOps 工程师**: 负责部署和维护 API 代理基础设施的技术人员\n\n### 用户痛点\n- Claude Code 插件与 AnyRouter API 兼容性问题\n- 网络访问限制和防火墙阻碍\n- 需要透明的 API 代理而不影响现有代码逻辑\n- 缺乏可靠的流式响应支持\n- 生产环境对稳定性和性能的高要求\n\n## Key Features\n### 1. **完全透明代理**\n支持所有 HTTP 方法(GET、POST、PUT、DELETE 等),无缝代理请求,无需修改客户端代码\n\n### 2. **智能 System Prompt 处理**\n- 支持 System Prompt 动态替换模式\n- 支持智能插入模式(检测关键字后决定插入或替换)\n- 仅对 `/v1/messages` 路由执行处理,避免影响其他 API\n\n### 3. **高性能流式响应**\n- 基于异步架构的流式传输\n- 完整支持 SSE (Server-Sent Events)\n- 零拷贝转发,最大化性能\n\n### 4. **企业级可靠性**\n- 严格遵循 RFC 7230 HTTP/1.1 规范\n- 自动过滤 hop-by-hop 头部\n- 连接池复用,支持高并发\n- 优雅的错误处理和资源管理\n\n### 5. **灵活的配置管理**\n- 环境变量配置\n- 自定义请求头注入\n- Docker 容器化部署支持\n\n## Business Objectives\n- **解决兼容性问题**: 消除 Claude Code 与 AnyRouter API 之间的 500 错误\n- **提供企业级稳定性**: 确保生产环境的可靠运行\n- **简化部署流程**: 通过 Docker 化简化安装和维护\n- **支持开发者生态**: 为使用 Anthropic API 的开发者提供基础设施支持\n- **建立技术标准**: 在 API 代理领域建立最佳实践标准\n\n## Success Metrics\n### 技术指标\n- **可用性**: 99.9% 服务正常运行时间\n- **响应延迟**: 代理延迟 < 50ms (P99)\n- **并发处理**: 支持 1000+ 并发连接\n- **错误率**: 代理服务错误率 < 0.1%\n\n### 用户满意度\n- **集成成功率**: 用户一次性集成成功率 > 95%\n- **问题解决率**: Claude Code 500 错误解决率 = 100%\n- **文档完整性**: 完整的部署和使用文档覆盖\n\n## Product Principles\n### 1. **透明优先 (Transparency First)**\n代理服务对客户端完全透明,不改变原有的 API 调用方式和响应格式\n\n### 2. **性能至上 (Performance First)**\n采用异步架构和连接池复用,确保最低延迟和最高吞吐量\n\n### 3. **标准兼容 (Standards Compliant)**\n严格遵循 HTTP RFC 规范,确保与各种 HTTP 客户端的兼容性\n\n### 4. **开发者友好 (Developer Friendly)**\n提供清晰的文档、简单的配置和详细的错误信息\n\n### 5. **生产就绪 (Production Ready)**\n内置健康检查、优雅关闭和资源管理等生产环境必需功能\n\n## Monitoring & Visibility\n### 健康监控\n- **健康检查端点**: `/health` 端点用于容器监控和负载均衡\n- **实时状态**: 服务运行状态和基本指标\n- **Docker 集成**: 支持 Docker 健康检查机制\n\n### 日志系统\n- **结构化日志**: 带前缀的分类日志(Proxy、System Replacement、Custom Headers 等)\n- **调试模式**: 可选的详细请求/响应日志\n- **错误追踪**: 详细的错误信息和堆栈跟踪\n\n### 部署监控\n- **容器状态**: Docker Compose 状态监控\n- **资源使用**: CPU、内存、网络使用情况\n- **自动重启**: 容器异常退出时自动重启\n\n## Future Vision\n### 短期增强 (3-6 个月)\n- **多上游支持**: 支持负载均衡和故障转移\n- **请求限流**: 基于 IP 或 API Key 的速率限制\n- **指标收集**: Prometheus metrics 端点支持\n- **日志持久化**: 可选的请求/响应日志存储\n\n### 中期规划 (6-12 个月)\n- **WebSocket 代理**: 支持实时 WebSocket 连接代理\n- **缓存机制**: Redis 集成的智能缓存系统\n- **API Key 管理**: 内置的 API Key 验证和配额管理\n- **Web 管理面板**: 图形化配置和监控界面\n\n### 长期愿景 (1+ 年)\n- **多云支持**: 支持多个云服务提供商的 API\n- **智能路由**: 基于性能和成本的智能请求路由\n- **边缘计算**: CDN 和边缘节点支持\n- **企业功能**: SSO、审计日志、合规性支持\n\n### 技术演进方向\n- **HTTP/3 支持**: 迁移到最新 HTTP 协议版本\n- **机器学习优化**: 智能缓存和路由决策\n- **微服务架构**: 拆分为更小的专业服务\n- **云原生增强**: Kubernetes Operator 和服务网格支持",
"fileStats": {
"size": 4995,
"lines": 119,
"lastModified": "2025-12-09T15:16:26.222Z"
},
"comments": []
}
Loading
Loading