# thanhtrixx/coffee-shop architecture

> Architecture diagram of the GitHub repository thanhtrixx/coffee-shop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thanhtrixx/coffee-shop
- Repository: https://github.com/thanhtrixx/coffee-shop

## Overview

##### Main Components

a. Module Structure (Core Components):
- Order Module
- Brewing Module
- Common Module (Cross-cutting concerns)

b. For each module, represent these layers:
- API Layer (Controllers, DTOs)
- Service Layer
- Internal Layer (Repositories, Entities)
- Command Layer (Inter-module communication)

##### Component Relationships

**┌─────────────────────────────────────────────────────────────┐**
- Coffee Shop Application                  │

- ┌─────────────┐        ┌──────────────┐    ┌──────────┐   │
- Order Module│◄─────►│Brewing Module │    │  Common  │   │
- Module  │   │
- ┘        └──────────────┘    └──────────┘   │

- ┘

##### Detailed Module Breakdown

Order Module:
**┌─────────────────────────────────────┐**
- Order Module             │
- ┌───────────────────────────────┐   │
- OrderController          │   │
- ┬───────────────┘   │
- ┌───────────────┼───────────────┐   │
- OrderService│               │   │
- ┼───────────────┘   │
- ┌───────────────┼───────────────┐   │
- OrderRepository  OrderEntity   │   │
- ┘   │
- ┘

##### Inter-module Communication
- Event listeners (OrderListener, BrewingListener)
- Command objects (BrewingCommand, BrewingResultCommand)

##### Additional Elements
- Database connection (likely using JPA/Hibernate based on the structure)
- Configuration components (application.yml)
- Cross-cutting concerns from the Common module

##### Important Notes
- Modular boundaries (Spring Modulith context)
- Clear separation between public APIs and internal implementations
- Event-driven communication pattern between modules
- Error handling flow through the Common module's exceptions

##### Technical Stack Indicators
- Kotlin
- Spring Framework
- Spring Modulith
- JPA (implied by repository pattern)

Remember to:
- Keep module boundaries clear and well-defined
- Both synchronous (direct) and asynchronous (event-based) communications
- Notes about the Spring Modulith specific patterns and conventions

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CoffeeShop["Coffee Shop Application"]
        subgraph OrderModule["Order Module"]
            OrderController["Order Controller"]:::controller
            OrderService["Order Service"]:::service
            OrderRepo["Order Repository"]:::repository
            OrderEntity["Order Entity"]:::entity
            OrderListener["Order Listener"]:::listener
            BrewingCommand["Brewing Command"]:::command
            
            OrderController --> OrderService
            OrderService --> OrderRepo
            OrderRepo --> OrderEntity
            OrderService --> BrewingCommand
            OrderListener --> OrderService
        end

        subgraph BrewingModule["Brewing Module"]
            BrewingListener["Brewing Listener"]:::listener
            BrewingResultCommand["Brewing Result Command"]:::command
            
            BrewingListener --> BrewingResultCommand
        end

        subgraph CommonModule["Common Module"]
            ExceptionHandling["Exception Handling"]:::common
            Logging["Logging"]:::common
        end

        AppConfig["Application Config"]:::config
        AppEntry["Application Entry"]:::main

        %% Inter-module communication
        BrewingCommand --> BrewingListener
        BrewingResultCommand --> OrderListener
        
        %% Common module usage
        OrderModule --> CommonModule
        BrewingModule --> CommonModule
    end

    %% Click events for file navigation
    click OrderController "https://github.com/thanhtrixx/coffee-shop/blob/main/src/main/kotlin/trile/coffeeshop/order/OrderController.kt"
    click OrderService "https://github.com/thanhtrixx/coffee-shop/blob/main/src/main/kotlin/trile/coffeeshop/order/OrderService.kt"
    click OrderRepo "https://github.com/thanhtrixx/coffee-shop/blob/main/src/main/kotlin/trile/coffeeshop/order/internal/OrderRepository.kt"
    click OrderEntity "https://github.com/thanhtrixx/coffee-shop/blob/main/src/main/kotlin/trile/coffeeshop/order/internal/OrderEntity.kt"
    click OrderListener "https://github.com/thanhtrixx/coffee-shop/blob/main/src/main/kotlin/trile/coffeeshop/order/internal/OrderListener.kt"
    click BrewingCommand "https://github.com/thanhtrixx/coffee-shop/blob/main/src/main/kotlin/trile/coffeeshop/order/command/BrewingCommand.kt"
    click BrewingListener "https://github.com/thanhtrixx/coffee-shop/blob/main/src/main/kotlin/trile/coffeeshop/brewing/internal/BrewingListener.kt"
    click BrewingResultCommand "https://github.com/thanhtrixx/coffee-shop/blob/main/src/main/kotlin/trile/coffeeshop/brewing/command/BrewingResultCommand.kt"
    click ExceptionHandling "https://github.com/thanhtrixx/coffee-shop/tree/main/src/main/kotlin/trile/coffeeshop/common/exception"
    click Logging "https://github.com/thanhtrixx/coffee-shop/blob/main/src/main/kotlin/trile/coffeeshop/common/Log.kt"
    click AppEntry "https://github.com/thanhtrixx/coffee-shop/blob/main/src/main/kotlin/trile/coffeeshop/CoffeeshopApp.kt"
    click AppConfig "https://github.com/thanhtrixx/coffee-shop/blob/main/src/main/resources/application.yml"
    click OrderModule "https://github.com/thanhtrixx/coffee-shop/tree/main/src/main/kotlin/trile/coffeeshop/order"
    click BrewingModule "https://github.com/thanhtrixx/coffee-shop/tree/main/src/main/kotlin/trile/coffeeshop/brewing"
    click CommonModule "https://github.com/thanhtrixx/coffee-shop/tree/main/src/main/kotlin/trile/coffeeshop/common"

    %% Styling
    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef repository fill:#FFC107,stroke:#FFA000,color:black
    classDef entity fill:#FFEB3B,stroke:#FBC02D,color:black
    classDef listener fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef command fill:#FF5722,stroke:#D84315,color:white
    classDef common fill:#673AB7,stroke:#4527A0,color:white
    classDef config fill:#795548,stroke:#4E342E,color:white
    classDef main fill:#607D8B,stroke:#37474F,color:white
```
