Contract API
FastAPI service for V2 contract workflows.
Storage
Contract list, detail, workspace tasks and approval timeline data use the SQLAlchemy repository. Local development defaults to SQLite so the V2 main flow can run without extra services:
CONTRACT_API_DATABASE_URL=sqlite+pysqlite:///.runtime/contract-api.sqlite3
Production can switch to PostgreSQL with the same repository:
CONTRACT_API_DATABASE_URL=postgresql+psycopg://contract:contract@localhost:5432/yuqei_contract
CONTRACT_API_DATABASE_AUTO_CREATE=false
CONTRACT_API_SEED_DEMO_DATA=false
Run migrations from this service directory:
cd yuqei-contract-platform/services/contract-api
python -m alembic upgrade head
Local Run
cd yuqei-contract-platform/services/contract-api
python -m uvicorn yuqei_contract_api.main:app --app-dir src --reload --port 8100
Run the contract review worker in another terminal when testing async AI review:
cd yuqei-contract-platform/services/contract-api
$env:PYTHONPATH="src;../../../yuqei-ai-sdk-python/src"
python -m yuqei_contract_api.review_worker
Process one queued review task batch and exit:
python -m yuqei_contract_api.review_worker --run-once --limit 1
Health endpoints:
GET /healthGET /api/v1/healthGET /api/v1/runtime/config-checkpython -m yuqei_contract_api.review_worker --health
/api/v1/runtime/config-check is the deployment guardrail. It flags unsafe runtime settings such as production SQLite, production auto table creation, enabled demo seed data, invalid AI Platform URL, invalid worker intervals, or an empty file storage directory.
Contract review worker production variables:
CONTRACT_API_ENVIRONMENT=production
CONTRACT_API_DATABASE_URL=postgresql+psycopg://...
CONTRACT_API_DATABASE_AUTO_CREATE=false
CONTRACT_API_SEED_DEMO_DATA=false
CONTRACT_API_FILE_STORAGE_DIR=/data/contract-files
CONTRACT_API_AI_PLATFORM_BASE_URL=http://ai-platform-api:8101
CONTRACT_API_UVICORN_WORKERS=1
CONTRACT_API_READ_CACHE_TTL_SECONDS=2
CONTRACT_API_REVIEW_WORKER_NAME=contract-review-worker-1
CONTRACT_API_REVIEW_WORKER_POLL_INTERVAL_SECONDS=5
CONTRACT_API_REVIEW_WORKER_BATCH_LIMIT=5
After deployment, verify the end-to-end review path from repository root:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File yuqei-infra\scripts\verify-contract-review-worker-flow.ps1 `
-ContractApiBaseUrl http://localhost:8100 `
-WorkerExecutionMode docker-compose `
-RequireConfidence
Use -RequirePrimarySources when the target environment has a populated knowledge base and the review must prove source-backed RAG output.
Docker Compose Baseline
From repository root:
Copy-Item yuqei-infra\compose\.env.example yuqei-infra\compose\.env
docker compose --env-file yuqei-infra\compose\.env -f yuqei-infra\compose\docker-compose.yml up --build
The compose baseline runs contract-api-migrate before contract-api, and keeps CONTRACT_API_DATABASE_AUTO_CREATE=false inside containers. For production, also set:
CONTRACT_API_ENVIRONMENT=production
CONTRACT_API_SEED_DEMO_DATA=false
After startup:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File yuqei-infra\scripts\verify-v2-runtime.ps1
Test
From repository root:
python -m pytest yuqei-contract-platform/services/contract-api/tests