Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
Keep domain logic in plain Python modules, define the interfaces it needs with Protocols or abstract classes, implement them in infrastructure adapters, and wire dependencies at the application edges so views, ORMs and external clients do not leak into the core.
In many projects, business rules end up inside views, serializers or ORM models, which makes them hard to test and to change. A layered or ports-and-adapters structure separates the domain, service or use-case layer, and infrastructure such as database repositories, message queues and HTTP clients. typing.Protocol lets the domain describe what it needs, like a PaymentGateway with a charge method, without importing the concrete implementation, and static type checkers verify that adapters match. Dependencies are passed through constructors or a small composition root, so tests can supply fakes. This should be applied pragmatically: simple CRUD features can stay close to the framework, while complex domains benefit most from the separation. Import-linting tools can enforce the layer boundaries.