Packages by layer
A class diagram. An order service in three packages, the domain inside the application, with a repository interface and its PostgreSQL implementation in infrastructure.






┌─ Application ───────────────────────────────────────────────────┐
│ │
│ ┌──────────────────────────┐ │
│ │ OrderController │ │
│ ├──────────────────────────┤ │
│ │ + create(req): Response │ │
│ └──────────────────────────┘ │
│ │ │
│ │ │
│ ▼ │
│ ┌──────────────────────────┐ │
│ │ OrderService │ │
│ ├──────────────────────────┤ │
│ │ + placeOrder(cmd): Order │ │
│ └──────────────────────────┘ │
│ ╎ │ │
│ ╎ │ │
│ ┌╌╌╌╌╌╌╌╌╌┘ └──────────┐ │
│ ╎ │ │
│ ┌─ Domain ───┼─────────────────────────────┼────────────────┐ │
│ │ ▼ ▼ │ │
│ │ ┌──────────────────┐ ┌────────────────────────────┐ │ │
│ │ │ Order │ │ «interface» │ │ │
│ │ ├──────────────────┤ │ OrderRepository │ │ │
│ │ │ - id: string │ ├────────────────────────────┤ │ │
│ │ ├──────────────────┤ │ + save(order: Order): void │ │ │
│ │ │ + total(): Money │ └────────────────────────────┘ │ │
│ │ └──────────────────┘ △ │ │
│ │ ◆ 1 ╎ │ │
│ │ │ ╎ │ │
│ │ │ 1..* ╎ │ │
│ │ ┌──────────────────┐ ╎ │ │
│ │ │ LineItem │ ╎ │ │
│ │ ├──────────────────┤ ╎ │ │
│ │ │ - quantity: int │ ╎ │ │
│ │ └──────────────────┘ ╎ │ │
│ └──────────────────────────────────────────┼────────────────┘ │
└─────────────────────────────────────────────┼───────────────────┘
╎
╎
╎
┌─ Infrastructure ┼────────────────┐
│ ╎ │
│ ┌────────────────────────────┐ │
│ │ PgOrderRepository │ │
│ ├────────────────────────────┤ │
│ │ + save(order: Order): void │ │
│ └────────────────────────────┘ │
└──────────────────────────────────┘
Spec
{ "type": "class", "classes": [ { "id": "controller", "label": "OrderController", "methods": [{"visibility": "+", "text": "create(req): Response"}] }, { "id": "service", "label": "OrderService", "methods": [{"visibility": "+", "text": "placeOrder(cmd): Order"}] }, { "id": "order", "label": "Order", "attributes": [{"visibility": "-", "text": "id: string"}], "methods": [{"visibility": "+", "text": "total(): Money"}] }, { "id": "item", "label": "LineItem", "attributes": [{"visibility": "-", "text": "quantity: int"}] }, { "id": "repo", "label": "OrderRepository", "stereotype": "interface", "color": "orange", "methods": [{"visibility": "+", "text": "save(order: Order): void"}] }, { "id": "pgRepo", "label": "PgOrderRepository", "methods": [{"visibility": "+", "text": "save(order: Order): void"}] } ], "relations": [ { "id": "r-controller-service", "from": "controller", "to": "service", "kind": "association", "directed": true }, {"id": "r-service-order", "from": "service", "to": "order", "kind": "dependency"}, { "id": "r-order-item", "from": "order", "to": "item", "kind": "composition", "from_card": "1", "to_card": "1..*" }, { "id": "r-service-repo", "from": "service", "to": "repo", "kind": "association", "directed": true }, {"id": "r-pgRepo-repo", "from": "pgRepo", "to": "repo", "kind": "realization"} ], "packages": [ { "id": "app", "label": "Application", "color": "blue", "contains": ["controller", "service", "domain"] }, {"id": "domain", "label": "Domain", "color": "purple", "contains": ["order", "item", "repo"]}, {"id": "infra", "label": "Infrastructure", "color": "gray", "contains": ["pgRepo"]} ]}Draw it yourself
diago render layered-packages.json > layered-packages.svgOpen it in the playground to edit it in your browser.