Refactor python-cli-hexagonal per modularity review findings#1
Open
deimagjas wants to merge 2 commits into
Open
Refactor python-cli-hexagonal per modularity review findings#1deimagjas wants to merge 2 commits into
deimagjas wants to merge 2 commits into
Conversation
Implements the four findings from the 2026-05-29 modularity review: - Layered domain (Bancolombia-style): domain/model/<feature>/ holds the model + its gateway (port); domain/usecase/<feature>/ holds the pure use case + its errors. Fixes low cohesion of the old flat files. - Pure use cases: greet(request) -> Greeting no longer performs IO; delivery via the port happens in the entrypoint. - Single composition root: wiring.build_dependencies() builds a Dependencies container once in the cli root callback, injected via ctx.obj; commands no longer construct dependencies. - Type checking with ty: verifies adapters structurally satisfy their gateway Protocol (pre-commit + CI). Closes the gap where a port signature change passed lint/tests and only broke at runtime. tach.toml now enforces usecase -> model -> shared-kernel boundaries. README and CLAUDE.md updated (architecture, recipe, invariants). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- wiring.Dependencies is now a frozen pydantic BaseModel instead of a dataclass (we are in the entrypoint, external deps are allowed here). It validates on construction that each injected port conforms to its Protocol, so a bad adapter is rejected at the composition root. - GreeterPort is marked @runtime_checkable to enable that isinstance validation; ty still verifies structural conformance statically. - Add pydantic>=2.0 as a runtime dependency. - Add tests/unit/test_wiring.py covering validation and immutability. - Remove the generated modularity-review.html (keep the .md). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
Author
|
Comentarios atendidos en e509bcd:
Verificación:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contexto
Implementa las cuatro observaciones del modularity review (2026-05-29) sobre la plantilla
python-cli-hexagonal. El review encontró que la plantilla es sólida como ports & adapters, pero que sus patrones por defecto empujaban a los adopters hacia acoplamiento desbalanceado al crecer.Cambios
domain/model/<feature>/contiene el modelo + su gateway (puerto);domain/usecase/<feature>/contiene el caso de uso puro + sus errores. Resuelve la baja cohesión de los antiguos archivos planos (models.py/ports.py/use_cases.py).greet(request) -> Greetingya no entrega IO; la entrega por el puerto ocurre en elentrypoint/.wiring.build_dependencies()construye un contenedorDependenciesuna sola vez en el callback raíz decli.py, inyectado víactx.obj. Los comandos ya no construyen dependencias.ty— verifica que los adapters satisfacen estructuralmente elProtocolde su gateway (pre-commit + CI). Cierra el hueco donde un cambio de firma de un puerto pasaba lint/tests y solo fallaba en runtime.tach.tomlahora fuerza el flujousecase → model → kernel compartido. README y CLAUDE.md actualizados (arquitectura, receta para añadir comandos, invariantes).Verificación
Comprobación del contrato (prueba de la observación #1): renombrar
GreeterPort.deliverhace quety checkfalle en el sitio de uso y enwiring.py(ConsoleGreeterno asignable al protocolo) — algo que antes pasaba CI en silencio.🤖 Generated with Claude Code