Thank you for your interest in contributing to AI for Investor! This document provides guidelines and instructions for contributors.
- Development Workflow
- Setting Up Development Environment
- Dependency Management
- Running Tests
- Coding Standards
- Submitting Changes
- Code Review Process
This repository uses a two-branch model:
| Branch | Role | Who merges into it |
|---|---|---|
dev |
Daily integration branch | All regular PRs (feature/*, fix/*, docs/*, refactor/*, test/*) |
master |
Release branch | Only release/vX.Y.Z promotion PRs and hotfix/master-* emergency PRs |
Regular changes must target dev, never master. PRs that target master without a
release/* or hotfix/master-* source branch are rejected by the PR Governance gate.
# 1. Fork the repository on GitHub, then clone YOUR fork:
git clone https://github.com/YOUR_USERNAME/backtrader_web.git
cd backtrader_web
# 2. Replace YOUR_USERNAME above with your own GitHub username.
# 3. Add the upstream remote so you can stay in sync with the canonical repo:
git remote add upstream https://github.com/cloudQuant/backtrader_web.git
git fetch upstream
# 4. Base your work on dev (see Branch Model above):
git checkout -b feature/your-feature-name upstream/devgit checkout -b feature/your-feature-name upstream/dev
# or
git checkout -b fix/your-bug-fix upstream/devBranch naming conventions (based on dev unless noted):
feature/- New features → PR todevfix/- Bug fixes → PR todevrefactor/- Code refactoring → PR todevdocs/- Documentation changes → PR todevtest/- Test additions or updates → PR todevrelease/vX.Y.Z- Release promotion, based ondev→ PR tomaster(maintainers)hotfix/master-*- Production emergency fix, based onmaster→ PR tomaster(maintainers, requires an incident reference and a plan to backport the fix todev)
Follow the coding standards outlined below.
Ensure all tests pass before pushing (see Running Tests).
Use conventional commit messages:
git commit -m "feat: add new strategy backtest feature"提交前自检清单:
- 不要提交数据库文件(如
backtrader.db)或其他本地产生的数据副本 - 不要提交 coverage 产物(如
coverage.xml、coverage.json、htmlcov/、.coverage.*) - 不要提交真实
.env、API Key、JWT 密钥、管理员密码或其他敏感配置 - 不要提交 IDE / 系统元数据(如
.DS_Store、.idea/、临时日志、调试输出) - 提交前确认
git status中没有意外的生成文件或大体积产物
Commit types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting, etc.)refactor: Code refactoringtest: Adding or updating testschore: Maintenance tasksperf: Performance improvementsci: CI/CD changes
git push origin feature/your-feature-nameThen create a pull request on GitHub targeting dev (see Branch Model).
The PR template asks for a ## Governance declaration section: declare your target branch,
the risk level (auto-classified from changed paths; labels cannot lower it), and your test
evidence. master hotfix PRs additionally require a backport plan; master release PRs
additionally require a release checklist.
- Python 3.10+
- Node.js 20+
- PostgreSQL 14+ (optional, for integration tests)
- Redis 7+ (optional)
cd src/backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -e ".[dev,postgres,redis,backtrader]"
# Run database migrations
python -c "from app.db.database import init_db; import asyncio; asyncio.run(init_db())"cd src/frontend
# Install dependencies
npm install
# Start development server
npm run devBackend dependency declarations live in src/backend/pyproject.toml. Edit that file when adding,
removing, or changing backend runtime, optional, or development dependencies.
Root config/requirements-dev.lock and config/requirements-prod.lock are generated artifacts for reproducible
installs:
requirements-dev.lockpins the full development toolchain plus optional dependency groups used by local verification.requirements-prod.lockpins the production dependency set used for deployment images and release checks.
Do not hand-edit lock files. Regenerate them after changing src/backend/pyproject.toml:
./scripts/ops/generate_lockfiles.shCommit the updated pyproject.toml and root lock files together. As of iteration 193
(P0-1 anti-drift fix), config/ is the only location for these lockfiles--the former
src/backend/requirements-prod.lock / requirements-dev.lock copies were deleted because
they had drifted from the CI-audited set, leaving the image's shipped dependencies
unaudited. scripts/ci/check_prod_lock_singleton.py runs in CI to prevent a second
requirements-prod.lock from re-appearing; the Dockerfile COPYs
config/requirements-prod.lock directly so the install target equals the audit target.
Iteration 175 introduced an opt-in [tool.uv.workspace] declaration at the repo root so the
two Python member packages (src/backend, src/bt_api_py) can be installed and validated
through a single command. Use the workspace flow when:
- you are working in both
src/backendandsrc/bt_api_pyin one branch and want a single venv resolution to keep their dependencies in lock-step; - you want to run
make check-all(lint + typecheck + tests across all members) before opening a PR.
Use the legacy single-package flow (pip install -e ".[dev]" inside src/backend/) when:
- you are only changing one member;
- you need to mirror the production install path used by deployment images.
- Append the new directory to
[tool.uv.workspace] membersin the rootpyproject.toml. - Ensure that directory has its own
pyproject.toml. - Re-run
uv sync --workspaceto refreshuv.lock. - Run
make workspace-lock-check(=python scripts/dev/check_workspace_lock_conflict.py) to verify the new dependencies do not conflict withconfig/requirements-dev.lock.
config/requirements-dev.lock remains the single source of truth (SSOT) for backend dev
installs. uv.lock is generated by uv sync --workspace for convenience and must remain
consistent with the SSOT — make workspace-lock-check runs in CI's monorepo-check
(advisory) job to catch drift early.
cd src/backend
# Run all tests
pytest
# Run specific test file
pytest tests/test_auth.py
# Run with coverage
pytest --cov=app --cov-report=html
# Run integration tests
pytest -m integration
# Run with verbose output
pytest -vcd src/frontend
# Run all unit tests
npm run test
# Run with coverage
npm run test -- --coverage
# Watch mode
npm run test -- --watch# Using the E2E runner script (recommended)
./scripts/dev/run-e2e.sh
# Or manually
cd src/frontend
npm run test:e2e
# With UI mode
npm run test:e2e:ui
# Debug mode
npm run test:e2e:debug
# Specific browser
npx playwright test --project=chromium
# Specific test file
npx playwright test auth.spec.ts# Start all services
docker compose -f docker/docker-compose.yml -f docker/compose/ci.yml up -d
# Run E2E tests
cd src/frontend
export BASE_URL=http://localhost:3000
npm run test:e2e
# Stop services
docker compose -f docker/docker-compose.yml -f docker/compose/ci.yml down- Follow PEP 8 style guidelines
- Use Ruff for linting and formatting
- Maximum line length: 100 characters
- Use type hints for function signatures
- Write docstrings for public functions and classes
from typing import List, Optional
def get_strategies(user_id: int, active: Optional[bool] = None) -> List[dict]:
"""
Retrieve strategies for a user.
Args:
user_id: The user's ID
active: Filter by active status
Returns:
List of strategy dictionaries
"""
# Implementation...- Use ESLint for linting
- Follow Vue 3 Composition API patterns
- Use Pinia for state management
- Write meaningful component names
// Good
<script setup lang="ts">
import { ref, computed } from 'vue'
interface Strategy {
id: number
name: string
}
const strategies = ref<Strategy[]>([])
const activeCount = computed(() => strategies.value.filter(s => s.active).length)
</script>- Unit tests should be fast and isolated
- E2E tests should cover critical user flows
- Mock external dependencies (API calls, database)
- Use descriptive test names
# Good test name
def test_login_with_valid_credentials_returns_token():
# ...Before submitting a PR, ensure:
- All tests pass locally
- Code follows style guidelines
- New features include tests
- Documentation is updated
- Commit messages follow conventions
- PR description is clear and complete
Use .github/PULL_REQUEST_TEMPLATE.md when you open a PR. Its key sections:
## What & Why
Brief description of changes and why they are needed.
## Governance declaration
- 目标分支: dev(或 master 的 release/hotfix 理由)
- 风险等级: R0/R1/R2/R3 + 命中路径说明
- 测试证据: 本地/CI 测试输出或链接
## Test Plan
How did you verify the change?
## i18n 变更清单 (i18n change manifest, 175 §4.7)
(only mandatory when locale files change — see template)
## Related Issues
Fixes #123- Be Constructive: Provide helpful feedback
- Be Respectful: Treat others with respect
- Be Timely: Respond to reviews promptly
- Explain Why: Explain reasoning for suggestions
- Code follows project standards
- Tests are adequate
- No security vulnerabilities
- Performance impact considered
- Documentation updated
- Make requested changes
- Reply to each comment with your response
- Mark conversations as resolved when addressed
- Request re-review when ready
All pull requests go through automated checks:
- Lint: Code style checks
- Tests: Unit and integration tests
- Build: Production build validation
- E2E: End-to-end browser tests
- Security: Security vulnerability scanning
See CI/CD Documentation for details.
When you attach logs, a zipped project copy, screenshots, or a support bundle to
an issue or chat, scrub local credentials before sharing. Developer-local
.env files and strategies/simulate/*/.env may hold real third-party keys
(OKX / Binance / HTX / CTP / Telegram / PyPI / ReadTheDocs). These are never
committed (they are .gitignored), but they can leak through bundles.
Checklist before sharing any bundle:
- Remove or redact every
.env/*.envfile from the bundle (find . -name '*.env' -printto locate them). - Strip credentials from logs: API keys, JWT secrets, admin passwords, broker tokens, session cookies.
- Redact secrets visible in screenshots (URLs with tokens, header panes).
- If a key was ever exposed (screenshot, CI artifact, shared bundle),
rotate it at the provider and update your local
.env. - Prefer
.env.example(placeholder values only) when showing config shape.
If you discover a credential leaked through a past bundle, treat it as an incident: rotate the affected keys first, then audit where the bundle traveled.
- Open an issue for bugs or feature requests
- Start a discussion for questions
- Check existing documentation
By contributing, you agree that your contributions will be licensed under the MIT License.