# hungngodev/flavorie architecture

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

- Interactive diagram: https://gitdiagram.com/hungngodev/flavorie
- Repository: https://github.com/hungngodev/flavorie

## Overview

##### Main Components
- Back-end API Server: Represent the Node.js/Express application which houses controllers, routes, middleware, models, and services for handling business logic (e.g., authentication, receipt scanning, ingredient management, meal suggestions and notifications). Label it “Backend API (Node.js/Express)” and note its connection to databases and external integrations.
- Peer Service: Represent the “peerjs” service that handles peer-to-peer communications for live video or WebRTC connections (possibly for the live cooking room feature). Label it “Peer Service (Peer.js)”.
- Database & Cache: Include external data stores like “MongoDB” (for storing users, recipes, posts, notifications, etc.), “Redis” (for caching and fast data retrieval), and “Cloudinary” (for media storage). Also show external API integrations with providers such as Spoonacular, ThemealDB, Unsplash, and Instacart.

##### Establish Relationships & Data Flows
- The Client to the Backend API for standard HTTP/REST API requests (authentication, fetching/updating ingredient data, posting to the community board).
- The Client to the Peer Service (or through the Backend) to illustrate the live chat and video calling features.
- Backend to external databases like MongoDB for persistent storage, and to Redis for caching.
- Backend to external cloud services (Cloudinary for image storage; third-party APIs: Spoonacular, ThemealDB, Unsplash) indicating data retrieval or update flows.
- Interactions with real-time channels (using Socket.io) between the Client and Backend for notifications and chat messages.

##### Architectural Patterns
- Separation of concerns: Show clear separations between the UI layer (client), business logic (backend), and communication layer (real-time/socket and peer-to-peer services).
- Modular design: The file tree indicates well‐segregated directories (controllers, models, routes, services) which maps to a layered architecture.
- Microservices architecture (if applicable): The presence of separate microservice directories and integration with external APIs should be illustrated.
- Containerization & Deployment: Note that Dockerfiles, docker-compose, and Nginx configurations indicate containerized deployment in AWS EC2 alongside CI/CD pipelines (Github Actions). Represent these as “Infrastructure / Deployment” elements (e.g., Docker container, Nginx reverse proxy, AWS EC2).

##### Final Assembly & Detail
- External microservices as smaller nodes outside the main backend that connect for specialized tasks like receipt scanning, ingredient seeding, and social media interactions.
- Finally, illustrate the deployment stack by placing Docker, Nginx, AWS, and CI/CD as the foundation or overlay for the entire system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Client("Client (React)"):::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        Backend("Backend API (Express)"):::backend
        Socket("Socket.io Service"):::realtime
        Cloudinary("Cloudinary"):::external
        Puppeteer("Puppeteer Microservice"):::micro
        Seeding("Seeding Microservices"):::micro
        Spoonacular("Spoonacular API Integration"):::external
        ThemealDB("ThemealDB API Integration"):::external
        MongoDB("MongoDB"):::external
        Redis("Redis"):::external
        ExternalAPIs("External APIs (Unsplash,Instacart)"):::external
        Celery("Celery/Python Service"):::micro
    end

    %% Peer and Real-time Communication
    subgraph "Peer and Real-time"
        Peer("Peer Service (Peer.js)"):::realtime
    end

    %% Infrastructure / Deployment
    subgraph "Infrastructure / Deployment"
        Deployment("Infrastructure/Deployment"):::infrastructure
    end

    %% Connections between layers
    Client -->|"REST_API_Calls"| Backend
    Client -->|"RealTime_Messages"| Socket
    Client -->|"Live_Chat/Video"| Peer

    Backend -->|"Data_Persistence"| MongoDB
    Backend -->|"Caching"| Redis
    Backend -->|"Image_Uploads"| Cloudinary
    Backend -->|"Scraping_Request"| Puppeteer
    Backend -->|"Seeding_Request"| Seeding
    Backend -->|"Async_Tasks"| Celery
    Backend -->|"Recipe_Data"| Spoonacular
    Backend -->|"Meal_Data"| ThemealDB
    Backend -->|"External_Data"| ExternalAPIs
    Backend -->|"RealTime_Updates"| Socket

    %% Deployment connectivity
    Deployment ---|"Hosts"| Client
    Deployment ---|"Hosts"| Backend
    Deployment ---|"Hosts"| Peer

    %% Click Events
    click Client "https://github.com/hungngodev/flavorie/tree/main/client/"
    click Backend "https://github.com/hungngodev/flavorie/tree/main/backend/"
    click Peer "https://github.com/hungngodev/flavorie/tree/main/peerjs/"
    click Socket "https://github.com/hungngodev/flavorie/blob/main/backend/src/socketio/socketio.ts"
    click Cloudinary "https://github.com/hungngodev/flavorie/blob/main/backend/src/services/cloudinary/cloudinaryServices.ts"
    click Puppeteer "https://github.com/hungngodev/flavorie/tree/main/backend/src/services/puppeteer/"
    click Seeding "https://github.com/hungngodev/flavorie/tree/main/backend/src/services/seeding/"
    click Spoonacular "https://github.com/hungngodev/flavorie/blob/main/backend/src/services/spoonacular/spoonacularServices.ts"
    click ThemealDB "https://github.com/hungngodev/flavorie/tree/main/backend/src/services/themealdb/"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef realtime fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef micro fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef infrastructure fill:#F0E68C,stroke:#000,stroke-width:2px;
```
