Skip to main content

DDD building blocks: entities, value objects, bounded contexts, and validation helpers.

Project description

attack-on-domain

Domain-Driven Design building blocks for Python 3.14+: entities, value objects, aggregates, CQRS, ports and adapters, use cases, domain events, invariants, and dependency injection.

Install

pip install attack-on-domain

Requires Python 3.14+.

Quick Example

from aod.domain import RootEntity, ValueObject, Event
from aod.application import UseCase, Command, CommandPort
from aod.infrastructure import CommandHandler, Session, AdapterContainer


class SqlSession(Session):
    def execute(self, operation: object) -> None: ...


class OrderId(ValueObject):
    value: str

class OrderPlaced(Event):
    order_id: str
    total: float

class Order(RootEntity):
    id: OrderId
    total: float

    def place(self) -> None:
        self._event_emitter.emit(OrderPlaced(order_id=self.id.value, total=self.total))

class PlaceOrder(Command[Order, None]):
    order_id: str
    total: float

class PlaceOrderHandler(CommandHandler[PlaceOrder]):
    session: SqlSession

    def handle(self, command: PlaceOrder) -> None:
        order = Order(id=OrderId(value=command.order_id), total=command.total)
        self.session.execute(order)

class PlaceOrderUseCase(UseCase):
    place_order: CommandPort[PlaceOrder]

    def run(self, order_id: str, total: float) -> None:
        order = Order(id=OrderId(value=order_id), total=total)
        order.place()
        self.place_order.handle(PlaceOrder(order_id=order_id, total=total))

container = AdapterContainer(handlers=[PlaceOrderHandler])
use_case = container.adapt_use_case(PlaceOrderUseCase)
use_case.run(order_id="1", total=99.99)

Key Features

  • Domain Building Blocks — Entity, RootEntity, ValueObject, Aggregate with mutation guards and identity
  • Domain Events — Immutable, auto-timestamped, automatically collected by use cases
  • CQRS — Commands, Queries, and dedicated handlers for clean read/write separation
  • Use Cases — Application-layer orchestration with auto-wired ports, logging, and transaction management
  • Business Invariants — Type-safe field and model-level rules enforced at construction time
  • Testing — Spy containers, session stubs, fakers, and event assertions
  • Hexagonal Architecture — Ports, adapters, and dependency injection through containers

Documentation

Full documentation at alfonsocuesta.github.io/attack-on-domain

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

attack_on_domain-0.0.20.tar.gz (54.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

attack_on_domain-0.0.20-py3-none-any.whl (91.8 kB view details)

Uploaded Python 3

File details

Details for the file attack_on_domain-0.0.20.tar.gz.

File metadata

  • Download URL: attack_on_domain-0.0.20.tar.gz
  • Upload date:
  • Size: 54.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for attack_on_domain-0.0.20.tar.gz
Algorithm Hash digest
SHA256 a2a8bb3a5d28eeea75b1ffc09864fb7ee62056d07c508f2aac70b933ec5910fd
MD5 d989ae327c67b0b4790bf50c07c6aa9f
BLAKE2b-256 d8a00d2464452aacd4e21d652c148238e0dc367b19ec4078ae1a7f2f1a44335e

See more details on using hashes here.

File details

Details for the file attack_on_domain-0.0.20-py3-none-any.whl.

File metadata

  • Download URL: attack_on_domain-0.0.20-py3-none-any.whl
  • Upload date:
  • Size: 91.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for attack_on_domain-0.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 d0b70c26b9cc18120e964a237bfbfffd0577e5fa07dea239750e78d8cae750d2
MD5 76bfd6beeb158719643941e3e4911ad4
BLAKE2b-256 7145e1821b916cde4b1c87da5201e371e3200aa24aff3e52f69ec441cd302c97

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page