# castro-1/stadium-delivery architecture

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

- Interactive diagram: https://gitdiagram.com/castro-1/stadium-delivery
- Repository: https://github.com/castro-1/stadium-delivery

## Overview

##### Main Components
- Frontend: Built with React (noted by client-app and restaurant-admin directories) that interacts with users using Material-UI.
- Microservices:
- Inventory Service: Handles product catalog management (examined in inventory-service – controllers, models, routes).
- Order Service: Manages order creation, validation, and stock updating (order-service – controllers, models, routes, Kafka producer usage).
- Notification Service: Sends real-time notifications to users (notification-service – Socket.io integration, Kafka consumer).
- Databases:
- MongoDB: Used for inventory and notifications.
- PostgreSQL: Used by the order service.
- External Communication & Tools:
- Kafka: Enables asynchronous communication between services.
- REST APIs: For frontend-microservice and inter-service communication.
- Docker & Kubernetes: For containerizing and orchestrating the services (see docker-compose.yml, Minikube deployment scripts, and k8s-new configuration files).

##### Component Relationships and Interactions
- User Interaction Flow:
- The user interacts with the frontend application.
- The frontend makes GET requests to the inventory service to display available products.
- When an order is placed, the frontend sends a POST request to the order service.
- Backend Processing Flow:
- The order service validates the order and queries or updates the inventory service accordingly.
- After order creation, the order service publishes a “pedido creado” (order created) event to Kafka.
- The notification service listens to Kafka; upon receiving an event, it creates and dispatches a notification using Socket.io.
- Data Persistence:
- MongoDB stores inventory and notification data.
- PostgreSQL is utilized by the order service to persist order details.

##### Architectural Patterns and Principles
- Microservices Architecture:
- Different services are narrowly focused on specific domains (inventory, order, notifications).
- Containerization & Orchestration:
- Each service is containerized with a Dockerfile and deployed using Kubernetes configurations.
- Event-driven Communication:
- Kafka is utilized to decouple services and enable asynchronous event-driven processing.
- API-based Communication:
- Services interact via RESTful endpoints, ensuring loose coupling.

##### Relevant Technologies, Frameworks, and Tools
- Frontend Technologies:
- React, Vite, Tailwind CSS alongside Material-UI (mentioned within README).
- Backend Technologies:
- Node.js with Express framework, with each microservice implementing its own set of controllers, models, and routes.
- Deployment & Infrastructure:
- Docker (for containerization)
- Kubernetes and Minikube (for orchestration)
- YAML files to describe deployments (in the k8s-new folder).

##### Additional Details
- Containers and orchestration elements:
- Docker images and Kubernetes clusters to emphasize containerization.
- Optionally, include configuration files like docker-compose and Minikube deployment scripts to note how the system is deployed.
- Utility scripts (like seed-data.js) as part of the startup or initialization flow for inventory data.
- Any integration with external systems (if applicable) should be labeled, though the primary interactions here remain internal.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interaction
    User("User"):::user

    %% Frontend Layer
    subgraph "Frontend Layer"
        ClientApp("Client App (React)"):::frontend
        RestaurantAdmin("Restaurant Admin (React)"):::frontend
    end

    %% Backend Microservices
    subgraph "Backend Microservices"
        Inventory("Inventory Service (Node/Express)"):::backend
        Order("Order Service (Node/Express & Kafka Producer)"):::backend
        Notification("Notification Service (Node/Express, Kafka Consumer & Socket.io)"):::backend
    end

    %% Messaging System
    Kafka("Kafka Broker"):::messaging

    %% Databases
    subgraph "Databases"
        MongoDB("MongoDB"):::database
        PostgreSQL("PostgreSQL"):::database
    end

    %% Containerization & Orchestration
    subgraph "Containerization & Orchestration"
        Docker("Docker"):::deployment
        DockerCompose("docker-compose.yml"):::deployment
        Kubernetes("Kubernetes (Minikube & k8s-new)"):::deployment
    end

    %% User to Frontend
    User -->|"interacts"| ClientApp
    User -->|"interacts"| RestaurantAdmin

    %% Frontend to Microservices via REST
    ClientApp -->|"GET/products"| Inventory
    ClientApp -->|"POST/order"| Order

    %% Internal Microservices Communications
    Order -->|"update/check_stock"| Inventory
    Order -->|"publish_order_event"| Kafka
    Kafka -->|"deliver_event"| Notification
    Notification -->|"push_notification(Socket.io)"| ClientApp

    %% Data Persistence
    Inventory -->|"CRUD operations"| MongoDB
    Notification -->|"CRUD operations"| MongoDB
    Order -->|"SQL operations"| PostgreSQL

    %% Containerization connections (all components are containerized)
    ClientApp -->|"containerized"| Docker
    RestaurantAdmin -->|"containerized"| Docker
    Inventory -->|"containerized"| Docker
    Order -->|"containerized"| Docker
    Notification -->|"containerized"| Docker
    Docker -->|"managed_by"| DockerCompose
    DockerCompose -->|"orchestrated_by"| Kubernetes

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#1F78B4,stroke-width:2px;
    classDef backend fill:#C1F7C1,stroke:#388E3C,stroke-width:2px;
    classDef database fill:#F7C1F7,stroke:#D81B60,stroke-width:2px;
    classDef messaging fill:#FFF7A3,stroke:#F9A825,stroke-width:2px;
    classDef deployment fill:#C1F7F0,stroke:#00796B,stroke-width:2px;
    classDef user fill:#FFE0B2,stroke:#F57C00,stroke-width:2px;

    %% Click Events for Component Mapping
    click ClientApp "https://github.com/castro-1/stadium-delivery/blob/main/client-app/src/App.jsx"
    click RestaurantAdmin "https://github.com/castro-1/stadium-delivery/blob/main/restaurant-admin/src/App.jsx"
    click Inventory "https://github.com/castro-1/stadium-delivery/blob/main/inventory-service/controllers/productController.js"
    click Order "https://github.com/castro-1/stadium-delivery/blob/main/order-service/controllers/orderController.js"
    click Notification "https://github.com/castro-1/stadium-delivery/blob/main/notification-service/controllers/notificationController.js"
    click MongoDB "https://github.com/castro-1/stadium-delivery/blob/main/k8s-new/03-mongodb.yaml"
    click PostgreSQL "https://github.com/castro-1/stadium-delivery/blob/main/k8s-new/04-postgres.yaml"
    click Kafka "https://github.com/castro-1/stadium-delivery/blob/main/k8s-new/05-kafka.yaml"
    click DockerCompose "https://github.com/castro-1/stadium-delivery/blob/main/docker-compose.yml"
    click Kubernetes "https://github.com/castro-1/stadium-delivery/blob/main/k8s-new/06-inventory-service.yaml"
```
