# salamalicun/nutribox architecture

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

- Interactive diagram: https://gitdiagram.com/salamalicun/nutribox
- Repository: https://github.com/salamalicun/nutribox

## Overview

##### Project type and purpose
- This is a monolithic full-stack Single Page Application (SPA) called “Nutribox” for generating personalized diets.
- Backend: Laravel 12.3.0 (PHP 8.2) using an MVC pattern.
- Frontend: React 19.0.0 + TypeScript, styled with Tailwind CSS, routed via Inertia.js (no separate REST API).
- Database: SQLite (local file).
- External integrations: OpenFoodFacts, Deepseek (via PHP client), Pexels.

##### File structure
- Top‐level directories:
- nutribox/ ← application root
- public/ ← static assets and index.php
- resources/js/ ← React components, pages, layouts, hooks
- app/ ← Laravel controllers, middleware, console commands, models
- config/, routes/, database/, storage/, tests/ ← config, routing, migrations/seeders, file storage, automated tests
- .github/workflows/*.yml ← CI/CD (lint, tests, deploy)

##### Key architectural patterns and tech
- Monolith with Inertia.js bridging Laravel controllers ↔ React pages
- Laravel’s MVC on server:
- Models ↔ SQLite database (Eloquent ORM)
- Controllers handle HTTP/Inertia requests, orchestrate Models and return Inertia responses
- Blade template (app.blade.php) bootstraps React SPA
- React SPA: Vite bundler, React components, Inertia client, shadcn/ui + custom TS components
- CI/CD: GitHub Actions runs linting, tests, then deployment to VPS (Apache + PHP).

##### Main components and interactions
A. Client (Browser)
- Inertia.js adapter issues link clicks/Form submissions as XHR
- React Rendering Layer (resources/js)
B. Web Server
- Apache (or PHP-FPM behind Apache)
- Laravel Application
- HTTP Kernel → Middleware → Controllers
- Controllers interact with Models and Services
- Return Inertia responses (JSON + page props)
C. Database
- SQLite file (database/database.sqlite) accessed by Eloquent Models
D. External Services
- OpenFoodFacts API (nutritional data lookup)
- Deepseek API (AI-powered suggestions via deepseek-php-client)
- Pexels API (image sourcing)
E. Static Assets & Build
- Vite builds React app → assets in public/js, public/css
- Tailwind CSS config (tailwind.config.js)
F. CI/CD Pipeline
- GitHub Actions:
1. Lint (eslint, PHP_CodeSniffer)
2. Tests (PHPUnit, Pest, Playwright e2e)
3. Deploy (SSH/FTP to VPS)

- Component names and responsibilities (e.g., MenusController, Comida model)
- Data flows with arrowheads (e.g., “Search product → OpenFoodFacts API → JSON response”)
- Configuration files or build tools (Vite, Composer, NPM scripts) as side annotations
- CI/CD steps linking GitHub repo to production VPS

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline" 
        direction TB
        Lint["Linting"]:::ci
        TestsCI["Testing"]:::ci
        DeployCI["Deployment"]:::ci
    end

    %% Frontend Layer
    subgraph "Browser & Frontend" 
        direction TB
        Browser["Browser (SPA)"]:::frontend
        InertiaClient["Inertia.js Client"]:::frontend
        subgraph "React SPA" 
            direction TB
            AppTSX["app.tsx"]:::frontend
            JSComponents["components & pages"]:::frontend
            LayoutsHooks["layouts & hooks"]:::frontend
            TailwindCSS["app.css (Tailwind CSS)"]:::frontend
        end
        ViteConfig["vite.config.ts"]:::frontend
        TSConfig["tsconfig.json"]:::frontend
    end

    %% Backend Layer
    subgraph "Web Server & Laravel" 
        direction TB
        Apache["Apache + PHP-FPM"]:::backend
        InertiaConfig["inertia.php"]:::backend
        AppBlade["app.blade.php"]:::backend
        HTTPKernel["HTTP Kernel"]:::backend
        MiddlewareDir["Middleware"]:::backend
        ControllersDir["Controllers"]:::backend
        OFFController["OFFController.php"]:::backend
        IAController["IAController.php"]:::backend
        PlayController["PlayController.php"]:::backend
        ModelsDir["Models"]:::backend
        subgraph "Routes" 
            direction TB
            RoutesWeb["web.php"]:::backend
            RoutesAuth["auth.php"]:::backend
            RoutesSettings["settings.php"]:::backend
        end
    end

    %% Database Layer
    subgraph "Database" 
        direction TB
        DBFile["database.sqlite"]:::db
        MigrationsDir["migrations"]:::db
        SeedersDir["seeders"]:::db
        FactoriesDir["factories"]:::db
    end

    %% External Services
    subgraph "External APIs" 
        direction TB
        OFFAPI["OpenFoodFacts API"]:::ext
        DeepseekAPI["Deepseek API"]:::ext
        PexelsAPI["Pexels API"]:::ext
    end

    %% Static Assets
    subgraph "Public Assets" 
        direction TB
        PublicJSCSS["public/js & public/css"]:::frontend
        PublicImg["public/img & public/lottie"]:::frontend
    end

    %% Automated Tests
    subgraph "Automated Tests" 
        direction TB
        TestsDir["tests"]:::ci
        TestsE2E["tests_e2e"]:::ci
    end

    %% Connections
    Lint --> TestsCI
    TestsCI --> DeployCI
    DeployCI -->|deploy| Apache

    Browser -->|"XHR via Inertia"| Apache
    Apache --> HTTPKernel
    HTTPKernel --> MiddlewareDir
    MiddlewareDir --> ControllersDir
    ControllersDir --> ModelsDir
    ControllersDir --> OFFAPI
    ControllersDir --> DeepseekAPI
    ControllersDir --> PexelsAPI
    ControllersDir --> DBFile
    ControllersDir --> MigrationsDir
    ControllersDir --> SeedersDir
    ControllersDir --> FactoriesDir
    ControllersDir -->|returns Inertia response| InertiaClient
    AppBlade --> AppTSX
    AppBlade --> PublicJSCSS
    AppTSX --> JSComponents
    AppTSX --> LayoutsHooks
    AppTSX --> TailwindCSS
    AppTSX --> ViteConfig
    AppTSX --> TSConfig
    PublicJSCSS --> Browser

    %% Click Events
    click AppTSX "https://github.com/salamalicun/nutribox/blob/main/nutribox/resources/js/app.tsx"
    click AppBlade "https://github.com/salamalicun/nutribox/blob/main/nutribox/resources/views/app.blade.php"
    click InertiaConfig "https://github.com/salamalicun/nutribox/blob/main/nutribox/config/inertia.php"
    click JSComponents "https://github.com/salamalicun/nutribox/tree/main/nutribox/resources/js/components"
    click JSComponents "https://github.com/salamalicun/nutribox/tree/main/nutribox/resources/js/pages"
    click LayoutsHooks "https://github.com/salamalicun/nutribox/tree/main/nutribox/resources/js/layouts"
    click LayoutsHooks "https://github.com/salamalicun/nutribox/tree/main/nutribox/resources/js/hooks"
    click ViteConfig "https://github.com/salamalicun/nutribox/blob/main/nutribox/vite.config.ts"
    click TSConfig "https://github.com/salamalicun/nutribox/blob/main/nutribox/tsconfig.json"
    click TailwindCSS "https://github.com/salamalicun/nutribox/blob/main/nutribox/resources/css/app.css"
    click ControllersDir "https://github.com/salamalicun/nutribox/tree/main/nutribox/app/Http/Controllers"
    click OFFController "https://github.com/salamalicun/nutribox/blob/main/nutribox/app/Http/Controllers/OFFController.php"
    click IAController "https://github.com/salamalicun/nutribox/blob/main/nutribox/app/Http/Controllers/IAController.php"
    click PlayController "https://github.com/salamalicun/nutribox/blob/main/nutribox/app/Http/Controllers/PlayController.php"
    click MiddlewareDir "https://github.com/salamalicun/nutribox/tree/main/nutribox/app/Http/Middleware"
    click ModelsDir "https://github.com/salamalicun/nutribox/tree/main/nutribox/app/Models"
    click RoutesWeb "https://github.com/salamalicun/nutribox/blob/main/nutribox/routes/web.php"
    click RoutesAuth "https://github.com/salamalicun/nutribox/blob/main/nutribox/routes/auth.php"
    click RoutesSettings "https://github.com/salamalicun/nutribox/blob/main/nutribox/routes/settings.php"
    click DBFile "https://github.com/salamalicun/nutribox/blob/main/nutribox/database/database.sqlite"
    click MigrationsDir "https://github.com/salamalicun/nutribox/tree/main/nutribox/database/migrations"
    click SeedersDir "https://github.com/salamalicun/nutribox/tree/main/nutribox/database/seeders"
    click FactoriesDir "https://github.com/salamalicun/nutribox/tree/main/nutribox/database/factories"
    click PublicJSCSS "https://github.com/salamalicun/nutribox/tree/main/nutribox/public/js"
    click PublicJSCSS "https://github.com/salamalicun/nutribox/tree/main/nutribox/public/css"
    click PublicImg "https://github.com/salamalicun/nutribox/tree/main/nutribox/public/img"
    click PublicImg "https://github.com/salamalicun/nutribox/tree/main/nutribox/public/lottie"
    click Lint "https://github.com/salamalicun/nutribox/blob/main/nutribox/.github/workflows/lint.yml"
    click TestsCI "https://github.com/salamalicun/nutribox/blob/main/nutribox/.github/workflows/tests.yml"
    click DeployCI "https://github.com/salamalicun/nutribox/blob/main/nutribox/.github/workflows/deploy.yml"
    click TestsDir "https://github.com/salamalicun/nutribox/tree/main/nutribox/tests"
    click TestsE2E "https://github.com/salamalicun/nutribox/tree/main/nutribox/tests_e2e"

    %% Styles
    classDef frontend fill:#a2f5a2,stroke:#333,stroke-width:1px
    classDef backend fill:#a2c4f5,stroke:#333,stroke-width:1px
    classDef db fill:#f5d78e,stroke:#333,stroke-width:1px
    classDef ext fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef ci fill:#dcb3ff,stroke:#333,stroke-width:1px
```
