ドメイン駆動開発のコアモジュール
Project description
dddlib
dddlib is a Python library that provides foundational components for implementing Domain-Driven Design.
This library does not provide application-specific business logic itself. Instead, it aims to provide common concepts that repeatedly appear in DDD design in a type-safe and easy-to-use form.
Positioning
dddlib standardizes the following elements commonly required in the domain layer.
- Value objects
- Entities
- Aggregate roots
- Domain events
- Identifiers
- Domain errors
- Messages
When these are implemented separately for each application, similar constraints, validations, equality comparisons, and reconstruction logic can easily become scattered.
dddlib serves as a foundation for reducing that repetition and making it easier to focus on designing the domain model itself.
Design Policy
dddlib is designed based on the following policies.
- Make it easy to handle value storage and immutability based on
dataclass - Provide an implementation that works well with type checking by
mypy - Keep the code explicit and readable in line with strict
ruffrules - Avoid concrete business processing and limit the scope to common domain foundations
- Separate it from
dddlib_clito distinguish library usage from CLI usage
For this reason, dddlib is intended to be used not as a framework, but as a thin foundational layer for domain models.
Provided Features
Value Objects
A value object is an object whose identity is determined by its value rather than by an ID.
In dddlib, the following operations, which are often needed when creating value objects, are consolidated.
- Validation at creation time
- Conversion to dictionaries
- Conversion to display strings
- Storage as immutable values
By using FrozenBase, behavior equivalent to dataclass(frozen=True) can be handled naturally.
Entities
An entity is an object that has identity through an identifier.
The entity foundation in dddlib supports the following operations.
- Creating objects with identifiers
- Internal creation for reconstruction
- Comparison based on identity
- Retrieving identifiers
Unlike value objects, entities have a lifecycle. Therefore, it is important to clearly separate identity determination.
Aggregate Roots
An aggregate root is the entry point for protecting domain consistency.
The aggregate root in dddlib inherits the characteristics of an entity while allowing domain events to be accumulated and retrieved.
- Adding events
- Getting and extracting events
- Adding multiple events together
This makes it easier to safely handle events that occur as a result of domain operations.
Domain Events
A domain event represents an important event that occurred within the domain.
In dddlib, emphasis is placed on handling events not as simple dictionaries or strings, but as typed objects.
By representing event contents as explicit classes, it becomes easier to connect them to event-driven processing, auditing, and notification processing.
Identifiers
An identifier is a value used to uniquely handle an entity or aggregate.
dddlib provides bases mainly for UUID-based identifiers, consolidating value validation and conversion.
This makes it easier to handle IDs as meaningful types instead of scattering raw str or int values throughout the code.
Errors and Messages
dddlib also standardizes errors and messages handled in the domain layer.
DDDErroris the foundation for domain errors that have a code and messageMessagehandles message body generation and formattingDDDMessagerepresents predefined messages with codes
Using this mechanism makes it easier to handle errors consistently across the entire application, rather than confining them to simple exception messages.
Typical Usage Image
dddlib is intended to be used, for example, in the following kind of structure.
- Define domain IDs by deriving them from
UUIDIdentifier - Give validation logic to value objects
- Determine entity identity based on IDs
- Publish domain events from aggregate roots
- Explicitly represent business failures with domain errors
This design makes it easier to build models using domain language without pushing too much responsibility into the application layer or infrastructure layer.
Relationship with the CLI
The main body of dddlib is a library.
If you want to support project work using a CLI, refer to the separate package dddlib_cli.
Adoption Approach
When adopting dddlib, it is useful to think through the following order.
- First, decide how to represent domain identifiers
- Next, extract concepts that should be closed as value objects
- Then, define entities and aggregate roots
- Finally, align the representation of events and errors
dddlib should be used as a tool for aligning implementation, rather than as something that disrupts this flow.
Notes
dddlibis not a completed business application, but a common foundation- The domain cannot be established simply by using it as-is, so each project needs to define concrete models
- CLI details are separated into the dddlib_cli README
License
For this project, refer to LICENSE.md directly under the repository root.
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 dddlib-0.1.0a1.tar.gz.
File metadata
- Download URL: dddlib-0.1.0a1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51e713ed331adde043cd69319b16c4bac7afdc853b13de516ca1ff497a38f6ac
|
|
| MD5 |
de984ab2e8d58cbdfd87464e80451154
|
|
| BLAKE2b-256 |
9c7d8d65ebbc878593568bad827f205b86f16dab82e916db8f670d8e7aba2f88
|
Provenance
The following attestation bundles were made for dddlib-0.1.0a1.tar.gz:
Publisher:
cd.yml on pochinoritaro/dddlib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dddlib-0.1.0a1.tar.gz -
Subject digest:
51e713ed331adde043cd69319b16c4bac7afdc853b13de516ca1ff497a38f6ac - Sigstore transparency entry: 1543337126
- Sigstore integration time:
-
Permalink:
pochinoritaro/dddlib@13917e06deae38a2a6ba4ea892e4392ee5270c08 -
Branch / Tag:
refs/tags/v0.1.0a1 - Owner: https://github.com/pochinoritaro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@13917e06deae38a2a6ba4ea892e4392ee5270c08 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file dddlib-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: dddlib-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f948c5ce7109efc748f568ec55724f11c14ed49bc31856350c8d6baf0a55ee36
|
|
| MD5 |
f9d3f6f8c3a7baca8b76da4f35a2b7dd
|
|
| BLAKE2b-256 |
e004d4d0ecab8db98f2f7956995e7b455d3388db3d1febd891e4e98bc9bec228
|
Provenance
The following attestation bundles were made for dddlib-0.1.0a1-py3-none-any.whl:
Publisher:
cd.yml on pochinoritaro/dddlib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dddlib-0.1.0a1-py3-none-any.whl -
Subject digest:
f948c5ce7109efc748f568ec55724f11c14ed49bc31856350c8d6baf0a55ee36 - Sigstore transparency entry: 1543337265
- Sigstore integration time:
-
Permalink:
pochinoritaro/dddlib@13917e06deae38a2a6ba4ea892e4392ee5270c08 -
Branch / Tag:
refs/tags/v0.1.0a1 - Owner: https://github.com/pochinoritaro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@13917e06deae38a2a6ba4ea892e4392ee5270c08 -
Trigger Event:
workflow_dispatch
-
Statement type: