From 12fdf415163dca8250a89c89e9214a33b0dc3e43 Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Thu, 24 Sep 2026 18:14:12 -0500 Subject: [PATCH] docs(blueprint): freeze Phase 0 architectural clarifications - Clarify dependency inversion between application ports and infrastructure adapters. - Distinguish public `create()` domain factory API from dataclass `__init__` for rehydration. - Add empty phases validation check to `Routine.create()` example. --- docs/praxis-implementation-blueprint.md | 48 ++++++++++++++++++++----- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/docs/praxis-implementation-blueprint.md b/docs/praxis-implementation-blueprint.md index 110a8b3..532fafb 100644 --- a/docs/praxis-implementation-blueprint.md +++ b/docs/praxis-implementation-blueprint.md @@ -117,15 +117,43 @@ tests/ ## 2. Dependency Direction +```text + ┌──────────────────┐ + │ interfaces/ │ (Phase 4 — FastAPI) + └────────┬─────────┘ + │ imports + ▼ + ┌──────────────────┐ + │ application/ │ use_cases/ + dtos/ + ports/ + └────────┬─────────┘ + │ imports + ┌──────────┴──────────┐ + ▼ ▼ + ┌──────────────┐ ┌──────────────────┐ + │ domain/ │ │ application/ │ + │ (pure Python│ │ ports/ │ + │ stdlib) │ │ (Protocol stubs)│ + └──────────────┘ └────────┬─────────┘ + ▲ implements (structurally) + │ + ┌────────┴─────────┐ + │ infrastructure/ │ + │ adapters/ │ + └──────────────────┘ ``` -tests/unit/domain/ → domain/ only (no mocks, no fakes) -tests/unit/application/ → application/ + domain/ (in-memory fakes for ports) -tests/integration/ → infrastructure/ (real DB) -interfaces/fastapi/ → application/use_cases/ (Phase 4) -application/use_cases/ → domain/ + application/ports/ -domain/ → stdlib only (dataclasses, enum, uuid, datetime, decimal) -infrastructure/adapters/ → application/ports/ (implements them) +The critical relationship: **both** `application/` and `infrastructure/` depend on `application/ports/`. `infrastructure/` never depends on `application/use_cases/`, and `application/` never depends on `infrastructure/`. The protocol is satisfied structurally — no base class import required. + +**In import terms:** + +```text +interfaces/fastapi/ → application/use_cases/ +application/use_cases/ → domain/ + application/ports/ +domain/ → stdlib only (dataclasses, enum, uuid, datetime, decimal) +infrastructure/adapters/ → application/ports/ (satisfies Protocol structurally) +tests/unit/domain/ → domain/ only (no mocks, no fakes) +tests/unit/application/ → application/ + domain/ (in-memory port fakes) +tests/integration/ → infrastructure/ (real DB — Phase 3) ``` **Absolute prohibition**: `domain/` must not import from `application/`, `infrastructure/`, or any third-party library. @@ -290,7 +318,9 @@ Domain factories and aggregate methods that need the current time receive `now: ## 8. Aggregate Construction -Aggregate roots are constructed via **factory classmethods**, not bare `__init__` calls, to make intent explicit and enforce invariants at construction: +The **public construction API** for aggregate roots is a `create()` classmethod. It carries the invariant checks and ID generation that must happen at construction time. The underlying dataclass `__init__` remains available as the implementation mechanism — `create()` calls it via `cls(...)`. + +This distinction matters: do not fight Python's generated `__init__` or mark it private. It is used internally by `create()` and will also be needed by infrastructure adapters when rehydrating persisted aggregates from storage (where invariants were already satisfied on the way in). ```python @classmethod @@ -303,6 +333,8 @@ def create( ) -> "Routine": if not name.strip(): raise ValueError("Routine name must not be blank") + if not phases: + raise ValueError("Routine must have at least one Phase") return cls( id=RoutineId.generate(), owner_id=owner_id,