- Node.js: 16.0+
- Python: 3.8+
- Git: 2.0+
- 操作系统: macOS / Linux / Windows
- IDE: VS Code / PyCharm / WebStorm
- 终端: iTerm2 (macOS) / Windows Terminal
- 包管理: npm / yarn (前端), pip / poetry (后端)
git clone https://github.com/ljxpython/aitestlab.git
cd aitestlabcd backend
# 使用 venv
python -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
# 或使用 conda
conda create -n aitestlab python=3.8
conda activate aitestlab# 安装 Python 依赖
pip install -r requirements.txt
# 或使用 poetry
poetry install# 运行数据库初始化脚本
python init_db.py
# 验证数据库创建
ls -la data/ # 应该看到 aitestlab.db 文件cd frontend
# 使用 npm
npm install
# 或使用 yarn
yarn install
# 或使用 pnpm
pnpm install创建 frontend/.env.local 文件:
REACT_APP_API_BASE_URL=http://localhost:8000
REACT_APP_ENV=development
REACT_APP_VERSION=1.0.0编辑 backend/conf/settings.yaml:
test:
# AI模型配置
aimodel:
model: "deepseek-chat"
base_url: "https://api.deepseek.com/v1"
api_key: "your-deepseek-api-key" # 替换为实际API密钥
# JWT配置
SECRET_KEY: "your-secret-key-change-in-production-aitestlab-2024"
ACCESS_TOKEN_EXPIRE_MINUTES: 1440 # 24小时
# 数据库配置
DATABASE_URL: "sqlite://./data/aitestlab.db"
# 日志配置
LOG_LEVEL: "DEBUG"
LOG_FILE: "./logs/app.log"-
DeepSeek API:
- 访问 https://platform.deepseek.com/
- 注册账号并获取API密钥
- 将密钥填入配置文件
-
其他AI服务 (可选):
- OpenAI: https://platform.openai.com/
- Claude: https://console.anthropic.com/
# 查看所有可用命令
make help
# 启动所有服务
make start
# 单独启动后端
make backend
# 单独启动前端
make frontend
# 停止所有服务
make stop
# 重启服务
make restartcd backend
# 激活虚拟环境
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
# 启动 FastAPI 服务
uvicorn __init__:app --host 0.0.0.0 --port 8000 --reload
# 或使用 Python 直接运行
python -m uvicorn __init__:app --host 0.0.0.0 --port 8000 --reloadcd frontend
# 启动 React 开发服务器
npm start
# 或使用 yarn
yarn start- 前端应用: http://localhost:3000
- 后端API: http://localhost:8000
- API文档: http://localhost:8000/docs
- API重定向文档: http://localhost:8000/redoc
# 检查后端服务
curl http://localhost:8000/health
# 检查前端服务
curl http://localhost:3000{
"recommendations": [
"ms-python.python",
"ms-python.black-formatter",
"ms-python.isort",
"bradlc.vscode-tailwindcss",
"esbenp.prettier-vscode",
"ms-vscode.vscode-typescript-next",
"ms-vscode.vscode-json"
]
}创建 .vscode/settings.json:
{
"python.defaultInterpreterPath": "./backend/venv/bin/python",
"python.formatting.provider": "black",
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}创建 .git/hooks/pre-commit:
#!/bin/sh
# 代码格式化检查
echo "Running pre-commit checks..."
# Python 代码检查
cd backend
black --check .
isort --check-only .
# TypeScript 代码检查
cd ../frontend
npm run lint
npm run type-check
echo "Pre-commit checks passed!"确保以下内容在 .gitignore 中:
# 环境变量
.env
.env.local
.env.production
# 数据库
*.db
*.sqlite
# 日志文件
logs/
*.log
# IDE
.vscode/
.idea/
*.swp
*.swo
# 操作系统
.DS_Store
Thumbs.db# 查看端口占用
lsof -i :3000 # 前端端口
lsof -i :8000 # 后端端口
# 杀死占用进程
kill -9 <PID>
# 或使用不同端口启动
PORT=3001 npm start # 前端
uvicorn __init__:app --port 8001 # 后端# 清理缓存
npm cache clean --force # 前端
pip cache purge # 后端
# 重新安装
rm -rf node_modules package-lock.json
npm install
rm -rf venv
python -m venv venv
pip install -r requirements.txt# 重新初始化数据库
rm -f backend/data/aitestlab.db
cd backend && python init_db.py
# 检查数据库内容
sqlite3 backend/data/aitestlab.db ".tables"
sqlite3 backend/data/aitestlab.db "SELECT * FROM users;"# macOS/Linux 权限修复
chmod +x scripts/*.sh
sudo chown -R $USER:$USER .
# Windows 权限问题
# 以管理员身份运行终端- Python: 遵循 PEP 8,使用 Black 格式化
- TypeScript: 遵循 ESLint 规则,使用 Prettier 格式化
- 提交信息: 使用约定式提交格式
# 创建功能分支
git checkout -b feature/user-authentication
# 提交代码
git add .
git commit -m "feat: 添加用户认证功能"
# 推送分支
git push origin feature/user-authentication# 后端调试
python -m pdb script.py
# 前端调试
# 使用浏览器开发者工具
# React DevTools 扩展环境搭建完成后,建议阅读:
如果遇到问题:
- 查看 故障排查文档
- 搜索 GitHub Issues
- 提交新的 Issue 或联系维护者