feat(bootstrap,api,infra): scaffold app composition, health route, and postgres/minio/qdrant adapters
Why: - first runnable slice of ADR-0012's resource-lifetime rules and ADR-0015's package layout: app-lifetime clients built once in the lifespan, released via explicit dependencies. Changes: - Settings split into per-domain nested settings (postgres/minio/ingestion/qdrant/app/logging); FastAPI app wired with /healthz, /readyz and a /v1 router; Postgres/MinIO/Qdrant adapters and SQLAlchemy models for tenants, API keys, source files, ingestion jobs/events.
This commit is contained in:
44
src/bootstrap/dependencies.py
Normal file
44
src/bootstrap/dependencies.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from collections.abc import AsyncIterator
|
||||
from dataclasses import dataclass
|
||||
|
||||
from fastapi import Request
|
||||
from minio import Minio
|
||||
from qdrant_client import AsyncQdrantClient
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker
|
||||
|
||||
from src.config import Settings
|
||||
|
||||
|
||||
@dataclass
|
||||
class AppResources:
|
||||
settings: Settings
|
||||
db_engine: AsyncEngine
|
||||
db_sessionmaker: async_sessionmaker[AsyncSession]
|
||||
minio_client: Minio
|
||||
qdrant_client: AsyncQdrantClient
|
||||
|
||||
|
||||
def _resources(request: Request) -> AppResources:
|
||||
return request.app.state.resources
|
||||
|
||||
|
||||
def get_settings(request: Request) -> Settings:
|
||||
return _resources(request).settings
|
||||
|
||||
|
||||
def get_minio_client(request: Request) -> Minio:
|
||||
return _resources(request).minio_client
|
||||
|
||||
|
||||
def get_qdrant_client(request: Request) -> AsyncQdrantClient:
|
||||
return _resources(request).qdrant_client
|
||||
|
||||
|
||||
async def get_db_session(request: Request) -> AsyncIterator[AsyncSession]:
|
||||
sessionmaker = _resources(request).db_sessionmaker
|
||||
async with sessionmaker() as session:
|
||||
try:
|
||||
yield session
|
||||
except Exception:
|
||||
await session.rollback()
|
||||
raise
|
||||
Reference in New Issue
Block a user