# for-men/fortickets architecture

> Architecture diagram of the GitHub repository for-men/fortickets, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/for-men/fortickets
- Repository: https://github.com/for-men/fortickets

## Overview

##### Main Components
- Service Registry: Include an “Eureka” component that handles dynamic service registration and discovery.
- Business Services:
– Concert Service: Represent the “concert-service” which manages concert data, schedules, stages, and related CRUD operations.
– Order Service: Represent the “order-service” responsible for booking, payment processes, messaging (consuming/producing Kafka messages), and order scheduling.
– User Service: Represent the “user-service” which handles user registration, login, authentication, and profile management.
- Shared Components:
– Common Component: Include “component/common” which holds common exception handling, security configurations, and utility classes for all services.
– Redis Component: Include “component/redis” which handles caching and possibly session management.
- Messaging Infrastructure:
– Kafka Cluster: Show Kafka (with producers and consumers) which the gateway and order service use for asynchronous processing and request queuing.
- Databases & External Infra:
– Database: Optionally indicate PostgreSQL as the primary data store (even if not explicitly in the file tree, it’s mentioned in the README).
– Monitoring and Logging: Include external monitoring tools like Prometheus, Grafana, and tracing with Zipkin as part of the infra.
– CI/CD & Containerization: Note that Docker (with Dockerfiles and docker-compose scripts) is heavily used and that GitHub Actions and AWS components (ECR, EC2) are part of the deployment pipeline.

##### Relationships and Interactions
- How the Gateway receives all client requests and first performs authentication (JWT) before forwarding the request to the appropriate business service.
- Caching and shared services (Redis, common components) as either side-notes or as modules embedded within each service that require caching and common functionality.

##### Important Architectural Patterns and Design Principles
- Microservices Pattern: Emphasize the distributed nature and separate deployment of business services.
- API Gateway Pattern: Clearly show the central role of the gateway in handling authentication, request filtering, and routing.
- Asynchronous Messaging: Illustrate the decoupling provided by Kafka and the use of queuing to handle high-load use cases.
- Centralized Service Discovery: Use Eureka as the system’s registry to dynamically manage service endpoints.
- Separation of Concerns: From the distinct packages (application, domain, infrastructure, presentation) in each service, highlight that each layer has its own responsibilities.
- Containerization & CI/CD: Note that Docker, along with orchestration via docker-compose, builds the infrastructure for automated testing and deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client / External Requests
    subgraph "Client / External Requests"
        Client("Client (Web/Mobile)"):::external
    end

    %% API Gateway Layer
    subgraph "API Gateway Layer"
        Gateway("API Gateway (JWT, PreFilter, PostFilter, KafkaFilter)"):::microservice
    end

    %% Business Services
    subgraph "Business Services"
        Concert("Concert Service"):::microservice
        Order("Order Service"):::microservice
        User("User Service"):::microservice
    end

    %% Shared Components
    subgraph "Shared Components"
        Common("Common Component"):::shared
        Redis("Redis Component"):::shared
    end

    %% Service Discovery
    subgraph "Service Discovery"
        Eureka("Eureka Service Registry"):::infrastructure
    end

    %% Messaging Infrastructure
    subgraph "Messaging Infrastructure"
        KafkaGW("Kafka Gateway Messaging"):::messaging
        KafkaOrder("Kafka Order Messaging"):::messaging
    end

    %% External Infrastructure
    subgraph "External Infrastructure"
        DB("PostgreSQL Database"):::infrastructure
        Monitoring("Monitoring & Logging (Prometheus, Grafana, Zipkin)"):::infrastructure
        CI("CI/CD & Containerization (Docker,GitHubActions,AWS)"):::ci
        Gatling("Load Testing (Gatling)"):::external
    end

    %% Connections: Client to Gateway
    Client -->|"request_routing"| Gateway

    %% API Gateway to Business Services
    Gateway -->|"concert_request"| Concert
    Gateway -->|"order_operations"| Order
    Gateway -->|"user_authentication"| User

    %% API Gateway to Messaging (Kafka) from Gateway side
    Gateway -->|"async_messaging"| KafkaGW

    %% Order Service to Messaging (Kafka) from Order side
    Order -->|"async_messaging"| KafkaOrder

    %% Service Discovery connections
    Gateway -->|"service_discovery"| Eureka
    Concert -->|"service_discovery"| Eureka
    Order -->|"service_discovery"| Eureka
    User -->|"service_discovery"| Eureka

    %% Shared Components connections for each Business Service
    Concert -->|"shared_utilities"| Common
    Concert -->|"caching_lookup"| Redis
    Order -->|"shared_utilities"| Common
    Order -->|"caching_lookup"| Redis
    User -->|"shared_utilities"| Common
    User -->|"caching_lookup"| Redis

    %% Inter-service communication from Order Service
    Order -->|"rest_call_concert"| Concert
    Order -->|"rest_call_user"| User

    %% Database connections from Business Services
    Concert -->|"db_rw"| DB
    Order -->|"db_rw"| DB
    User -->|"db_rw"| DB

    %% Monitoring connections
    Gateway -->|"monitoring"| Monitoring
    Concert -->|"monitoring"| Monitoring
    Order -->|"monitoring"| Monitoring
    User -->|"monitoring"| Monitoring
    Eureka -->|"monitoring"| Monitoring

    %% CI/CD / Deployment connections
    Gateway -->|"deployment"| CI
    Concert -->|"deployment"| CI
    Order -->|"deployment"| CI
    User -->|"deployment"| CI
    Eureka -->|"deployment"| CI

    %% Load Testing connection
    Gatling -->|"load_testing"| Gateway

    %% Style Definitions
    classDef microservice fill:#b3e5fc,stroke:#0277bd,stroke-width:2px;
    classDef infrastructure fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef external fill:#ffe082,stroke:#ff8f00,stroke-width:2px;
    classDef shared fill:#d1c4e9,stroke:#512da8,stroke-width:2px;
    classDef messaging fill:#ef9a9a,stroke:#c62828,stroke-width:2px;
    classDef ci fill:#f0f4c3,stroke:#afb42b,stroke-width:2px;

    %% Click Events
    click Eureka "https://github.com/for-men/fortickets/tree/main/application/eureka"
    click Gateway "https://github.com/for-men/fortickets/tree/main/application/gateway-service"
    click Concert "https://github.com/for-men/fortickets/tree/main/application/concert-service"
    click Order "https://github.com/for-men/fortickets/tree/main/application/order-service"
    click User "https://github.com/for-men/fortickets/tree/main/application/user-service"
    click Common "https://github.com/for-men/fortickets/tree/main/component/common"
    click Redis "https://github.com/for-men/fortickets/tree/main/component/redis"
    click KafkaGW "https://github.com/for-men/fortickets/tree/main/application/gateway-service/src/main/java/com/fortickets/gatewayservice/kafka"
    click KafkaOrder "https://github.com/for-men/fortickets/tree/main/application/order-service/src/main/java/com/fortickets/orderservice/infrastructure/messaging"
```
