How andersongomes001/clean-architecture-java works
This repository is organized as a clean/hexagonal architecture Java application. The core idea is that business logic lives in the center, while controllers and storage adapters sit at the edges behind ports.
1. Entry point
- Main.java is the application bootstrap.
- pom.xml indicates a Maven-based Java project.
2. Domain layer
- com.commitdesexta.domain.model contains the core business objects: Product, Cart, and Order.
- These are the most stable part of the system and should not depend on infrastructure concerns.
3. Application layer: input ports
- com.commitdesexta.application.port.input defines the supported use cases:
- create product
- add item to cart
- remove item from cart
- calculate total
- checkout
- These ports define what the system can do from the outside.
4. Application layer: use case implementations
- com.commitdesexta.application.usecase contains the actual business workflows.
- Each use case implements an input port and orchestrates domain objects plus repository ports.
- This is where cart manipulation, total calculation, and checkout logic are coordinated.
5. Application layer: output ports
- com.commitdesexta.application.port.output defines repository abstractions for:
- ProductRepositoryPort
- CartRepositoryPort
- OrderRepositoryPort
- Use cases depend on these interfaces, not on concrete persistence or storage code.
6. Infrastructure: controllers
- com.commitdesexta.infrastructure.controller contains the entry adapters:
- ProductController
- CartController
- OrderController
- These are the boundary for external requests and translate them into use case calls.
- ProductResponse in the DTO package shows that API-facing models are separated from domain models.
7. Infrastructure: repository adapters
- com.commitdesexta.infrastructure.adapter.inmemory provides in-memory implementations of the output ports.
- This means the application can run without an external database, which is useful for local execution, demos, or testing.
8. Persistence model and mapping
- com.commitdesexta.infrastructure.persistence.entity contains storage-oriented entities: CartEntity, OrderEntity, and ProductEntity.
- com.commitdesexta.infrastructure.persistence.mapper contains mappers that translate between domain objects and persistence entities.
- This separation keeps persistence shape independent from domain shape.
9. Primary data flow
- External request enters a controller.
- Controller calls an input-port use case.
- Use case loads or updates domain objects.
- Use case calls an output-port repository abstraction.
- A concrete adapter stores or retrieves data.
- Result flows back through the controller to the caller.
10. Business boundaries
- Product management is separate from Cart and Order flows.
- CheckoutUseCase likely bridges the cart and order subsystems by converting a cart into an order and finalizing totals.
- This suggests a simple commerce workflow with clear state transitions.
11. Architectural style
- The package structure strongly suggests a ports-and-adapters / clean architecture design.
- Dependencies point inward: infrastructure depends on application ports, and application depends on domain plus output abstractions.
12. What to show in an architecture diagram
- Put domain in the center.
- Surround it with application/usecase and the input/output ports.
- On the outside, place controller as the inbound adapter and inmemory adapter / persistence as outbound adapters.
- Show Product, Cart, and Order as separate domain entities connected to their respective use cases and repositories.
Main entry points: input Input ports · usecase Cart usecases · CheckoutUseCase.java Checkout · output Output ports
Components 16
Domain
Core business model and rules
Application
Use cases and ports
- Input ports · Supported application actions
src/main/java/com/commitdesexta/application/port/input - Product usecases · Create and expose products
src/main/java/com/commitdesexta/application/usecase - Cart usecases · Add, remove, and total cart flows
src/main/java/com/commitdesexta/application/usecase - Checkout · Finalize cart into order
src/main/java/com/commitdesexta/application/usecase/CheckoutUseCase.java - Output ports · Persistence abstractions
src/main/java/com/commitdesexta/application/port/output
Infrastructure
Entry adapters and storage adapters
- Main · Application entry point
src/main/java/com/commitdesexta/Main.java - Product controller · Handles product requests
src/main/java/com/commitdesexta/infrastructure/controller/ProductController.java - Cart controller · Handles cart requests
src/main/java/com/commitdesexta/infrastructure/controller/CartController.java - Order controller · Handles order requests
src/main/java/com/commitdesexta/infrastructure/controller/OrderController.java - Product response · API-facing product model
src/main/java/com/commitdesexta/infrastructure/controller/dto/ProductResponse.java - In-memory repos · In-memory implementations of repositories
src/main/java/com/commitdesexta/infrastructure/adapter/inmemory - Entities · Storage-oriented records
src/main/java/com/commitdesexta/infrastructure/persistence/entity - Mappers · Domain to persistence mapping
src/main/java/com/commitdesexta/infrastructure/persistence/mapper
Connections 21
- Main → Product controller: bootstraps · Application entry wires inbound adapters
- Main → Cart controller: bootstraps · Application entry wires inbound adapters
- Main → Order controller: bootstraps · Application entry wires inbound adapters
- Product controller → Input ports: calls · Controllers invoke use cases through input ports
- Cart controller → Input ports: calls · Controllers invoke use cases through input ports
- Order controller → Input ports: calls · Controllers invoke use cases through input ports
- Input ports → Product usecases: implemented by · Use cases realize input ports
- Input ports → Cart usecases: implemented by · Use cases realize input ports
- Input ports → Checkout: implemented by · Use cases realize input ports
- Product usecases → Product: uses · Product workflows operate on product domain objects
- Cart usecases → Cart: uses · Cart workflows operate on cart domain objects
- Cart usecases → Product: uses · Cart flows reference catalog items
- Checkout → Cart: uses · Checkout consumes cart state
- Checkout → Order: creates · Checkout finalizes an order
- Product usecases → Output ports: reads/writes · Use cases persist through repository ports
- Cart usecases → Output ports: reads/writes · Use cases persist through repository ports
- Checkout → Output ports: reads/writes · Use cases persist through repository ports
- Output ports → In-memory repos: implemented by · Adapters provide concrete repository behavior
- In-memory repos → Entities: stores · Adapters persist storage-shaped entities
- In-memory repos → Mappers: uses · Adapters translate between models and entities
- Product controller → Product response: returns · Controllers expose API DTOs