# thykp/esd_team8 architecture

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

- Interactive diagram: https://gitdiagram.com/thykp/esd_team8
- Repository: https://github.com/thykp/esd_team8

## Overview

##### Main Components
- Frontend: A React-based UI built with Vite, TypeScript, Tailwind CSS, and ShadCN UI. It connects to Supabase for authentication.
- Backend: A microservices architecture consisting of “simple” and “complex” services. These services use different languages – Go, JavaScript/TypeScript, and Python – and frameworks like Gin, Express, Hono, FastAPI, and Flask.
- API Gateway: Kong is used to aggregate and manage requests across microservices.
- Message Broker: RabbitMQ is the primary messaging system enabling real-time communication between services.
- Databases/Storage: The project mentions a mix of SQL and NoSQL databases and uses solutions such as Firebase, Google Cloud Storage, and Supabase for storage and data persistence.
- Orchestration & Deployment: Kubernetes YAML files (deployments, services, configmaps, etc.) indicate that microservices are containerized and deployed on a Kubernetes cluster managed partly via Terraform scripts. There are CI/CD pipelines (GitHub Actions, Snyk, Checkov) in place for automated builds and deployments.
- Monitoring and Logging: Use of Prometheus and Grafana for metrics, along with logging utilities in individual services.
- Infrastructure as Code: Terraform configurations manage aspects such as the GKE cluster, storage, load balancers, and versioning.

##### Component Relationships and Interactions
- The frontend application sends user interactions and API calls to the backend via REST or gRPC.
- The Kong API Gateway fronts the backend microservices, handling CORS, rate limiting, and custom authentication.
- Backend microservices (classified as either “simple” or “complex”) handle specific business logic (e.g., ordering, payment, menu management, chat, recommendation) and communicate asynchronously via RabbitMQ.
- The microservices interact with their respective databases and external storage systems.
- CI/CD pipelines automate the building, testing, and deployment of Docker images, which are deployed to Kubernetes (using Kubernetes manifests from the “backend/kubernetes” directory).
- Monitoring data flows from microservices to Prometheus and Grafana, making cluster performance visible.

##### Highlighting Architectural Patterns & Technologies
- Microservices Architecture: The system is modular, with services loosely coupled and dedicated to specific business functions.
- Language/Framework Agnosticism: Different microservices use various technology stacks.
- Containerization and Orchestration: Docker (with docker-compose for local development) and Kubernetes for production deployments.
- Cloud-Native CI/CD: Automated pipelines are in place, including security scanning (Snyk, Checkov).
- Real-time inter-service communication: Implemented via RabbitMQ.
- API Gateway Pattern: Implemented by Kong to centralize API management.

##### Final Suggestions
- Every component is labeled (e.g., “Frontend – React App,” “Backend Service – Order Processing,” “RabbitMQ,” “Kong Gateway”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD & Infrastructure Layer
    CICD["CI/CD Pipeline (GitHub Actions)"]:::infraClass
    Terraform["Terraform (Infrastructure)"]:::infraClass

    %% Frontend Layer
    Frontend["Frontend - React + Vite + Tailwind + Supabase Auth"]:::frontendClass

    %% Kubernetes Cluster (Deployment and Orchestration)
    subgraph "Kubernetes Cluster"
        APIGateway["API Gateway (Kong)"]:::gatewayClass
        subgraph "Backend Microservices - Complex"
            CompleteOrder["Complete Order Service"]:::backendClass
            OrderFood["Order-Food Service"]:::backendClass
            ReccomendFood["Reccomend-Food Service"]:::backendClass
        end
        subgraph "Backend Microservices - Simple"
            ChatGPT["ChatGPT Service"]:::backendClass
            CreditArchive["Credit Service (Archive)"]:::backendClass
            Menu["Menu Service"]:::backendClass
            SimpleOrder["Order Service"]:::backendClass
            Payment["Payment Service"]:::backendClass
            Queue["Queue Service"]:::backendClass
            Reccomendation["Reccomendation Service"]:::backendClass
        end
        SocketIO["Socket.IO Service"]:::backendClass
        RabbitMQ["RabbitMQ"]:::backendClass
        Prometheus["Prometheus"]:::monitoringClass
        Grafana["Grafana"]:::monitoringClass
        %% Dummy node for Kubernetes cluster reference
        K8S["Kubernetes Deployments"]:::infraClass
    end

    %% External / Storage Layer
    DB["Databases/Storage (SQL/NoSQL, Firebase, GCS, Supabase)"]:::externalClass

    %% Connections from CI/CD & Infra to Kubernetes
    CICD --> K8S
    Terraform --> K8S
    CICD --> APIGateway
    Terraform --> APIGateway

    %% Frontend connections
    Frontend -->|"calls"| APIGateway
    Frontend -->|"real-time"| SocketIO

    %% API Gateway routing to Microservices
    APIGateway -->|"route"| CompleteOrder
    APIGateway -->|"route"| OrderFood
    APIGateway -->|"route"| ReccomendFood
    APIGateway -->|"route"| ChatGPT
    APIGateway -->|"route"| CreditArchive
    APIGateway -->|"route"| Menu
    APIGateway -->|"route"| SimpleOrder
    APIGateway -->|"route"| Payment
    APIGateway -->|"route"| Queue
    APIGateway -->|"route"| Reccomendation

    %% Microservices interacting with Message Broker and Databases
    CompleteOrder -->|"async"| RabbitMQ
    ChatGPT -->|"async"| RabbitMQ

    OrderFood -->|"stores"| DB
    CreditArchive -->|"stores"| DB
    Payment -->|"stores"| DB

    %% Microservices reporting to Monitoring tools
    OrderFood -->|"metrics"| Prometheus
    Menu -->|"metrics"| Grafana
    RabbitMQ -->|"metrics"| Prometheus

    %% Kubernetes Cluster monitoring
    K8S -->|"monitors"| Prometheus
    K8S -->|"monitors"| Grafana

    %% Class Definitions (Styles)
    classDef frontendClass fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backendClass fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef gatewayClass fill:#DDA0DD,stroke:#000,stroke-width:1px;
    classDef infraClass fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef monitoringClass fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef externalClass fill:#F5DEB3,stroke:#000,stroke-width:1px;

    %% Click Events
    click Frontend "https://github.com/thykp/esd_team8/tree/main/frontend/"
    click CompleteOrder "https://github.com/thykp/esd_team8/tree/main/backend/services/complex/complete-order/"
    click OrderFood "https://github.com/thykp/esd_team8/tree/main/backend/services/complex/order-food/"
    click ReccomendFood "https://github.com/thykp/esd_team8/tree/main/backend/services/complex/reccomend-food/"
    click ChatGPT "https://github.com/thykp/esd_team8/tree/main/backend/services/simple/chatgpt/"
    click CreditArchive "https://github.com/thykp/esd_team8/tree/main/backend/services/simple/credit/archive/"
    click Menu "https://github.com/thykp/esd_team8/tree/main/backend/services/simple/menu/"
    click SimpleOrder "https://github.com/thykp/esd_team8/tree/main/backend/services/simple/order/"
    click Payment "https://github.com/thykp/esd_team8/tree/main/backend/services/simple/payment/"
    click Queue "https://github.com/thykp/esd_team8/tree/main/backend/services/simple/queue/"
    click Reccomendation "https://github.com/thykp/esd_team8/tree/main/backend/services/simple/reccomendation/"
    click SocketIO "https://github.com/thykp/esd_team8/tree/main/backend/socket.io/"
    click APIGateway "https://github.com/thykp/esd_team8/tree/main/backend/kong/"
    click RabbitMQ "https://github.com/thykp/esd_team8/tree/main/backend/rabbitmq-setup/"
    click K8S "https://github.com/thykp/esd_team8/tree/main/backend/kubernetes/"
    click Prometheus "https://github.com/thykp/esd_team8/blob/main/backend/monitoring/prometheus.yml"
    click Grafana "https://github.com/thykp/esd_team8/blob/main/backend/kubernetes/deployments/grafana-deployment.yaml"
    click CICD "https://github.com/thykp/esd_team8/tree/main/.github/workflows/"
    click Terraform "https://github.com/thykp/esd_team8/tree/main/terraform/"
```
