# maxime1992/pizza-sync architecture

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

- Interactive diagram: https://gitdiagram.com/maxime1992/pizza-sync
- Repository: https://github.com/maxime1992/pizza-sync

## Overview

##### Main System Components
- Frontend Application:
- Built in Angular.
- Organized into multiple modules and features such as “pizzas,” “orders,” “countdown,” “providers,” “identification-dialog,” etc.
- Uses NgRx for state management (actions, reducers, effects) to handle pizzas, orders, ingredients, and UI state.
- Connects to backend via RESTful endpoints and socket.io for real-time updates.

- Backend Server:
- Implemented using Node.js with NestJS.
- Contains various controllers and modules for handling command-line operations and managing features (models for pizzas, orders, ingredients, users, etc.).
- Implements real-time communications via socket.io.
- Offers command-line commands (e.g., countdown updates, provider management) through its interactive prompt.
- Contains utility/helper modules for common operations (file, HTTP, normalization, etc.).

- Data Flow & Communication:
- The frontend sends HTTP requests to the backend API and interacts over WebSockets for real-time data (e.g., live order updates, countdown changes).
- The command-line utility on the backend feeds data or configurations into the system that then propagate in real time to the frontend.

- Docker / Deployment Environment:
- API service container (built from Dockerfile.api) running the backend server.
- NGINX container (built from Dockerfile.nginx) serving the Angular static assets and forwarding HTTP + WebSocket connections.
- A docker-compose configuration ties these containers together with proper linking and port forwarding.

##### Architectural Relationships and Interactions
- Frontend (Angular) and backend (NestJS) as separate but connected components.
- HTTP REST calls: frontend → backend.
- WebSocket communication: bidirectional between frontend and backend.
- Command-line interactions: admin command input on the backend that triggers state changes and is propagated to the frontend.
- Within the backend, display internal modularity (e.g., “features” for pizzas, orders, and users) as smaller blocks under a larger "Backend" component.
- For the frontend, indicate separation between core/shared modules, feature modules (like pizzas, orders, countdown), and state management libraries (NgRx store, effects, etc.).

##### Architectural Patterns & Design Principles
- Separation of concerns between frontend (UI, state management, Angular components) and backend (API, WebSocket, business logic, command-line interface).
- Real-time updates using socket.io as a key integration point.
- How Docker is used as a containerization and deployment strategy with separate containers for API (backend) and a static file server/caching proxy (NGINX) for the frontend.

- A “Frontend” block that is further decomposed into:
- Core & Shared Modules.
- Feature Modules (Pizzas, Orders, Countdown, etc.).
- State Management (NgRx Store, Actions & Effects).
- A “Backend” block that is subdivided into:
- API Layer (HTTP endpoints).
- WebSocket Service (real-time updates).
- Command-Line Interface (interactive admin commands like countdown settings).
- Business Logic/Modules (Models for pizzas, orders, ingredients, users, etc.).
- Helper Utilities.
- An “External Services” or “Pizza Providers” block that illustrates the backend’s task of parsing external provider websites.
- API Container (Dockerfile.api).
- NGINX Container (Dockerfile.nginx) acting as a static file server and reverse proxy.
- A “Docker Compose” element which coordinates both containers and their network links.

##### Final Assembly
- On a separate section “Deployment”, include the “Docker Compose” with nodes for API Container and NGINX Container and show how the NGINX container connects to the API container.

## Diagram (Mermaid)

```mermaid
graph TD
  subgraph "Pizza-Sync System"
    %% Frontend Section
    subgraph "Frontend (Angular App)"
      direction TB
      FE["Frontend App (Angular)"]:::frontend
      FE_Pizzas["Pizzas Module"]:::frontend
      FE_Orders["Orders Module"]:::frontend
      FE_Countdown["Countdown Module"]:::frontend
      FE_ID["Identification Dialog"]:::frontend
      FE_NgRx["NgRx State Management"]:::frontend
    end

    %% Backend Section
    subgraph "Backend (NestJS API + CLI)"
      direction TB
      BE["Backend Server (NestJS)"]:::backend
      %% API Layer
      subgraph "API Layer"
        direction TB
        BE_API["API Controller"]:::backend
        BE_Socket["Real-time Updates (Socket.io)"]:::backend
      end
      %% Command-Line Interface
      subgraph "Command-Line Interface"
        direction TB
        BE_CLI["Command-Line Interface"]:::backend
        BE_Countdown["Countdown Command"]:::backend
        BE_Provider1["Provider Command"]:::backend
        BE_Provider2["Provider Command"]:::backend
      end
      %% Models
      subgraph "Models"
        direction TB
        BE_ModelPizzas["Pizzas Module"]:::backend
        BE_ModelOrders["Orders Module"]:::backend
        BE_ModelIngredients["Ingredients Module"]:::backend
        BE_ModelUsers["Users Module"]:::backend
        BE_ModelPizzaCategories["Pizzas-Categories Module"]:::backend
      end
      BE_External["External Pizza Providers"]:::backend
      BE_Helper["Helper Utilities"]:::backend
    end

    %% Deployment Section
    subgraph "Deployment"
      direction TB
      DC["Docker Compose"]:::deployment
      API_Container["API Container"]:::deployment
      NGINX_Container["NGINX Container"]:::deployment
    end
  end

  %% Interactions
  FE -->|"HTTPAPI"| BE_API
  FE ---|"WebSocket"| BE_Socket
  BE_CLI -->|"TriggersUpdates"| FE
  BE_API -->|"ParsesDataFrom"| BE_External
  NGINX_Container -->|"ReverseProxy"| API_Container
  DC --> NGINX_Container
  DC --> API_Container

  %% Click Events
  click FE "https://github.com/maxime1992/pizza-sync/tree/master/frontend/"
  click FE_Pizzas "https://github.com/maxime1992/pizza-sync/tree/master/frontend/src/app/features/pizzas/"
  click FE_Orders "https://github.com/maxime1992/pizza-sync/tree/master/frontend/src/app/features/orders/"
  click FE_Countdown "https://github.com/maxime1992/pizza-sync/tree/master/frontend/src/app/features/countdown/"
  click FE_ID "https://github.com/maxime1992/pizza-sync/tree/master/frontend/src/app/features/identification-dialog/"
  click FE_NgRx "https://github.com/maxime1992/pizza-sync/tree/master/frontend/src/app/shared/states/"
  click BE "https://github.com/maxime1992/pizza-sync/tree/master/backend/src/"
  click BE_API "https://github.com/maxime1992/pizza-sync/blob/master/backend/src/app.controller.ts"
  click BE_CLI "https://github.com/maxime1992/pizza-sync/tree/master/backend/src/command-line/"
  click BE_Countdown "https://github.com/maxime1992/pizza-sync/blob/master/backend/src/command-line/commands/countdown.command.ts"
  click BE_Provider1 "https://github.com/maxime1992/pizza-sync/blob/master/backend/src/command-line/commands/provider.command.ts"
  click BE_Provider2 "https://github.com/maxime1992/pizza-sync/blob/master/backend/src/command-line/commands/providers.command.ts"
  click BE_ModelPizzas "https://github.com/maxime1992/pizza-sync/tree/master/backend/src/features/models/pizzas/"
  click BE_ModelOrders "https://github.com/maxime1992/pizza-sync/tree/master/backend/src/features/models/orders/"
  click BE_ModelIngredients "https://github.com/maxime1992/pizza-sync/tree/master/backend/src/features/models/ingredients/"
  click BE_ModelUsers "https://github.com/maxime1992/pizza-sync/tree/master/backend/src/features/models/users/"
  click BE_ModelPizzaCategories "https://github.com/maxime1992/pizza-sync/tree/master/backend/src/features/models/pizzas-categories/"
  click BE_External "https://github.com/maxime1992/pizza-sync/tree/master/backend/src/features/pizzas-providers/"
  click BE_Helper "https://github.com/maxime1992/pizza-sync/tree/master/backend/src/helpers/"
  click BE_Socket "https://github.com/maxime1992/pizza-sync/blob/master/backend/src/server.ts"
  click API_Container "https://github.com/maxime1992/pizza-sync/blob/master/Dockerfile.api"
  click NGINX_Container "https://github.com/maxime1992/pizza-sync/blob/master/Dockerfile.nginx"
  click NGINX_Container "https://github.com/maxime1992/pizza-sync/blob/master/nginx.conf"
  click DC "https://github.com/maxime1992/pizza-sync/blob/master/docker-compose.yml"

  %% Styles
  classDef frontend fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
  classDef backend fill:#90EE90,stroke:#008000,stroke-width:2px;
  classDef deployment fill:#D3D3D3,stroke:#808080,stroke-width:2px;
```
