# microservices-patterns/ftgo-application architecture

> Architecture diagram of the GitHub repository microservices-patterns/ftgo-application, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microservices-patterns/ftgo-application
- Repository: https://github.com/microservices-patterns/ftgo-application

## Overview

##### Project type and purpose
- This is an example microservice application (“FTGO”) illustrating the patterns in the “Microservice Patterns” book.
- It is a polyglot microservice architecture composed of multiple Spring Boot services, a GraphQL API gateway, shared libraries, and infrastructure components (Kafka, MySQL, DynamoDB).

##### File structure
- Top-level modules correspond to individual services:
- ftgo-consumer-service
- ftgo-restaurant-service (also an AWS Lambda flavor)
- ftgo-order-service
- ftgo-kitchen-service
- ftgo-accounting-service
- ftgo-order-history-service (CQRS read model)
- ftgo-api-gateway / ftgo-api-gateway-graphql
- Shared libraries under ftgo-common*, common-swagger, test-util, JSON schema codegen.
- Infrastructure & deployment manifests: Docker Compose yaml at root, Kubernetes yamls in deployment/kubernetes and each service’s src/deployment/kubernetes.
- Build orchestrated via Gradle (including custom plugins in buildSrc).

##### Main components
- External client(s) or UI (Swagger UI, GraphQL client, curl).
- API Gateway (REST or GraphQL)
- Six microservices: Consumer, Restaurant, Order, Kitchen, Accounting, Order History
- Message Broker (Kafka + Zookeeper)
- Databases: MySQL (for services), DynamoDB (for order history)
- Shared libraries (logical grouping, not runtime component)

##### Interactions and data flows
- Client → API Gateway (HTTP/GraphQL)
- API Gateway → downstream services via synchronous HTTP or gRPC
- Services communicate inter-process via Eventuate Tram (Kafka) for commands/events
- Sagas orchestrate long-running transactions (Order creation, cancellation, revision)
- Each service subscribes to commands/events on its own topic.
- Order History service builds CQRS view by subscribing to domain events and writing to DynamoDB
- Each service persists its own state in a private database (MySQL for most; AWS Lambda variant uses embedded storage)

##### Architectural patterns & design principles
- Microservice per bounded context, spring-boot modules
- Database per service
- Synchronous APIs (REST, gRPC) for client-service and service-service queries
- Asynchronous messaging via Kafka for decoupling and saga orchestration (Eventuate Tram & Sag­as)
- Event sourcing in Accounting service
- CQRS read model in Order History service
- API composition via API Gateway (GraphQL or REST)

##### Relevant technologies & frameworks
- Spring Boot (web, Data JPA)
- Eventuate Tram (transactional messaging), Eventuate Tram Sagas
- Apache Kafka & Zookeeper
- MySQL, DynamoDB (via test-local containers)
- Swagger UI for each service
- GraphQL in ftgo-api-gateway-graphql
- Docker Compose & Kubernetes for deployment

##### Detail but clarity
- Both sync and async interactions

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Clients"
        Client["External Client (UI / curl)"]:::client
    end

    subgraph "API Gateway Layer"
        RESTGW["REST API Gateway"]:::gateway
        GraphQLGW["GraphQL API Gateway"]:::gateway
    end

    subgraph "Microservices"
        ConSvc["Consumer Service"]:::service
        RestSvc["Restaurant Service"]:::service
        RestLambda["Restaurant Service (AWS Lambda)"]:::service
        OrderSvc["Order Service"]:::service
        KitchenSvc["Kitchen Service"]:::service
        AccountSvc["Accounting Service"]:::service
        OrderHistSvc["Order History Service"]:::service
    end

    subgraph "Shared Libraries"
        Common["Common Utilities"]:::library
        JPA["JPA Utilities"]:::library
        SwaggerLib["Swagger Generation"]:::library
        JSONCodegen["JSON Schema Codegen"]:::library
    end

    subgraph "Infrastructure"
        Kafka["Kafka Broker"]:::broker
        ZK["Zookeeper"]:::broker
        MySQL["MySQL Databases (per service)"]:::db
        Dynamo["DynamoDB (Order History)"]:::db
    end

    %% Synchronous Client → Gateway
    Client -->|"HTTP/REST"| RESTGW
    Client -->|"GraphQL"| GraphQLGW

    %% Gateway → Services
    RESTGW -->|"REST/gRPC"| ConSvc
    RESTGW -->|"REST/gRPC"| RestSvc
    RESTGW -->|"REST/gRPC"| OrderSvc
    RESTGW -->|"REST/gRPC"| KitchenSvc
    RESTGW -->|"REST/gRPC"| AccountSvc

    GraphQLGW -->|"GraphQL"| ConSvc
    GraphQLGW -->|"GraphQL"| RestSvc
    GraphQLGW -->|"GraphQL"| OrderSvc
    GraphQLGW -->|"GraphQL"| KitchenSvc
    GraphQLGW -->|"GraphQL"| AccountSvc

    %% Service → Own Database
    ConSvc -->|"JPA"| MySQL
    RestSvc -->|"JPA"| MySQL
    RestLambda -->|"Embedded DB"| MySQL
    OrderSvc -->|"JPA"| MySQL
    KitchenSvc -->|"JPA"| MySQL
    AccountSvc -->|"JPA/Event Sourcing"| MySQL
    OrderHistSvc -->|"CQRS Read"| Dynamo

    %% Asynchronous Messaging via Kafka
    ConSvc -.->|"CreateOrderCommand"| Kafka
    Kafka -.->|"OrderCreatedEvent"| OrderSvc
    RestSvc -.->|"RestaurantApprovedEvent"| Kafka
    Kafka -.->|"ApproveRestaurantReply"| ConSvc
    OrderSvc -.->|"OrderCreatedEvent"| Kafka
    KitchenSvc -.->|"OrderReadyEvent"| Kafka
    AccountSvc -.->|"AccountingEvent"| Kafka
    Kafka -.->|"Consume Events"| OrderHistSvc

    %% Zookeeper for Kafka
    ZK --> Kafka

    %% Click Events
    click RESTGW "https://github.com/microservices-patterns/ftgo-application/blob/master/ftgo-api-gateway/src/main/java/net/chrisrichardson/ftgo/apiagateway/ApiGatewayApplication.java"
    click GraphQLGW "https://github.com/microservices-patterns/ftgo-application/blob/master/ftgo-api-gateway-graphql/src/index.js"
    click ConSvc "https://github.com/microservices-patterns/ftgo-application/blob/master/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/ConsumerServiceMain.java"
    click RestSvc "https://github.com/microservices-patterns/ftgo-application/blob/master/ftgo-restaurant-service/src/main/java/net/chrisrichardson/ftgo/restaurantservice/RestaurantServiceMain.java"
    click RestLambda "https://github.com/microservices-patterns/ftgo-application/blob/master/ftgo-restaurant-service-aws-lambda/src/main/java/net/chrisrichardson/ftgo/restaurantservice/aws/AbstractHttpHandler.java"
    click OrderSvc "https://github.com/microservices-patterns/ftgo-application/blob/master/ftgo-order-service/src/main/java/net/chrisrichardson/ftgo/orderservice/main/OrderServiceMain.java"
    click KitchenSvc "https://github.com/microservices-patterns/ftgo-application/blob/master/ftgo-kitchen-service/src/main/java/net/chrisrichardson/ftgo/kitchenservice/main/KitchenServiceMain.java"
    click AccountSvc "https://github.com/microservices-patterns/ftgo-application/blob/master/ftgo-accounting-service/src/main/java/net/chrisrichardson/ftgo/accountingservice/main/AccountingServiceMain.java"
    click OrderHistSvc "https://github.com/microservices-patterns/ftgo-application/blob/master/ftgo-order-history-service/src/main/java/net/chrisrichardson/ftgo/cqrs/orderhistory/main/OrderHistoryServiceMain.java"
    click Common "https://github.com/microservices-patterns/ftgo-application/blob/master/ftgo-common/src/main/java/net/chrisrichardson/ftgo/common/CommonConfiguration.java"
    click JPA "https://github.com/microservices-patterns/ftgo-application/blob/master/ftgo-common-jpa/src/main/resources/META-INF/orm.xml"
    click SwaggerLib "https://github.com/microservices-patterns/ftgo-application/blob/master/common-swagger/src/main/java/net/chrisrichardson/eventstore/examples/customersandorders/commonswagger/CommonSwaggerConfiguration.java"
    click JSONCodegen "https://github.com/microservices-patterns/ftgo-application/blob/master/buildSrc/src/main/groovy/FtgoJSONSchemaToPojoCodeGen.groovy"

    classDef client fill:#D3D3D3,stroke:#000;
    classDef gateway fill:#DDA0DD,stroke:#000;
    classDef service fill:#ADD8E6,stroke:#000;
    classDef broker fill:#FFA500,stroke:#000;
    classDef db fill:#90EE90,stroke:#000;
    classDef library fill:#FFD700,stroke:#000;
```
