# furiousfoe/farmwise architecture

> Architecture diagram of the GitHub repository furiousfoe/farmwise, 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/furiousfoe/farmwise
- Repository: https://github.com/furiousfoe/farmwise

## Overview

##### Main Components
- Data Management & Dataset Storage:
- The “Cotton Disease” directory contains sub-folders (train, test, val) with labeled images of diseased and fresh cotton plants/leaves. This represents the raw input data used for training, validation, and testing the ML model.
- The “uploads” directory includes ML scripts, a pre-trained model (including the H5 file and Jupyter Notebook), and potentially user-uploaded images.
- Machine Learning Module:
- This includes the machine learning script (ml_script.py) and the ResNet-based model saved under uploads/model. This component is responsible for image preprocessing (using OpenCV as per the README) and prediction.
- Backend (Web Application):
- The “src” folder with files like config.js and index.js indicates a Node.js/Express backend.
- User authentication, integration with the ML module (for inference on uploaded images), and possibly interfacing with both SQL and Google Cloud for data storage.
- Frontend (Web Views):
- The “views” folder (with EJS templates for pages like home, landing-page, login, signup, upload, and result) forms the presentation layer for the web application.
- The “public” folder (containing stylesheets and images) supports the frontend with static assets.
- Mobile Application:
- Database / External Services:
- As described in the README, this project uses SQL and Google Cloud for user data and result storage. This should be represented as a persistent storage/back-end service.
- Submissions & Documentation:
- The “Submissions” folder contains presentation documents, which although not part of the runtime architecture, indicate additional project artifacts that might help you understand the overall design and external interactions.

##### Relationships and Interactions
- Data Flow from the “Cotton Disease” dataset → ML Training Module → Model files.
- User Initiation: Web/Mobile App sends image upload requests to the Backend → Backend calls ML Module for prediction → Response sent back to Web/Mobile frontends.
- The backend then manages data persistence by logging results in the SQL/Google Cloud database.
- Authentication flows between the user interfaces (login/signup pages) and backend.

##### Architectural Patterns and Technologies
- This is a full-stack architecture employing separation of concerns:
- Client-side components (web views, mobile interface) are distinctly separated from the server-side logic (Node.js/Express APIs).
- The system utilizes an MVC-like pattern with clearly defined views (EJS in “views”) and controller logic in “src/index.js”.
- Integration of machine learning into the application can be highlighted as a microservice or separate module.
- Relevant Technologies:
- Programming: Node.js, Express, EJS.
- Machine Learning: Python scripts (ml_script.py), ResNet, possibly VGG16.
- Image Processing: OpenCV.
- Databases: SQL databases and Google Cloud storage.
- Mobile Development: Flutter (Android).
- Deployment and static assets handling via “public” and configuration files in “src”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["User (Web & Mobile)"]:::user
    subgraph "Frontend"
        F1["Templates (views)"]:::frontend
        F2["Static Assets (public)"]:::frontend
    end
    subgraph "Backend API (Node.js/Express)"
        B1["Index (src/index.js)"]:::backend
        B2["Config (src/config.js)"]:::backend
        B3["Package Files (src/package.json & package-lock.json)"]:::backend
    end
    subgraph "ML Inference Service (Python, ResNet Model)"
        M1["ML Script (ml_script.py)"]:::ml
        M2["Model Files (uploads/model)"]:::ml
    end
    D["Dataset Repository (Cotton Disease)"]:::data
    Db["Database (SQL/Google Cloud)"]:::database
    S["Submissions & Documentation (Submissions)"]:::doc

    %% User interaction flow
    A -->|"initiates"| F1
    F1 -->|"uploads_image"| B1
    B1 -->|"inference_request"| M1
    M1 -->|"returns_prediction"| B1
    B1 -->|"stores_result"| Db
    B1 -->|"serves_response"| F1

    %% Training data flow
    D -->|"training_data"| M2

    %% Click Events
    click D "https://github.com/furiousfoe/farmwise/tree/main/Cotton Disease"
    click M1 "https://github.com/furiousfoe/farmwise/blob/main/uploads/ml_script.py"
    click M2 "https://github.com/furiousfoe/farmwise/tree/main/uploads/model"
    click B1 "https://github.com/furiousfoe/farmwise/blob/main/src/index.js"
    click B2 "https://github.com/furiousfoe/farmwise/blob/main/src/config.js"
    click B3 "https://github.com/furiousfoe/farmwise/blob/main/src/package.json"
    click F1 "https://github.com/furiousfoe/farmwise/tree/main/views"
    click F2 "https://github.com/furiousfoe/farmwise/tree/main/public"
    click S "https://github.com/furiousfoe/farmwise/tree/main/Submissions"

    %% Styles
    classDef user fill:#f9c,stroke:#333,stroke-width:2px;
    classDef frontend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef backend fill:#bfb,stroke:#333,stroke-width:2px;
    classDef ml fill:#fbf,stroke:#333,stroke-width:2px;
    classDef data fill:#ff9,stroke:#333,stroke-width:2px;
    classDef database fill:#afa,stroke:#333,stroke-width:2px;
    classDef doc fill:#ccc,stroke:#333,stroke-width:2px;
```
