2026-10-29 10:59:29 +08:00
# Repository Guidelines
## Project Structure & Module Navigation
2026-10-29 16:25:09 +08:00
Use `am.py` for CLI/WSGI, `logistics_chat/` for business code, and `static/css/` /`static/js/` for page assets. [Architecture ](docs/architecture.md ) defines module contracts and extraction rules.
2026-10-29 10:59:29 +08:00
| Area | Files and search anchors |
|---|---|
| AI | `logistics_chat/chat_service.py` : `create_chat_stream` ; `logistics_chat/ai_client.py` : `post_completion` |
| Knowledge | `logistics_chat/knowledge.py` : `knowledge_list` , `search_knowledge` ; `docs/knowledge.md` |
| Pricing | `logistics_chat/pricing.py` : `RATES` , `calc_freight` ; `logistics_chat/rates_extra.py` |
| Tracking | `logistics_chat/tracking.py` : `extract_tracking_no` , `build_track` , `CARD_PREFIX` |
2026-10-29 18:01:28 +08:00
| Order test data | `logistics_chat/order_data.py` : `lookup_order` , `answer_query` , `import_records` ; `scripts/import_order_test_data.py` |
2026-10-29 10:59:29 +08:00
| Persistence | `logistics_chat/db.py` : `init_db` , `save_message` ; `logistics_chat/history_service.py` |
2026-10-29 16:28:50 +08:00
| Human support | `logistics_chat/human_service.py` : lifecycle, transfer, notes, recall; `logistics_chat/routes/human.py` |
2026-10-29 10:59:29 +08:00
| Business / files | `logistics_chat/business_service.py` , `logistics_chat/file_service.py` ; `logistics_chat/routes/` |
2026-10-29 16:28:50 +08:00
| UI | `templates/` ; `static/css/theme.css` : tokens; page CSS; `static/js/chat.js` : `doSend` , `I18N` ; `static/js/admin.js` : `poll` , `sendReply` , `setChatView` ; `admin_tools.js` : notes, transfer, search; `support.js` : emoji, notifications, rating |
2026-10-29 14:42:46 +08:00
| Startup / hooks | `logistics_chat/__init__.py` : `create_app` ; `config.py` : `default_config` ; `hooks.py` , `runtime.py` in that package |
2026-10-29 10:59:29 +08:00
| CLI / tests | `start.bat` : `probe_python` ; `scripts/` , `tests/` , `examples/requests/` |
2026-10-29 16:25:09 +08:00
| Deployment | `Jenkinsfile` , `Dockerfile` ; `deploy/gray_config.py` : `GrayConfig` ; publish/activate/TLS scripts; `docs/deployment.md` |
2026-10-29 10:59:29 +08:00
## Efficient Search & File Boundaries
Start with mapped files, then follow callers. Prefer symbols over saved line numbers. `rg --files` includes untracked source; respect ignored runtime data.
```powershell
rg - -files
rg -n -F -e 'calc_freight' -e '/api/human/' logistics_chat static / js
```
Routes adapt HTTP; services compose rules, persistence, and model calls. Keep pure rules independent of Flask. Preserve URL/SSE/storage contracts and update navigation after moves.
## Build, Test, and Development Commands
Run from the repository root:
```powershell
py -3 -m venv . venv
.\. venv \ Scripts \ python . exe -m pip install -r requirements . txt
2026-10-29 14:42:46 +08:00
Copy-Item . env . example . env # First run only; set DEEPSEEK_API_KEY inside .env.
2026-10-29 10:59:29 +08:00
.\. venv \ Scripts \ python . exe am . py
.\. venv \ Scripts \ python . exe -m unittest discover -s tests -v
```
2026-10-29 16:25:09 +08:00
`start.bat` prefers active `VIRTUAL_ENV` ; verify with `start.bat --check-python` . No frontend build is required.
2026-10-29 10:59:29 +08:00
## Coding Style & Naming Conventions
Use four-space Python indentation, `snake_case` , `UPPER_SNAKE_CASE` constants, and JavaScript `camelCase` . Preserve Chinese terminology. No formatter/linter is configured.
## Testing Guidelines
Use `tests/test_<feature>.py` and `test_<behavior>` . Mock DeepSeek; configure temporary database/upload/backup/log paths before `create_app` . Pytest: `.\.venv\Scripts\python.exe -m pytest -v` ; Linux/macOS: `.venv/bin/python -m pytest -v` .
2026-10-29 16:30:13 +08:00
Tests run `tests/frontend/admin.test.cjs` and `chat.test.cjs` when Node.js is available; no npm dependencies.
2026-10-29 10:59:29 +08:00
## Commit & Pull Request Guidelines
History uses concise Chinese summaries. Keep commits focused. PRs explain behavior, validation, linked issues, and UI screenshots.
## Security & Configuration Tips
2026-10-29 16:30:13 +08:00
Never commit credentials or runtime/customer data. Revoke exposed keys. Keep `uploads/.gitkeep` . Startup reads root `.env` ; environment variables override it. Restart after changes. `create_app` initializes storage unless `INITIALIZE_RUNTIME=False` ; business tables start empty. Default HOST is `0.0.0.0` ; Linux deployment binds loopback. Admin authentication remains incomplete; protect all acceptance routes through Nginx.