# rudra8984/scarecrow architecture

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

- Interactive diagram: https://gitdiagram.com/rudra8984/scarecrow
- Repository: https://github.com/rudra8984/scarecrow

## Overview

- Frontend: Represent “scarecrow-front” as a React.js web application. This is the user interface for farmers, buyers, and sellers. Include assets like HTML/CSS/JS, images, and public static files.
- Backend: Show “ScareCrow-back” as the Django server that handles routing, business logic, and integration of AI-powered modules. Inside the backend, identify the “disease_detector” application which encapsulates the core functionality for disease detection and crop analysis.
- AI/ML Modules: Highlight the components that perform AI-based crop recommendation and disease diagnosis. This includes:
- The use of pre-trained models (e.g., “crop_recommendation_model.pkl”, “label_encoder.pkl”, and “paddy_image_classifier.joblib”).
- Scripts like “LLM_model.py”, “crop_analyser.py”, and “image_classifier_code.py” that encapsulate the machine learning logic.
- The model training environment in “model_traning”, which (even if standalone) plays a key role in generating or updating the models.
- External Services and Integrations:
- Chatbot Integration: Note the use of the Gemini API, which facilitates follow-up Q&A about disease treatments.
- Marketplace Database: Represent Firebase as a key external dependency for the agricultural marketplace, even though the integration may be referenced in the settings and documentation rather than in explicit file structure.
- Cloud Hosting: Mention GCP and Firebase Hosting for deployment of the backend and/or frontend.
- Data Stores: Indicate the databases or storage solutions used:
- For Django, include a relational database (e.g., PostgreSQL, SQLite, etc. as per typical Django setups).
- For the marketplace, denote Firebase’s real-time database for product listings and user profiles.

##### Interactions and Data Flows
- Frontend to Backend:
- API calls from the React application to the Django backend for processing user inputs (crop parameters or image uploads).
- Backend Processing:
- Within Django, illustrate the flow where the “disease_detector” module forwards data to respective AI/ML model inference functions.
- Routing via files like “urls.py”, “views.py”, and the use of templates (e.g., “index.html”, “index2.html”) for rendering responses.
- AI/ML Pipeline:
- Subprocesses where uploaded images or input parameters are processed by ML models.
- That training notebooks (in “model_traning”) are used to develop and update models, which are then loaded by the Django app.
- External API Integration:
- Marketplace Integration:
- Interactions between the backend and Firebase to update or retrieve marketplace data.

##### Architectural Patterns
- Modular Separation: Clarify how the Django backend is organized into separate apps (e.g., “disease_detector”, “scarecrowApp”), which enforces modularity.
- MVC/MVT Pattern: Indicate that Django follows the Model-View-Template (MVT) architecture, where each component is clearly delineated.
- Microservice or Inter-module Interaction: While the system is mostly monolithic in Django architecture, the separation between the frontend and the backend can be shown as a microservice-like division.

##### Detail Relevant Technologies and Frameworks
- Frontend with React.js, and list supporting libraries as used in the project (e.g., mention that it uses standard HTML/CSS/JavaScript tooling).
- Django and Python (Python 3.12+) as core backend technologies.
- AI/ML frameworks (TensorFlow/Keras as mentioned in the README) that may be involved in model building/training.
- Denote external services like Firebase (for the marketplace) and Gemini API (for chatbot integration), as well as the hosting platforms GCP and Firebase Hosting.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE("React Application"):::frontend
        Assets("Static Assets (HTML/CSS/JS/Images)"):::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE("Django Server"):::backend
        DDetector("Disease Detector Module"):::backend
        AppConfig("Django App Config"):::backend
    end

    %% AI/ML Modules and Pre-trained Models
    subgraph "AI/ML Modules"
        LLM("LLM Model"):::ai
        CA("Crop Analyser"):::ai
        IC("Image Classifier Logic"):::ai
        subgraph "Pre-trained Models"
            CropRec("Crop Recommendation Model"):::ai
            Encoder("Label Encoder"):::ai
            PaddyClassifier("Paddy Image Classifier"):::ai
        end
    end

    %% Model Training Environment
    subgraph "Model Training Environment"
        Training("Training Notebooks"):::training
    end

    %% External Services & Data Stores
    subgraph "External Services & Data Stores"
        Chatbot("Gemini API (Chatbot)"):::external
        Firebase("Firebase (Marketplace DB & Hosting)"):::external
        RelDB("Relational Database (Django)"):::external
    end

    %% Connections and Data Flows
    FE -->|"API_request(crop/disease)"| BE
    Assets --> FE
    BE -->|"Routing(via urls/views)"| AppConfig
    BE -->|"Processes_request"| DDetector
    DDetector -->|"Inference_call"| LLM
    DDetector -->|"Inference_call"| CA
    DDetector -->|"Inference_call"| IC
    LLM -->|"Loads_model"| CropRec
    LLM -->|"Loads_model"| Encoder
    CA -->|"Loads_model"| CropRec
    IC -->|"Loads_model"| PaddyClassifier
    BE -->|"Chatbot_query"| Chatbot
    BE -->|"Marketplace_logic"| Firebase
    BE -->|"Stores_data"| RelDB
    Training -->|"Updates_models"| LLM
    Training -->|"Updates_models"| CA
    Training -->|"Updates_models"| IC
    FE -->|"Marketplace_interaction"| Firebase

    %% Click Events
    click FE "https://github.com/rudra8984/scarecrow/tree/main/scarecrow-front"
    click BE "https://github.com/rudra8984/scarecrow/tree/main/ScareCrow-back"
    click DDetector "https://github.com/rudra8984/scarecrow/tree/main/ScareCrow-back/disease_detector"
    click LLM "https://github.com/rudra8984/scarecrow/blob/main/ScareCrow-back/disease_detector/LLM_model.py"
    click CA "https://github.com/rudra8984/scarecrow/blob/main/ScareCrow-back/disease_detector/crop_analyser.py"
    click IC "https://github.com/rudra8984/scarecrow/blob/main/ScareCrow-back/disease_detector/image_classifier_code.py"
    click CropRec "https://github.com/rudra8984/scarecrow/blob/main/ScareCrow-back/disease_detector/models/crop_recommendation_model.pkl"
    click Encoder "https://github.com/rudra8984/scarecrow/blob/main/ScareCrow-back/disease_detector/models/label_encoder.pkl"
    click PaddyClassifier "https://github.com/rudra8984/scarecrow/blob/main/ScareCrow-back/disease_detector/models/paddy_image_classifier.joblib"
    click Training "https://github.com/rudra8984/scarecrow/tree/main/ScareCrow-back/model_traning"
    click AppConfig "https://github.com/rudra8984/scarecrow/tree/main/ScareCrow-back/scarecrowApp"

    %% Styles
    classDef frontend fill:#AEE1F9,stroke:#1F77B4,stroke-width:2px;
    classDef backend fill:#FFD700,stroke:#B8860B,stroke-width:2px;
    classDef ai fill:#98FB98,stroke:#2E8B57,stroke-width:2px;
    classDef training fill:#FFB6C1,stroke:#C71585,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#696969,stroke-width:2px;
```
