# ash98ketchum/smartmeal_ai_ architecture

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

- Interactive diagram: https://gitdiagram.com/ash98ketchum/smartmeal_ai_
- Repository: https://github.com/ash98ketchum/smartmeal_ai_

## Overview

##### Project Type and Purpose
- SmartMeal AI is a full-stack web application that connects restaurants (surplus food providers) with NGOs (food recipients).
- Frontend: React + Vite + TypeScript, Tailwind CSS, Framer Motion.
- Backend: Node.js + Express.js monolith with REST API, Prisma ORM (SQLite), and an AI component (Python training script + model.pkl).

##### File Structure
- Top level: `frontend/` and `backend/` directories.
- `frontend/`: Vite project, `src/` with pages (public, authentication, restaurant, NGO), layouts, components, assets, configuration files (Tailwind, tsconfig, vite.config).
- `backend/`: Node/Express entrypoint (`server.cjs`), `data/` folder (JSON files + model.pkl), Python script (`train_model.py`), Prisma setup (`schema.prisma`, `migrations`, dev SQLite DB), standard `package.json`.
- No microservices—single backend monolith with clear separation of API, data persistence, and ML training.

##### README for Additional Insights
- RESTful endpoints for servings, events, archive, history.
- JWT-based authentication planned (stubbed).
- AI prediction endpoint triggered via “Recalibration” button.
- Hosting notes: front and back run in same origin or proxied.

- Client-Side Browser (React App)
- Public Pages
- Authentication UI
- Restaurant & NGO Dashboards
- API Server (Node.js + Express)
- Routing Layer (REST controllers)
- Business Logic Layer (services: servings, events, requests, feedback)
- ML Service (invokes `train_model.py`, loads `model.pkl`)
- Auth Middleware (JWT stub)
- Data Layer
- Prisma ORM Client
- SQLite Database (dev.db) + JSON data files (seed/dev)
- External/Hosting
- (Optional) Deployment Platforms: Vercel/Netlify for front, Heroku/Docker for back

b. Relationships & Interactions
- Browser → HTTP (Axios) → REST API endpoints
- API Server → Prisma → SQLite (CRUD)
- “Recalibration” HTTP request → ML Service → Python script → updates model.pkl / predictions JSON → served back to client
- Data flows: restaurant uploads → API → DB → client dashboards; NGO requests → API → DB → notifications (future)

c. Architectural Patterns & Design Principles
- Monolithic backend with layered architecture (Router → Service → Data Access)
- Frontend adheres to component-based UI with layout shells, route guards (`PrivateRoute`), and atomic UI components (Buttons, Cards).
- Separation of concerns: UI, API, persistence, ML.
- RESTful design, future JWT auth.

d. Key Technologies & Frameworks
- Frontend: React, Vite, TypeScript, React Router v6, Tailwind CSS, Framer Motion, Axios
- Backend: Node.js, Express.js, Prisma ORM, SQLite, Python (scikit-learn or similar) for ML model
- Dev tooling: ESLint, PostCSS, tsconfig, Prisma Studio

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Client-Side Browser (React App)"]:::ui
        PublicPages["Public Pages"]:::ui
        AuthPages["Authentication UI"]:::ui
        PrivateRoute["Route Guard (PrivateRoute)"]:::ui
        RestaurantPage["Restaurant Dashboard UI"]:::ui
        NGODashboard["NGO Dashboard UI"]:::ui
        SharedLayouts["Shared Layouts"]:::ui
        AtomicUI["Atomic/UI Components"]:::ui
        CommonUI["Common UI Components"]:::ui
        FrontendConfig["Frontend Configuration"]:::ui
    end

    %% Server Layer
    subgraph "Server Layer"
        direction TB
        Express["Express Server"]:::api
        Routers["Routing & Controllers"]:::api
        Services["Business Logic / Services"]:::api
        AuthMw["Auth Middleware (JWT Stub)"]:::api
        subgraph "ML Service"
            direction TB
            Train["train_model.py"]:::ml
            Model["model.pkl"]:::ml
            Predicted["predicted.json"]:::ml
        end
        subgraph "Data Layer"
            direction TB
            PrismaClient["Prisma Client"]:::data
            SchemaPrisma["schema.prisma"]:::data
            Migrations["migrations"]:::data
            DevDB["dev.db"]:::data
            JSONSeeds["JSON Seed Files"]:::data
        end
    end

    %% Connections
    Browser -->|uses| PublicPages
    Browser -->|uses| AuthPages
    AuthPages -->|protected by| PrivateRoute
    Browser -->|navigates to| RestaurantPage
    Browser -->|navigates to| NGODashboard
    Browser -->|layout from| SharedLayouts
    Browser -->|components from| AtomicUI
    Browser -->|components from| CommonUI
    Browser -->|configurations| FrontendConfig

    Browser -->|HTTP Requests| Express
    Express -->|routes| Routers
    Routers -->|calls| Services
    Services -->|verifies| AuthMw
    Services -->|CRUD operations| PrismaClient
    PrismaClient -->|reads/writes| DevDB
    PrismaClient -->|reads| JSONSeeds

    Routers -->|triggers retraining| Train
    Train -->|outputs| Model
    Services -->|loads| Model
    Services -->|writes predictions| Predicted
    Predicted -->|served to| Browser

    %% Click Events
    click Browser "https://github.com/ash98ketchum/smartmeal_ai_/tree/main/frontend/"
    click PublicPages "https://github.com/ash98ketchum/smartmeal_ai_/tree/main/frontend/src/pages/public/"
    click AuthPages "https://github.com/ash98ketchum/smartmeal_ai_/tree/main/frontend/src/pages/authentication/"
    click PrivateRoute "https://github.com/ash98ketchum/smartmeal_ai_/blob/main/frontend/src/components/auth/PrivateRoute.tsx"
    click RestaurantPage "https://github.com/ash98ketchum/smartmeal_ai_/blob/main/frontend/src/pages/restaurant/Dashboard.tsx"
    click AtomicUI "https://github.com/ash98ketchum/smartmeal_ai_/tree/main/frontend/src/components/ui/"
    click CommonUI "https://github.com/ash98ketchum/smartmeal_ai_/tree/main/frontend/src/components/common/"
    click SharedLayouts "https://github.com/ash98ketchum/smartmeal_ai_/tree/main/frontend/src/layouts/"
    click FrontendConfig "https://github.com/ash98ketchum/smartmeal_ai_/blob/main/frontend/vite.config.ts"
    click Express "https://github.com/ash98ketchum/smartmeal_ai_/blob/main/backend/server.cjs"
    click Routers "https://github.com/ash98ketchum/smartmeal_ai_/blob/main/backend/server.cjs"
    click Train "https://github.com/ash98ketchum/smartmeal_ai_/blob/main/backend/train_model.py"
    click Model "https://github.com/ash98ketchum/smartmeal_ai_/blob/main/backend/data/model.pkl"
    click Predicted "https://github.com/ash98ketchum/smartmeal_ai_/blob/main/backend/data/predicted.json"
    click PrismaClient "https://github.com/ash98ketchum/smartmeal_ai_/blob/main/backend/prisma/client.ts"
    click SchemaPrisma "https://github.com/ash98ketchum/smartmeal_ai_/blob/main/backend/prisma/schema.prisma"
    click Migrations "https://github.com/ash98ketchum/smartmeal_ai_/tree/main/backend/prisma/migrations/"
    click DevDB "https://github.com/ash98ketchum/smartmeal_ai_/blob/main/backend/prisma/dev.db"
    click JSONSeeds "https://github.com/ash98ketchum/smartmeal_ai_/tree/main/backend/data/"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#007ACC,color:#000
    classDef api fill:#DFF7D8,stroke:#28A745,color:#000
    classDef data fill:#FFE5B4,stroke:#FF8C00,color:#000
    classDef ml fill:#EAD7FF,stroke:#800080,color:#000
```
