-
Notifications
You must be signed in to change notification settings - Fork 14
GH#14040: tighten hexagonal.md 181→160 lines #14061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,32 +8,19 @@ | |||||||||
|
|
||||||||||
| ```mermaid | ||||||||||
| flowchart TB | ||||||||||
| subgraph DriverSide["DRIVER SIDE (Primary / Inbound / Left)"] | ||||||||||
| REST["REST API Adapter"] | ||||||||||
| CLI["CLI Adapter"] | ||||||||||
| DriverPorts["DRIVER PORTS\n(Use Case Interfaces)"] | ||||||||||
| REST --> DriverPorts | ||||||||||
| CLI --> DriverPorts | ||||||||||
| subgraph DriverSide["DRIVER SIDE (Primary / Inbound)"] | ||||||||||
| REST["REST API"] --> DriverPorts["DRIVER PORTS\n(Use Case Interfaces)"] | ||||||||||
| CLI["CLI"] --> DriverPorts | ||||||||||
| end | ||||||||||
|
|
||||||||||
| subgraph Hexagon["THE HEXAGON"] | ||||||||||
| subgraph AppCore["APPLICATION CORE"] | ||||||||||
| subgraph Domain["DOMAIN\n(Business Logic)"] | ||||||||||
| end | ||||||||||
| end | ||||||||||
| Domain["DOMAIN\n(Business Logic)"] | ||||||||||
| end | ||||||||||
|
|
||||||||||
| subgraph DrivenSide["DRIVEN SIDE (Secondary / Outbound / Right)"] | ||||||||||
| DrivenPorts["DRIVEN PORTS\n(Repository Interfaces)"] | ||||||||||
| Postgres["Postgres Adapter"] | ||||||||||
| RabbitMQ["RabbitMQ Adapter"] | ||||||||||
| DrivenPorts --> Postgres | ||||||||||
| DrivenPorts --> RabbitMQ | ||||||||||
| subgraph DrivenSide["DRIVEN SIDE (Secondary / Outbound)"] | ||||||||||
| DrivenPorts["DRIVEN PORTS\n(Repository Interfaces)"] --> Postgres["Postgres"] | ||||||||||
| DrivenPorts --> RabbitMQ["RabbitMQ"] | ||||||||||
| end | ||||||||||
|
|
||||||||||
| DriverPorts --> AppCore | ||||||||||
| AppCore --> DrivenPorts | ||||||||||
|
|
||||||||||
| DriverPorts --> Domain | ||||||||||
| Domain --> DrivenPorts | ||||||||||
| style DriverSide fill:#3b82f6,stroke:#2563eb,color:white | ||||||||||
| style Hexagon fill:#10b981,stroke:#059669,color:white | ||||||||||
| style DrivenSide fill:#f59e0b,stroke:#d97706,color:white | ||||||||||
|
|
@@ -59,14 +46,12 @@ export interface IOrderRepositoryPort { | |||||||||
| save(order: Order): Promise<void>; | ||||||||||
| delete(order: Order): Promise<void>; | ||||||||||
| } | ||||||||||
| // application/ports/driven/event_publisher_port.ts | ||||||||||
| export interface IEventPublisherPort { | ||||||||||
| publish(event: DomainEvent): Promise<void>; | ||||||||||
| publishAll(events: DomainEvent[]): Promise<void>; | ||||||||||
| } | ||||||||||
| // application/ports/driven/payment_gateway_port.ts | ||||||||||
| export interface IPaymentGatewayPort { | ||||||||||
| charge(amount: Money, paymentMethod: PaymentMethod): Promise<PaymentResult>; | ||||||||||
| charge(amount: Money, method: PaymentMethod): Promise<PaymentResult>; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter
Suggested change
|
||||||||||
| refund(paymentId: PaymentId, amount: Money): Promise<RefundResult>; | ||||||||||
| } | ||||||||||
| ``` | ||||||||||
|
|
@@ -78,17 +63,11 @@ export interface IPaymentGatewayPort { | |||||||||
| ```typescript | ||||||||||
| // infrastructure/adapters/driver/rest/order_controller.ts | ||||||||||
| export class OrderController { | ||||||||||
| constructor( | ||||||||||
| private readonly placeOrder: IPlaceOrderPort, | ||||||||||
| private readonly getOrder: IGetOrderPort, | ||||||||||
| ) {} | ||||||||||
|
|
||||||||||
| constructor(private readonly placeOrder: IPlaceOrderPort, private readonly getOrder: IGetOrderPort) {} | ||||||||||
| async create(req: Request, res: Response): Promise<void> { | ||||||||||
| const orderId = await this.placeOrder.execute({ | ||||||||||
| customerId: req.user.id, | ||||||||||
| items: req.body.items.map((item: any) => ({ | ||||||||||
| productId: item.product_id, quantity: item.quantity, | ||||||||||
| })), | ||||||||||
| items: req.body.items.map((i: any) => ({ productId: i.product_id, quantity: i.quantity })), | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||||||
| }); | ||||||||||
| res.status(201).json({ id: orderId.value }); | ||||||||||
| } | ||||||||||
|
|
@@ -112,7 +91,7 @@ class InMemoryOrderRepository implements IOrderRepositoryPort: # for tests | |||||||||
| delete(order): orders.delete(order.id.value) | ||||||||||
|
|
||||||||||
| class StripePaymentGateway implements IPaymentGatewayPort: | ||||||||||
| charge(amount, paymentMethod) -> PaymentResult: | ||||||||||
| charge(amount, method) -> PaymentResult: | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the TypeScript interface change, renaming
Suggested change
|
||||||||||
| intent = stripe.paymentIntents.create({amount: amount.cents, ...}) | ||||||||||
| return PaymentResult.success(PaymentId.from(intent.id)) | ||||||||||
| refund(paymentId, amount): stripe.refunds.create({paymentIntent: paymentId.value, ...}) | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The simplification of the Mermaid diagram, specifically removing the
AppCoresubgraph and connectingDriverPortsdirectly toDomain, might oversimplify the architecture and misrepresent the dependency flow. In Hexagonal Architecture, driver adapters interact with application services (use cases), which then orchestrate the domain logic. TheAppCorelayer represented this crucial application service layer. The direct connectionDriverPorts --> Domainimplies that adapters are calling the domain logic directly, which is generally discouraged. While Rule 1 suggests conciseness in core files, Rule 4 and Rule 5 emphasize restoring key concepts and details for clarity and technical accuracy.References