3.9 KiB
3.9 KiB
TradeMate (外贸小助手) — Agent Guide
Architecture
- Backend:
backend/— FastAPI + SQLAlchemy 1.4 async + asyncpg, singleapp.main:app - Frontend:
uni-app/— Vue 3 + uni-app (H5 first, later WeChat mini-program) - Config:
backend/app/config.pyreads from/.env(project root) via pydantic BaseSettings - Auth: JWT (python-jose). Default dep
get_current_user_idinbackend/app/api/v1/deps.py - AI Router:
backend/app/ai/router.py— singletonAIRouter, primary=opencode_go, fallbacks=sensenova/openai/anthropic - Database: PostgreSQL via
asyncpg, pool_size=20
Dev Commands
# Backend (from project root — .env is there)
cd backend && source venv/bin/activate && uvicorn app.main:app --reload --port 8000
# Frontend — uni-app (mobile)
cd uni-app && npm run dev:h5
# Admin frontend (PC management)
cd admin-frontend && npm run dev # port 5173, base: /admin/
# User workspace (PC workbench)
cd user-frontend && npm run dev # port 5174, base: /workspace/
# Tests (backend — needs PostgreSQL running with foreign_trade_test DB)
cd backend && venv/bin/pytest # all
venv/bin/pytest tests/test_auth_api.py # single file
venv/bin/pytest tests/ -k "test_login" # keyword filter
# Builds
cd uni-app && npm run build:h5 # uni-app (mobile H5)
cd admin-frontend && npm run build # admin => /www/wwwroot/trade.yuzhiran.com/admin/
cd user-frontend && npm run build # workspace => /www/wwwroot/trade.yuzhiran.com/workspace/
# Alembic migrations
cd backend && alembic upgrade head
alembic revision --autogenerate -m "desc"
Deployment
- Landing page at
trade.yuzhiran.com/— static marketing HTML - SPA at
trade.yuzhiran.com/app/— uni-app build (mobile) - Admin at
trade.yuzhiran.com/admin/— Vue 3 + Element Plus (standalone) - Workspace at
trade.yuzhiran.com/workspace/— Vue 3 + Element Plus (standalone) - Nginx: SPA fallbacks for
/app/,/admin/,/workspace/ - vite config: each project has its own
basepath and dev port - API: proxied via nginx
location /api/to127.0.0.1:8002
Critical Quirks
- Route ordering: FastAPI matches top-down. Specific routes (
/{customer_id}/health) must be registered before wildcard/{customer_id}. - AI
extract_info: Some models (e.g. deepseek-v4-flash) don't supportresponse_format={"type": "json_object"}.openai.pycatches the failure and retries without it. - Manual auth on some endpoints:
keywordsandcompetitor-analysisendpoints useauthorization: str = Header(None)instead ofDepends(get_current_user_id). - MarketingService fallback: When no AI providers initialized, returns template content instead of crashing.
- Onboarding service: calls
mkt.generate(product_info={"name": ..., ...}), not keyword args. Checkonboarding.pyfor the exact dict shape. - Login:
POST /api/v1/auth/loginuses JSONLoginRequestmodel, notOAuth2PasswordRequestForm. - CustomerHealthService:
get_health_overviewendpoint must useCustomerHealthService(db)notCustomerService(db).
Project Conventions
- No README.md — key context is in
PROGRESS.mdanddocs/ - Chinese UI — mobile-first, for foreign-trade SOHOs/small teams
- No comments in code unless explicitly asked
- Commit messages focus on "why" not "what", in English
- Services instantiate
MarketingService()(no db needed). For customer health:CustomerHealthService(db) - AI providers in
backend/app/ai/providers/— inherit fromOpenAIProviderif compatible with OpenAI API format - Static assets go in
uni-app/src/static/ - Test DB:
foreign_trade_test(uses credentials fromconftest.py, not.env)
Remember
- Write tests for new features
- Run
cd backend && venv/bin/pytestbefore committing - Keep context compact — avoid bloating the session with unnecessary file reads