Commit bbd546f
feat: add pyfly.domain DDD primitives + OrderService sample (v26.05.02) (#8)
Adds the DDD building blocks that mirror fireflyframework-starter-domain
(Java) and FireflyFramework.Starter.Domain (.NET), plus a complete
OrderService sample that exercises every primitive end-to-end.
pyfly.domain (new module, zero runtime dependencies)
- Entity[TID]: identity-based equality, transient/persisted distinction,
(type, id) hashing.
- ValueObject: marker base for @DataClass(frozen=True) records with
structural equality, immutability, replace() helper.
- AggregateRoot[TID]: extends Entity[TID] with a pending_events buffer
(raise_event / pending_events / clear_events). Distinct from the
event-sourced pyfly.eventsourcing.AggregateRoot; both coexist.
- DomainEvent: frozen-dataclass base with auto-assigned UUID event_id,
UTC occurred_at, and event_type defaulted to the subclass name.
- Specification[T]: composable in-memory predicate with & / | / ~
combinators and a Specification.of(callable) factory.
- DomainRepository[A, TID]: runtime-checkable collection-like protocol
(add, find, remove, next_id).
- DomainException, BusinessRuleViolation (DOMAIN_RULE_VIOLATION),
AggregateNotFound (DOMAIN_AGGREGATE_NOT_FOUND): extend
pyfly.kernel.BusinessException so the existing RFC 7807 mappers
translate them automatically.
- pyfly.starters.domain re-exports every primitive alongside
enable_domain_stack so a single import line is enough for a
domain-tier service.
OrderService sample (samples/order_service/)
Mirrors the layered split used by Java domain microservices in
firefly-oss and the .NET FireflyFramework.Samples.OrdersService:
interfaces/ DTOs + enums (PlaceOrderRequest, OrderDto, OrderStatus)
models/ Order aggregate root + repository (port + InMemory adapter)
core/ Commands, queries, handlers, mapper, ConfirmOrderSaga
web/ @rest_controller for /api/v1/orders
sdk/ Typed httpx-based client
app.py @pyfly_application + @enable_domain_stack
Order is a real AggregateRoot[str] with state-machine invariants
enforced by BusinessRuleViolation. PlaceOrderHandler creates and
persists the aggregate and publishes its pending events.
ConfirmOrderSaga walks the order through PLACED ->
INVENTORY_RESERVED -> PAID -> SHIPPED with full compensation via
three stub external services (InventoryService, PaymentService,
ShippingService). 13/13 end-to-end tests pass against the real CQRS
bus and saga engine -- no mocks.
Fixed: async saga and TCC step support
@saga_step / @try_method / @confirm_method / @cancel_method used to
wrap the target with a synchronous functools.wraps adapter that masked
inspect.iscoroutinefunction. The engine therefore called async def
steps without await and the actual coroutine never ran. The wrappers
were no-ops; metadata is now attached directly to the original
function. Regression test pinned in
tests/transactional/saga/test_async_steps.py.
Versioning
- pyproject.toml: 26.5.1 -> 26.5.2
- pyfly.__version__: 26.05.01 -> 26.05.02
- install.sh PYFLY_VERSION: 26.05.01 -> 26.05.02
- README badge, install URLs, "Current" section, Modules count (38 -> 39)
- ROADMAP marks Phase 4 DDD as complete; Backoffice and Utils planned
- CHANGELOG.md adds v26.05.02 entry
- New module guide docs/modules/domain.md
42 new tests (35 domain + 1 async-saga regression + 13 sample). All
existing tests still pass (1279 in the impacted slices).
Co-authored-by: Andrés Contreras Guillén <ancongui@Andress-MacBook-Pro.local>1 parent 0172266 commit bbd546f
68 files changed
Lines changed: 3471 additions & 58 deletions
File tree
- docs
- modules
- samples/order_service
- src/order_service
- core
- mappers
- services
- orders
- interfaces
- dtos
- v1
- enums
- v1
- models
- entities
- v1
- repositories
- sdk
- web
- controllers
- tests
- src/pyfly
- domain
- starters
- transactional
- saga
- tcc
- tests
- domain
- transactional/saga
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
9 | 95 | | |
10 | 96 | | |
11 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
732 | 732 | | |
733 | 733 | | |
734 | 734 | | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
735 | 797 | | |
736 | 798 | | |
737 | 799 | | |
| |||
742 | 804 | | |
743 | 805 | | |
744 | 806 | | |
745 | | - | |
| 807 | + | |
746 | 808 | | |
747 | 809 | | |
748 | | - | |
| 810 | + | |
749 | 811 | | |
750 | 812 | | |
751 | | - | |
| 813 | + | |
752 | 814 | | |
753 | 815 | | |
754 | 816 | | |
| |||
925 | 987 | | |
926 | 988 | | |
927 | 989 | | |
928 | | - | |
| 990 | + | |
929 | 991 | | |
930 | 992 | | |
931 | 993 | | |
| |||
964 | 1026 | | |
965 | 1027 | | |
966 | 1028 | | |
| 1029 | + | |
967 | 1030 | | |
968 | 1031 | | |
969 | 1032 | | |
| |||
1017 | 1080 | | |
1018 | 1081 | | |
1019 | 1082 | | |
| 1083 | + | |
1020 | 1084 | | |
1021 | 1085 | | |
1022 | 1086 | | |
| |||
1045 | 1109 | | |
1046 | 1110 | | |
1047 | 1111 | | |
1048 | | - | |
| 1112 | + | |
1049 | 1113 | | |
1050 | 1114 | | |
1051 | 1115 | | |
| |||
1071 | 1135 | | |
1072 | 1136 | | |
1073 | 1137 | | |
1074 | | - | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
1075 | 1145 | | |
1076 | 1146 | | |
1077 | 1147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| |||
0 commit comments