1.4 KiB
1.4 KiB
Project Memory
Architecture
Conventions
Pitfalls
Context
Headquarter Backend Patterns (FN-004)
- Use SQLAlchemy 2.0 async style with
mapped_column+Mapped[]syntax - For Alembic + asyncpg: rewrite
postgresql://topostgresql+asyncpg://in bothapp/db.pyandalembic/env.py - For pytest + async SQLAlchemy testing: use
pytest-asyncio==0.21.2(not 1.3.0) withasyncio_mode = "auto",NullPool, and a session-scopedevent_loopfixture to avoid event loop mismatches with asyncpg - Test DB isolation:
begin_nested()on a connection +async_sessionmakerbound to that connection; overrideget_db_sessiondependency - Secret encryption: derive Fernet key from settings string via
SHA-256 + base64.urlsafe_b64encode - Auth dev bypass: only active when
settings.debug and settings.auth_dev_bypass; creates/returns a fixedauthentik_sub="dev-user" - JWT production path: fetch OIDC discovery → get
jwks_uri→ fetch JWKS → match bykid→ decode withjwt.decode(..., algorithms=["RS256"])