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, AdapterContainerBase, inject_adapters
# Value Object
class OrderId(ValueObject):
value: str
# Domain Event
class OrderPlaced(Event):
order_id: str
total: float
# Aggregate Root
class Order(RootEntity):
id: OrderId
total: float
def place(self) -> None:
self._event_emitter.emit(OrderPlaced(order_id=self.id.value, total=self.total))
# Command
class PlaceOrder(Command[Order, None]):
order_id: str
total: float
# Infrastructure Handler
class PlaceOrderHandler(CommandHandler[PlaceOrder]):
def handle(self, command: PlaceOrder) -> None:
order = Order(id=OrderId(value=command.order_id), total=command.total)
self.session.execute(order)
# Application Use Case
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))
# Dependency Injection
class AppContainer(AdapterContainerBase):
pass
container = AppContainer(handlers=[PlaceOrderHandler])
use_case = inject_adapters(container, 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
- Getting Started — Install, quickstart, and concepts
- Domain Layer — Entities, Value Objects, Services, Events, Invariants
- Application Layer — Use Cases, Ports, Contracts
- Infrastructure Layer — Sessions, Handlers, Containers, Injection
- Testing — Spies, stubs, fakers, and assertions
- DDD to AoD — Map DDD concepts to framework components
- API Reference — Full class and method reference
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file attack_on_domain-0.0.18.tar.gz.
File metadata
- Download URL: attack_on_domain-0.0.18.tar.gz
- Upload date:
- Size: 53.3 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08285eea1d496c6b42c3e21e05cc09e888fcb46c62b9af8f06abf86c16debd0f
|
|
| MD5 |
d1e4e545e276c10600b3682ad1f58b8a
|
|
| BLAKE2b-256 |
f428c238297ae9bf1aa1b187c61a57ddd7f829eba9c4c4306ab024f75ad49f10
|
File details
Details for the file attack_on_domain-0.0.18-py3-none-any.whl.
File metadata
- Download URL: attack_on_domain-0.0.18-py3-none-any.whl
- Upload date:
- Size: 91.3 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29b1b1923500f92dd57ef2739192e61c661d669cf32cd2de1c22bfbd8ddfa645
|
|
| MD5 |
96643997cca806d31489271dd955f96d
|
|
| BLAKE2b-256 |
04920bdecea5ef3a06cd2a37a6b736b33e78bc65682e2a8c5438d29c1694d1a8
|