generated from coulomb/repo-seed
2.5 KiB
2.5 KiB
Implementation Guide – DirektVermittlungDe (FastAPI)
This guide explains how this codebase implements the architectural decisions and API specification of DirektVermittlungDe.
1. Architecture Mapping
-
Belegorientierung:
Documentis the central aggregate.- Domain models in
app/domain/models.py - ORM model in
app/adapters/orm.py::Document
- Domain models in
-
Interaction Threads:
ThreadandMessagemap to interaction threads and their logs.- Cursor-based pagination implemented in
app/service/threads_service.py::list_messages - The
created_attimestamp is used as the pagination cursor.
- Cursor-based pagination implemented in
-
Routing Engine:
- Implemented as an adapter in
app/adapters/routing.py - Operates solely on
DocumentMetadata(plaintext) as required by the split-payload model.
- Implemented as an adapter in
-
Asynchronous Exports:
POST /exports→start_export()inapp/service/exports_service.py- Returns
202 AcceptedwithjobIdand uses a job registry (app/adapters/jobs.py) - In a production system this would publish to Redis / RabbitMQ and be processed by workers.
2. Security
-
Auth:
- OAuth2 / JWT is abstracted in
app/adapters/auth.py. - In this reference implementation, we parse unverified claims; in production, validate via JWKS.
- OAuth2 / JWT is abstracted in
-
Data Protection:
- Encrypted payloads are treated as opaque strings and stored via
app/adapters/storage.py. - Only routing metadata is stored in PostgreSQL for server-side logic.
- Encrypted payloads are treated as opaque strings and stored via
-
Retention:
- Each
Documentgets aretention_date, set to a grace period in the future. - Implement a periodic cleanup job that deletes rows where
retention_date < NOW().
- Each
3. Performance / Hybrid Concurrency
- All endpoints are
async defand rely on the async SQLAlchemy engine. - CPU-heavy operations (PDF merge, crypto) must not be run inside the event loop.
- To extend this, create a
ProcessPoolExecutorinworkers/and call vialoop.run_in_executor.
- To extend this, create a
4. Extending the System
- Real Routing Rules:
- Add a
routing_rulestable and adaptapp/adapters/routing.pyto query it.
- Add a
- Real Export Workers:
- Replace
jobs.pywith a Redis-backed queue and a worker process inworkers/exports_worker.py.
- Replace
- Authority Integration:
- Call the authority’s eAkte ingress API from the worker, using authority-specific keys.
5. Definition of Done Checklist
Before going to production:
- Load-test
POST /documentsandGET /threads/{id}/messages. - Verify that logs never contain Aktenzeichen or other PII.
- Verify that retention cleanup jobs work correctly on staging data.