Backend:
- Structured JSON logging (python-json-logger) with request ID correlation
- RequestIDMiddleware (server-generated UUID, no client trust)
- Global exception handlers: AppException, RequestValidationError, generic 500
— all return consistent {"error": {code, message, request_id}} format
- Async rate limiting with lock + stale key eviction on auth endpoints
- Health endpoint checks DB connectivity, returns version + status
- Custom exception classes (NotFoundException, ForbiddenException, etc.)
- OpenAPI docs with tag descriptions, conditional URL (disabled in production)
- LOG_LEVEL, DOCS_ENABLED, RATE_LIMIT_* settings added
Docker:
- Backend: multi-stage build (builder + runtime), non-root user, HEALTHCHECK
- Frontend: removed dead user, HEALTHCHECK directive
- docker-compose: restart policies, healthchecks, Redis service, named volumes
for uploads/PDFs, rate limit env vars forwarded
- Alembic migrations run only in Dockerfile CMD (removed from lifespan)
Nginx:
- server_tokens off
- CSP, Referrer-Policy, Permissions-Policy headers
- HSTS ready (commented, enable with TLS)
Config & Docs:
- .env.production.example with production-ready settings
- CLAUDE.md project conventions (structure, workflow, naming, how-to)
- .env.example updated with new variables
Review fixes applied:
- Rate limiter: async lock prevents race condition, stale key eviction
- Request ID: always server-generated (no log injection)
- Removed duplicate alembic migration from lifespan
- Removed dead app user from frontend Dockerfile
- Health check logs DB errors
- Rate limit env vars forwarded in docker-compose
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
34 lines
1005 B
Python
34 lines
1005 B
Python
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
DATABASE_URL: str = "postgresql+asyncpg://ai_assistant:changeme@postgres:5432/ai_assistant"
|
|
SECRET_KEY: str = "changeme_secret_key_at_least_32_chars_long"
|
|
ENVIRONMENT: str = "development"
|
|
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 15
|
|
REFRESH_TOKEN_EXPIRE_DAYS: int = 30
|
|
REFRESH_TOKEN_EXPIRE_HOURS: int = 24
|
|
|
|
BACKEND_CORS_ORIGINS: list[str] = ["http://localhost", "http://localhost:3000"]
|
|
|
|
ANTHROPIC_API_KEY: str = ""
|
|
CLAUDE_MODEL: str = "claude-sonnet-4-20250514"
|
|
|
|
UPLOAD_DIR: str = "/data/uploads"
|
|
MAX_UPLOAD_SIZE_MB: int = 20
|
|
|
|
LOG_LEVEL: str = "INFO"
|
|
DOCS_ENABLED: bool = True
|
|
RATE_LIMIT_REQUESTS: int = 20
|
|
RATE_LIMIT_WINDOW_SECONDS: int = 60
|
|
|
|
FIRST_ADMIN_EMAIL: str = "admin@example.com"
|
|
FIRST_ADMIN_USERNAME: str = "admin"
|
|
FIRST_ADMIN_PASSWORD: str = "changeme_admin_password"
|
|
|
|
model_config = {"env_file": ".env", "extra": "ignore"}
|
|
|
|
|
|
settings = Settings()
|