# 5004-sea-fa24-geeng/final-project-final-project-8 architecture

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

- Interactive diagram: https://gitdiagram.com/5004-sea-fa24-geeng/final-project-final-project-8
- Repository: https://github.com/5004-sea-fa24-geeng/final-project-final-project-8

## Overview

##### Project type and purpose
- This is a full-stack web application (“Food Wizard”) that lets users pick ingredients to get recipe suggestions.
- Frontend: React + TypeScript + Vite SPA (`food-frontend/`)
- Backend: Java Spring Boot REST API (`src/main/java/com/group8/foodwizard/`)
- No local database—uses TheMealDB external API and a local `ingredients.json` for ingredient metadata.

##### File structure
- Top-level:
- `food-frontend/` (React/Vite app)
- `src/main/java/com/group8/foodwizard/` (Spring Boot code)
- `src/main/resources/static/` (built SPA assets served by Spring Boot)
- `Dockerfile`, `fly.toml` (deployment), `gradlew*` + `gradle/` (build), `data/ingredients.json` (static data)
- `DesignDocuments/`, `Manual/`, `Instructions/` (docs)
- Backend follows MVC:
- Controllers: REST endpoints (`RecipeController.java`)
- Models: domain (`Recipe`, `Ingredient`, `Meal`), request DTOs, strategy sub-packages
- Config: CORS / SPA routing (`SpaWebMvcConfigurer.java`)
- Frontend:
- Pages & Components (custom UI + composable UI library)
- Services call backend APIs
- Store (state management) + models + utility functions

##### Key README insights
- Purpose: reduce food waste by suggesting recipes based on user-selected ingredients
- Tech stack: Spring Boot, React + Vite, TheMealDB API
- Deployment: Docker + Fly.io

##### Main components
a. User (Browser)
b. Frontend SPA
- UI Components
- State Store
- API Service layer
c. Backend REST API
- Controllers (RecipeController)
- Business Logic / Strategy modules
- JSON Parser utility
- Static asset server (serves built SPA)
d. External systems
- TheMealDB API
- Static ingredient data (`ingredients.json`)
e. Build/Deployment (optional)
- Vite build → static assets → Spring Boot’s `resources/static`
- Docker container on Fly.io

##### Relationships & data flow
1. User interacts with SPA in browser
2. SPA calls backend REST endpoints (e.g., `/recipes?ingredients=...`)
3. Backend Controller delegates to Strategy classes
4. Backend calls TheMealDB API (external HTTP) and/or reads `ingredients.json`
5. Backend aggregates/parses JSON into domain models → returns JSON to SPA
6. SPA updates state/store → rerenders UI
7. (On deploy) CI builds frontend (Vite) → copies assets into Spring Boot → Dockerizes application → deploys to Fly

##### Architectural patterns & design principles
- Backend:
- MVC (RestController + Models + Utilities)
- Strategy Pattern for different “get meal” algorithms (`IGetMealStrategy`)
- Single Spring Boot application bundling static SPA assets
- Frontend:
- Component-based UI with custom + shared UI library
- Unidirectional data flow via service calls → state store → view
- Separation of concerns: UI, models, services, store, utils

##### Detail
- Strategy classes as a sub-module under Business Logic.
- Static asset server in Spring Boot (to illustrate integration of frontend build).
- That there’s no traditional database—just external API + local JSON.
- Optionally, annotate the Docker and Fly.io deployment for completeness.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Title
    subgraph "Food Wizard System Architecture"
    end

    %% User
    User["User (Browser)"]:::external

    %% Frontend
    subgraph "Frontend SPA" 
        direction TB
        SPA["React SPA"]:::frontend
        Entry["main.tsx"]:::frontend
        ViteConfig["vite.config.ts"]:::frontend
        subgraph "UI Components"
            direction TB
            CustomComponents["Custom Components"]:::frontend
            SharedUI["Shared UI Library"]:::frontend
        end
        Store["State Store"]:::frontend
        Service["API Service Layer"]:::frontend
        Models["Frontend Models"]:::frontend
    end

    %% Backend
    subgraph "Backend (Spring Boot)" 
        direction TB
        App["FoodwizardApplication.java"]:::backend
        Controller["RecipeController"]:::backend
        subgraph "Business Logic"
            direction TB
            Strategy["Strategy Modules"]:::backend
            DomainModels["Recipe Domain Models"]:::backend
            RequestDTO["RecipeRequest DTO"]:::backend
            ApiUtils["ApiUtils (TheMealDB)"]:::backend
            JsonParser["JsonParser Utility"]:::backend
        end
        Config["SpaWebMvcConfigurer"]:::backend
        StaticAssets["Static Asset Server"]:::backend
        LocalData["Local Ingredient Data"]:::external
    end

    %% External API
    ExternalAPI["TheMealDB API"]:::external

    %% Build & Deploy
    subgraph "Build & Deployment"
        direction TB
        ViteBuild["Vite Build"]:::external
        Docker["Docker & Fly.io"]:::external
    end

    %% Connections
    User -->|"uses UI"| SPA
    SPA -->|"contains"| Entry
    SPA -->|"uses"| ViteConfig
    SPA -->|"renders"| CustomComponents
    SPA -->|"renders"| SharedUI
    SPA -->|"manages"| Store
    SPA -->|"calls"| Service
    SPA -->|"uses data models"| Models

    Service -->|"HTTP/JSON"| Controller
    Controller -->|"delegates to"| Strategy
    Strategy -->|"uses models"| DomainModels
    Strategy -->|"validates via"| RequestDTO
    Strategy -->|"calls"| ApiUtils
    ApiUtils -->|"HTTP/JSON"| ExternalAPI
    Strategy -->|"parses JSON"| JsonParser
    Config -->|"serves SPA assets"| StaticAssets
    StaticAssets -->|"from build"| ViteBuild
    App -->|"entry point"| Controller
    App -->|"configures CORS/SPARouting"| Config
    LocalData -->|"read by"| Strategy

    ViteBuild -->|"outputs to"| StaticAssets
    StaticAssets -->|"bundled in"| App
    App -->|"containerized"| Docker

    %% Click Events
    click SPA "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/tree/main/food-frontend/"
    click CustomComponents "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/tree/main/food-frontend/src/components/custom/"
    click SharedUI "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/tree/main/food-frontend/src/components/ui/"
    click Store "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/blob/main/food-frontend/src/store/ingredientStore.ts"
    click Service "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/blob/main/food-frontend/src/services/ingredientService.ts"
    click Models "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/tree/main/food-frontend/src/models/"
    click Entry "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/blob/main/food-frontend/src/main.tsx"
    click ViteConfig "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/blob/main/food-frontend/vite.config.ts"
    click App "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/blob/main/src/main/java/com/group8/foodwizard/FoodwizardApplication.java"
    click Controller "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/blob/main/src/main/java/com/group8/foodwizard/controllers/RecipeController.java"
    click Strategy "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/tree/main/src/main/java/com/group8/foodwizard/model/recipe/strategy/"
    click DomainModels "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/tree/main/src/main/java/com/group8/foodwizard/model/recipe/"
    click RequestDTO "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/blob/main/src/main/java/com/group8/foodwizard/model/requests/RecipeRequest.java"
    click ApiUtils "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/blob/main/src/main/java/com/group8/foodwizard/model/api/ApiUtils.java"
    click JsonParser "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/blob/main/src/main/java/com/group8/foodwizard/model/formatter/JsonParser.java"
    click Config "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/blob/main/src/main/java/com/group8/foodwizard/config/SpaWebMvcConfigurer.java"
    click StaticAssets "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/tree/main/src/main/resources/static/"
    click LocalData "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/blob/main/data/ingredients.json"
    click Docker "https://github.com/5004-sea-fa24-geeng/final-project-final-project-8/tree/main/Dockerfile"

    %% Styles
    classDef frontend fill:#E3FCEF,stroke:#067D06
    classDef backend fill:#DBEAFE,stroke:#1E40AF
    classDef external fill:#FEF3C7,stroke:#B45309
    class User,ExternalAPI,LocalData,ViteBuild,Docker external
    class SPA,Entry,ViteConfig,CustomComponents,SharedUI,Store,Service,Models frontend
    class App,Controller,Strategy,DomainModels,RequestDTO,ApiUtils,JsonParser,Config,StaticAssets backend
```
