# shreyaschakravarthy19/fooddetectionandcalorieestimation architecture

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

- Interactive diagram: https://gitdiagram.com/shreyaschakravarthy19/fooddetectionandcalorieestimation
- Repository: https://github.com/shreyaschakravarthy19/fooddetectionandcalorieestimation

## Overview

##### Main components
- Frontend:
– Located in the Templates directory (HTML files like dashboard.html, index.html, login.html, etc.)
– Uses Jinja2 templating, CSS, and JavaScript for rendering the user interface.
- Backend:
– The core application is within app.py, which serves as the Flask server handling HTTP requests, routing, and API endpoints.
- Machine Learning (ML) Pipeline:
– High-level steps include image preprocessing, food detection/classification (using models like EfficientNet and potentially MobileNetV2), and calorie estimation.
– Although the ML logic details might reside within the app.py code (or linked modules), note that a Jupyter notebook (efficicientnet_model.ipynb) is provided, likely illustrating the training and evaluation of the deep learning model.
- Database Layer:
– SQLite databases found in the instance folder (food_tracking.db and mini_proj.db) store user meal logs and nutritional data.
- External Services and Data:
– Integration with the USDA Nutritional Database (as indicated in the README), which supplies caloric and nutrient values.
- DevOps / Continuous Integration:
– GitHub workflows in the .github/workflows folder indicate CI/CD pipelines for tasks like building/deploying the site with Jekyll.

##### Relationships and interactions
- Users interact with the Frontend, uploading images and receiving visual feedback and dashboard insights.
- The Frontend sends requests to the Backend (Flask) which orchestrates the ML pipeline.
- The ML pipeline processes the image: performing food detection, classification, and calorie estimation, and then sends results back to the Flask server.
- The Backend interacts with the SQLite databases to store/retrieve meal logs and nutritional information.
- In cases where nutritional details are required, the system might call the USDA API to verify or enrich data.
- Automated tests (located in the tests folder) ensure integrity and performance, and CI workflows (in the .github folder) manage continuous deployment and testing.

##### Architectural patterns and design principles
- Model-View-Controller (MVC)-like separation:
– Templates serve as the View, app.py (Flask) as the Controller, and the databases along with ML models serve as the Model.
- Micro-modularity: Even if not explicitly divided into microservices, separating the UI, backend logic, ML inference, and persistence highlights well-defined boundaries.
- Data flow: From image input through ML inference, data storage, and then back as user feedback.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        UI["User Interface (HTML, CSS, JS & Jinja2)"]:::frontend
    end

    %% Backend and Machine Learning
    subgraph "Backend & ML"
        BE["Flask Application (Python/Flask)"]:::backend
        ML["Machine Learning Inference Engine (EfficientNet & Food Detection)"]:::ml
    end

    %% Data & External Services
    subgraph "Data & External Services"
        DB["SQLite Databases (Meal Logs & Nutritional Data)"]:::database
        API["USDA Nutritional Database API"]:::external
    end

    %% DevOps & Testing
    subgraph "DevOps & Testing"
        CI["CI/CD Pipeline (GitHub Workflows)"]:::devops
        TEST["Automated Tests (pytest)"]:::testing
    end

    %% Connections
    UI -->|"upload image & requests"| BE
    BE -->|"process image"| ML
    BE -->|"store/retrieve data"| DB
    BE -->|"fetch nutritional info"| API
    CI -->|"deploy & test"| BE
    TEST -->|"validate functionality"| BE

    %% Click Events
    click UI "https://github.com/shreyaschakravarthy19/fooddetectionandcalorieestimation/tree/main/Templates/"
    click BE "https://github.com/shreyaschakravarthy19/fooddetectionandcalorieestimation/blob/main/app.py"
    click ML "https://github.com/shreyaschakravarthy19/fooddetectionandcalorieestimation/blob/main/efficentnet_model.ipynb"
    click DB "https://github.com/shreyaschakravarthy19/fooddetectionandcalorieestimation/tree/main/instance/"
    click CI "https://github.com/shreyaschakravarthy19/fooddetectionandcalorieestimation/tree/main/.github/workflows/"
    click TEST "https://github.com/shreyaschakravarthy19/fooddetectionandcalorieestimation/tree/main/tests/"

    %% Styles
    classDef frontend fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef backend fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef ml fill:#D5F5E3,stroke:#333,stroke-width:2px;
    classDef database fill:#FADBD8,stroke:#333,stroke-width:2px;
    classDef external fill:#E8DAEF,stroke:#333,stroke-width:2px;
    classDef devops fill:#D6EAF8,stroke:#333,stroke-width:2px;
    classDef testing fill:#F9E79F,stroke:#333,stroke-width:2px;
```
