3.1 KiB
3.1 KiB
Repository Guidelines
必须使用中文回复我
Project Structure & Module Organization
app.pyis the Flask entrypoint; it wires blueprints fromlawrisk/api(v1.pylegacy,v2.pycurrent) and enables CORS/logging.lawrisk/servicescontains business logic and data access (lawrisk_service.py,lawrisk_v2_service.py,licensing_repo.py); keep new services thin and testable.lawrisk/utilshosts shared helpers (env loading, ingestion/export scripts); favor adding config lookups toenv_loader.py.- Static/manual QA tools live in
static/(notablyv2_tester.html); SQL/JSON seeds indata/; Jinja templates intemplates/. - Tests reside in
tests/plus a few legacytest_*.pyscripts in the repo root; mirror module paths when adding new files. - Documentation and prior agent notes are under
docs/(API references, DB guide, deployment notes).
Build, Test, and Development Commands
- Install deps:
pip install -r requirements.txt(Python 3.11+ recommended). - Run the API locally:
python app.py(defaults tohttp://localhost:8000, health check at/healthz). - Lint/format:
ruff .andblack .before submitting. - Tests:
pytest(usepytest -qfor faster feedback). For API smoke tests, openstatic/v2_tester.htmlorcurlthe V2 endpoint shown indocs/guides/README.md.
Coding Style & Naming Conventions
- Black defaults (88 cols) and Ruff rules apply; avoid manual wrapping that fights autoformatting.
- Packages/files are lowercase with underscores; functions use descriptive verbs (
fetch_risk_snapshot), responses staysnake_case. - Add short docstrings on service functions, especially those hitting the database or external AI.
- Read configuration via
lawrisk.utils.env_loaderrather thanos.environdirectly to keep behavior consistent.
Testing Guidelines
- Prefer pytest function tests; place them alongside mirrored package paths (
tests/api/test_v2.py,tests/services/test_lawrisk_service.py). - Cover happy paths plus edge cases (missing env vars, empty query results, database/connectivity errors).
- When adding Flask routes, include a test client request asserting status, payload shape, and auth behavior.
- Keep fixtures deterministic; use small JSON/SQL samples from
data/instead of live services when possible.
Commit & Pull Request Guidelines
- Follow the existing Conventional Commit pattern (
feat: ...,fix: ...,chore: ...); scope subjects to the domain (e.g.,feat: enhance v2 permit filter). - Group one logical change per commit; avoid mixing formatting-only changes with functional updates.
- PRs should state intent, summarize testing (
pytest, manual curls, screenshots of payload diffs), and link any issue/task. Call out config/env expectations for reviewers.
Security & Configuration Tips
- Copy
.envlocally and set DB creds (PG_*,LIC_PG_*),FLASK_SECRET_KEY, and DashScope keys before running anything beyond unit tests. - Never hardcode secrets or connection strings; prefer env variables read through
env_loader. - Guard new endpoints with existing auth middleware and log sensitive operations at INFO, not DEBUG, to avoid leaking payloads.