# agelenler/food-ordering-system architecture

> Architecture diagram of the GitHub repository agelenler/food-ordering-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/agelenler/food-ordering-system
- Repository: https://github.com/agelenler/food-ordering-system

## Overview

##### Main Components
- Microservices:
– Customer Service (with its customer-application, customer-dataaccess, customer-domain, and customer-messaging modules)
– Order Service (including its order-application, order-dataaccess, order-domain, and order-messaging modules)
– Payment Service (with payment-container, payment-dataaccess, payment-domain, and payment-messaging modules)
– Restaurant Service (encompassing restaurant-container, restaurant-dataaccess, restaurant-domain, and restaurant-messaging modules)
- Common Module:
– Contains shared domain classes and common infrastructure across services (see common/common-application, common-dataaccess, and common-domain)
- Infrastructure Components:
– Kafka Subsystem: Includes Kafka Producer, Consumer, Model and Config components; the Docker Compose files show a Kafka cluster and Zookeeper setup.
– Outbox Pattern: Each service (especially Order, Payment, and Restaurant) has an outbox with scheduler classes, dedicated repositories, and mappers.
– Saga Orchestrator: Specific classes implementing steps in SAGA (see OrderApprovalSaga, OrderPaymentSaga, and related scheduler/outbox schedulers).

##### Relationships and Interactions
- Each microservice exposes REST endpoints (e.g., CustomerController, OrderController) and communicates via messaging.
– The Order Service emits events (e.g., OrderCreatedEvent) that other services listen to.
– The Payment Service listens to payment request messages from Order and responds via Kafka.
– The Restaurant Service listens for restaurant approval events and publishes responses.
- Outbox modules capture local state changes and publish integration events.
- SAGA orchestration is evident in the Order Service, where multiple steps coordinate (customer notification, payment confirmation, restaurant approval).

##### Architectural Patterns Highlighted
- Clean and Hexagonal Architecture: Show separation between Application, Domain, and Infrastructure (data access, messaging layers).
- Domain-Driven Design (DDD): Bounded contexts for customer, order, payment, and restaurant with corresponding domain entities, value objects, and domain services.
- Event-Driven Communication: Kafka-based messaging channels (producers and consumers) are essential for asynchronous integration.
- Outbox Pattern: An internal staging area for transactional message production.
- SAGA Pattern: The orchestration of multi-step long-running transactions across microservices.

##### Technologies and Frameworks
- Spring Boot for all microservices (each service container has a main application class).
- Maven (pom.xml files) for dependency management.
- Kafka (producers, consumers, event models, and Avro schemas provided in the kafka modules).
- Docker Compose for deployment of Kafka, Zookeeper, and other infrastructure components.
- Databases (implied via schema init scripts and SQL files) and JPA/Hibernate (repositories and entity classes).

##### Additional Advice for Detail
- Do not over-simplify – it is beneficial to show as many boundaries and interactions as possible.
- Be mindful of how the modules are structured (e.g., separate data access, domain, application layers) so that their dependencies are clearly mapped out.
- How the Outbox and Saga mechanisms support eventual consistency across the distributed transactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Customer Service Microservice
    subgraph "Customer Service"
        custApp["Application Layer (CustomerController)"]:::service
        custDomain["Domain Layer (Entities, Services)"]:::service
        custData["Data Access Layer (Repositories)"]:::service
        custMsg["Messaging Layer (Events)"]:::service
    end

    %% Order Service Microservice
    subgraph "Order Service"
        orderApp["Application Layer (OrderController)"]:::service
        orderDomain["Domain Layer (Entities, Services)"]:::service
        orderData["Data Access Layer (Repositories)"]:::service
        orderMsg["Messaging Layer (Events)"]:::service
    end

    %% Payment Service Microservice
    subgraph "Payment Service"
        payContainer["Application Container (Spring Boot)"]:::service
        payDomain["Domain Layer (Entities, Services)"]:::service
        payData["Data Access Layer (Repositories)"]:::service
        payMsg["Messaging Layer (Events)"]:::service
    end

    %% Restaurant Service Microservice
    subgraph "Restaurant Service"
        restContainer["Application Container (Spring Boot)"]:::service
        restDomain["Domain Layer (Entities, Services)"]:::service
        restData["Data Access Layer (Repositories)"]:::service
        restMsg["Messaging Layer (Events)"]:::service
    end

    %% Common Module
    subgraph "Common Module"
        commonApp["Common_Application"]:::common
        commonDomain["Common_Domain"]:::common
        commonData["Common_DataAccess"]:::common
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        kafka["Kafka_Cluster_(Producer|Consumer|Model|Config)"]:::infrastructure
        outbox["Outbox_Pattern_Modules"]:::infrastructure
        saga["Saga_Orchestrator"]:::infrastructure
    end

    %% REST API interactions
    custApp -->|"REST_call"| orderApp

    %% Order Service calls Payment and Restaurant Services
    orderApp -->|"InitiatePayment"| payContainer
    orderApp -->|"SendOrderForApproval"| restContainer
    payContainer -->|"PaymentConfirmation"| orderApp

    %% Messaging interactions via Outbox and Kafka
    orderMsg -->|"OrderCreatedEvent"| payMsg
    orderMsg -->|"OrderCreatedEvent"| restMsg
    payMsg -->|"PaymentResponse"| orderMsg

    %% Outbox integration - services publish events to Outbox
    orderMsg -->|"IntegrationEvent"| outbox
    payMsg -->|"IntegrationEvent"| outbox
    restMsg -->|"IntegrationEvent"| outbox
    outbox -->|"PublishEvent"| kafka

    %% Kafka delivering messages back into service messaging layers
    kafka -->|"KafkaMessage"| orderMsg
    kafka -->|"KafkaMessage"| payMsg
    kafka -->|"KafkaMessage"| restMsg
    kafka -->|"KafkaMessage"| custMsg

    %% SAGA orchestration interactions
    saga -->|"InitiateSaga"| orderApp
    orderApp -->|"SagaCompleted"| saga

    %% Click Events for Customer Service Modules
    click custApp "https://github.com/agelenler/food-ordering-system/tree/master/customer-service/customer-application"
    click custData "https://github.com/agelenler/food-ordering-system/tree/master/customer-service/customer-dataaccess"
    click custDomain "https://github.com/agelenler/food-ordering-system/tree/master/customer-service/customer-domain"
    click custMsg "https://github.com/agelenler/food-ordering-system/tree/master/customer-service/customer-messaging"

    %% Click Events for Order Service Modules
    click orderApp "https://github.com/agelenler/food-ordering-system/tree/master/order-service/order-application"
    click orderData "https://github.com/agelenler/food-ordering-system/tree/master/order-service/order-dataaccess"
    click orderDomain "https://github.com/agelenler/food-ordering-system/tree/master/order-service/order-domain"
    click orderMsg "https://github.com/agelenler/food-ordering-system/tree/master/order-service/order-messaging"

    %% Click Events for Payment Service Modules
    click payContainer "https://github.com/agelenler/food-ordering-system/tree/master/payment-service/payment-container"
    click payData "https://github.com/agelenler/food-ordering-system/tree/master/payment-service/payment-dataaccess"
    click payDomain "https://github.com/agelenler/food-ordering-system/tree/master/payment-service/payment-domain"
    click payMsg "https://github.com/agelenler/food-ordering-system/tree/master/payment-service/payment-messaging"

    %% Click Events for Restaurant Service Modules
    click restContainer "https://github.com/agelenler/food-ordering-system/tree/master/restaurant-service/restaurant-container"
    click restData "https://github.com/agelenler/food-ordering-system/tree/master/restaurant-service/restaurant-dataaccess"
    click restDomain "https://github.com/agelenler/food-ordering-system/tree/master/restaurant-service/restaurant-domain"
    click restMsg "https://github.com/agelenler/food-ordering-system/tree/master/restaurant-service/restaurant-messaging"

    %% Click Events for Common Module
    click commonApp "https://github.com/agelenler/food-ordering-system/tree/master/common/common-application"
    click commonData "https://github.com/agelenler/food-ordering-system/tree/master/common/common-dataaccess"
    click commonDomain "https://github.com/agelenler/food-ordering-system/tree/master/common/common-domain"

    %% Click Events for Infrastructure Components
    click kafka "https://github.com/agelenler/food-ordering-system/tree/master/infrastructure/kafka"
    click outbox "https://github.com/agelenler/food-ordering-system/tree/master/infrastructure/outbox"
    click saga "https://github.com/agelenler/food-ordering-system/tree/master/infrastructure/saga"

    %% Styling
    classDef service fill:#AED6F1,stroke:#5DADE2,stroke-width:2px;
    classDef common fill:#F9E79F,stroke:#F4D03F,stroke-width:2px;
    classDef infrastructure fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
```
