Essential info for AI agents working on AI for Investor, a quantitative trading platform.
Tech Stack: Python 3.10+ (FastAPI, SQLAlchemy 2.0, Pydantic) | Vue 3 + TypeScript (Vite, Element Plus, Pinia) | SQLite/PostgreSQL/MySQL
- If the user cancels a
run_commandrequest twice in a row, assume the command or script is likely flawed, too broad, or poorly targeted. - Do not repeat the same command pattern a third time.
- Rewrite the command into a new, smaller, safer, and more observable form, or write a different script before asking to run it again.
- Prefer read-only verification and narrower diagnostics before retrying a state-mutating command.
pip install -e ".[dev,backtrader]" # Install dependencies
pytest # Run all tests
pytest tests/test_auth.py # Run single test file
pytest tests/test_auth.py::TestRegister::test_register_success # Run single test
pytest --cov=app --cov-report=term # Tests with coverage
pytest -v -s # Verbose output
pytest -m "not e2e" # Skip e2e tests
ruff check src/backend # Lint
ruff check src/backend --fix # Auto-fix lint issues
ruff format src/backend # Formatnpm install # Install dependencies
npm run dev # Development server
npm run build # Production build
npm run typecheck # TypeScript type check (vue-tsc)
npm run test # Unit tests
npm run test -- --coverage # Tests with coverage
npm run test:e2e # E2E tests (requires running app)
npm run test:e2e:headed # E2E with visible browser
npm run lint # LintConfig: src/backend/pyproject.toml - Line length: 100, Ruff rules: E, F, I, W
Naming: Files snake_case.py, Classes PascalCase, Functions snake_case(), Constants UPPER_SNAKE_CASE, API routes kebab-case
Imports: Standard lib → Third-party → Local (handled by Ruff/isort)
Type Hints: Required for all functions
def get_strategies(user_id: int, active: Optional[bool] = None) -> List[dict]:Docstrings: Google style for public functions/classes
Architecture (Layered):
app/api/- Routes: request parsing, validationapp/services/- Business logic (core implementation)app/schemas/- Pydantic DTOsapp/models/- SQLAlchemy ORMapp/db/- Repositoriesapp/middleware/- Logging, security
Rules:
- One service class per file, use
@lru_cachefor singletons - Prefer
async defmethods - Service layer: return
None/Falsefor failures - API layer: convert failures to
HTTPException
Error Handling:
- Service: Return
None/Falsefor expected failures, raise for unexpected - API: Convert to
HTTPExceptionwith appropriate status codes - Use Pydantic for input validation (automatic 422)
Config: src/frontend/tsconfig.json (strict mode)
Naming: Components PascalCase.vue, Composables/Stores useCamelCase(), Types PascalCase, Constants UPPER_SNAKE_CASE
Component Structure:
<script setup lang="ts">
// 1. Imports
import { ref, computed, onMounted } from 'vue'
// 2. Props/Emits
const props = defineProps<{ taskId: string }>()
// 3. Reactive data
const loading = ref(false)
// 4. Computed
const hasResult = computed(() => !!store.currentResult)
// 5. Methods
async function runBacktest() { /* ... */ }
// 6. Lifecycle
onMounted(() => { /* ... */ })
</script>
<style scoped>
/* Use scoped styles */
</style>Best Practices: Use Composition API (<script setup>), Pinia for state, TypeScript strict mode, async/await
Backend (pytest):
class TestRegister:
async def test_register_success(self, client: AsyncClient):
resp = await client.post("/api/v1/auth/register", json={...})
assert resp.status_code == 200- Naming:
test_*.py,TestFeatureName,test_specific_scenario - Mock external dependencies, use fixtures in
conftest.py - Mark:
@pytest.mark.integration,@pytest.mark.e2e
Frontend: Vitest + Playwright
Conventional Commits: <type>(<scope>): <description>
Types: feat, fix, docs, style, refactor, test, chore, perf, ci
Examples: feat(backtest): add cancel endpoint, fix(auth): handle token refresh
- Open regular repository changes (
feature/*,fix/*,docs/*,refactor/*, andtest/*) as PRs targetingdev; do not directly commit changes tomaster. masteris reserved for maintainer-ownedrelease/vX.Y.Zpromotions andhotfix/master-*emergency fixes. Follow CONTRIBUTING.md for the required governance declaration and evidence.
- Never hardcode secrets; use
.env(not committed) - Validate input via Pydantic schemas
- Use parameterized queries (SQLAlchemy handles this)
- Execute strategy code in sandboxed environment
Config: .pre-commit-config.yaml (Ruff, whitespace, YAML/JSON validation)
pip install pre-commit && pre-commit install # Setup
pre-commit run --all-files # Run manuallyNew API Endpoint: Schema (app/schemas/) → Service (app/services/) → Route (app/api/) → Tests
New Frontend Page: View (src/views/) → Route → Store (src/stores/) → API wrapper → Tests
Database Change: Model (app/models/) → Repository (app/db/) → Service → Tests
src/backend/pyproject.toml- Python configsrc/frontend/package.json- Frontend scriptsdocs/CODING_STANDARDS.md- Detailed standardsdocs/DEVELOPMENT.md- Dev setup