# ai-hackathon-2025/scarecrow architecture

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

- Interactive diagram: https://gitdiagram.com/ai-hackathon-2025/scarecrow
- Repository: https://github.com/ai-hackathon-2025/scarecrow

## Overview

##### Project Type and Purpose
- This project is a full-stack Django web application. The “scarecrowApp” directory (with files such as settings.py, urls.py, asgi.py, and wsgi.py) clearly indicates a Django configuration for the web frontend and backend.
- The “disease_detector” package contains domain-specific logic for analyzing crops, classifying images (likely to detect diseases), and recommending crop-related actions. It includes modules for model training (Jupyter notebooks), a crop analyser, and pre-trained machine learning models (stored as .pkl, .joblib files).
- The project combines web application functionalities (serving front-end pages, static files, and Django views) with machine learning components for processing crop data and images.

##### File Structure
- Top-Level Files and Directories:
- .gitignore, README.md, manage.py, and requirement.txt: Standard files for project management and dependency tracking.
- The "scarecrowApp" directory: Contains the Django project configuration and routing files (ASGI, WSGI, settings, and URL configurations).
- The "disease_detector" package: It comprises application logic, analysis scripts (crop_analyser.py and image_classifier_code.py), model training notebooks, and pre-built models stored in the models subdirectory.
- "static" and "templates": Directories for the frontend – CSS, JavaScript, and HTML files that render the UI.
- Additional notebooks in "model_traning" that reinforce the focus on model training and evaluation.
- Architectural Aspects:
- The separation between “scarecrowApp” and “disease_detector” suggests modularization where the Django app serves as the orchestration layer, and the disease_detector module provides domain-specific ML logic.
- The presence of Jupyter notebooks suggests an exploratory and iterative process for model training and evaluation.

##### Detail the Components
- Frontend Component:
- Templates (HTML files) and Static Files (CSS & JavaScript) that build the user interface.
- This component handles user interactions and displays results from the backend.
- Backend Component – Django Application (“scarecrowApp”):
- Acts as the central coordinator taking HTTP requests, routing them appropriately, and delivering responses.
- Contains URL configurations, settings, middleware, and interfaces with the domain logic.
- Domain Logic / Business Layer – Disease Detector:
- This package includes:
◦ Crop Analyser: Code responsible for analyzing crop images or data.
◦ Image Classifier: Functions to classify images to detect diseases.
◦ Model Training Scripts: Jupyter notebooks and training modules for building/updating machine learning models.
◦ Pre-trained Models: Stored serialized models and encoders (such as crop recommendation model, label encoder, paddy image classifier) that are loaded for inference.
- Relationship: The Django backend (views, controllers) invokes functions in the disease_detector to process data, predict outcomes, and then return findings to the user.
- Data Store / Dataset:
- CSV files (like Crop_recommendation.csv) that serve as data input for crop recommendation.
- Serve as a reference used during prediction or additional analysis.
- Deployment & Infrastructure:
- The manage.py file and configuration files in scarecrowApp indicate how the project is executed and deployed (using Django’s ASGI/WGSI).

##### Establish Relationships and Interactions
- Data Flow:
- User Request: A user interacts with the frontend (via the browser), making an HTTP request.
- Django Routing: The request is received by the Django application (scarecrowApp) and routed to the appropriate view.
- Business Logic Invocation: The view calls functions in the disease_detector package to perform image classification, crop analysis, or model inference.
- Data Retrieval/Processing: If necessary, the disease_detector accesses data files (e.g., Crop_recommendation.csv) or loads pre-trained models.
- Response: The results are sent back through Django views, rendered in templates, and finally displayed on the user interface.
- Dependencies between modules:

## Diagram (Mermaid)

```mermaid
graph TD
    A("User Request"):::external

    subgraph "Web Frontend (Templates & Static Files)"
        F1("Template: index.html"):::frontend
        F2("CSS: style.css"):::frontend
        F3("JS: script.js"):::frontend
    end

    subgraph "Django Backend (scarecrowApp)"
        B1("settings.py"):::backend
        B2("urls.py"):::backend
        B3("asgi.py"):::backend
        B4("wsgi.py"):::backend
    end

    subgraph "Disease Detector Module"
        D0("Disease Detector Package"):::business
        D1("Crop Analyser"):::business
        D2("Image Classifier"):::business
        D3("Django Views"):::business
        D0 --> D1
        D0 --> D2
        D0 --> D3
    end

    subgraph "Model Training & Evaluation"
        M1("crop-dataset.ipynb"):::business
        M2("Paddy_CNN_clasification.ipynb"):::business
    end

    P("Pre-trained Models"):::data
    Data("Dataset (Crop_recommendation.csv)"):::data

    Deploy("manage.py"):::deployment

    %% Flow Connections
    A -->|"HTTP_Request"| F1
    F1 -->|"Submit"| B1
    B1 -->|"Invokes"| D0
    D3 -->|"Returns_Response"| B1
    B1 -->|"Sends_Response"| F1
    D1 -->|"Uses_Model"| P
    D1 -->|"Reads_Data"| Data
    D2 -->|"Uses_Model"| P
    M1 -->|"Updates_Model"| P
    M2 -->|"Updates_Model"| P
    Deploy -->|"Starts"| B1

    %% Indicate composition within Frontend
    F1 --- F2
    F1 --- F3

    %% Styling
    classDef frontend fill:#A2D2FF,stroke:#333,stroke-width:2px;
    classDef backend fill:#CFF09E,stroke:#333,stroke-width:2px;
    classDef business fill:#FFDFBA,stroke:#333,stroke-width:2px;
    classDef data fill:#F0E5DE,stroke:#333,stroke-width:2px;
    classDef deployment fill:#FFB7B2,stroke:#333,stroke-width:2px;
    classDef external fill:#E0BBE4,stroke:#333,stroke-width:2px;

    %% Click Events
    click F1 "https://github.com/ai-hackathon-2025/scarecrow/blob/main/templates/index.html"
    click F2 "https://github.com/ai-hackathon-2025/scarecrow/blob/main/static/css/style.css"
    click F3 "https://github.com/ai-hackathon-2025/scarecrow/blob/main/static/js/script.js"
    click B1 "https://github.com/ai-hackathon-2025/scarecrow/blob/main/scarecrowApp/settings.py"
    click B2 "https://github.com/ai-hackathon-2025/scarecrow/blob/main/scarecrowApp/urls.py"
    click B3 "https://github.com/ai-hackathon-2025/scarecrow/blob/main/scarecrowApp/asgi.py"
    click B4 "https://github.com/ai-hackathon-2025/scarecrow/blob/main/scarecrowApp/wsgi.py"
    click D0 "https://github.com/ai-hackathon-2025/scarecrow/tree/main/disease_detector"
    click D1 "https://github.com/ai-hackathon-2025/scarecrow/blob/main/disease_detector/crop_analyser.py"
    click D2 "https://github.com/ai-hackathon-2025/scarecrow/blob/main/disease_detector/image_classifier_code.py"
    click D3 "https://github.com/ai-hackathon-2025/scarecrow/blob/main/disease_detector/views.py"
    click M1 "https://github.com/ai-hackathon-2025/scarecrow/blob/main/disease_detector/model_training/crop-dataset.ipynb"
    click M2 "https://github.com/ai-hackathon-2025/scarecrow/blob/main/model_traning/Paddy_CNN_clasification.ipynb"
    click P "https://github.com/ai-hackathon-2025/scarecrow/tree/main/disease_detector/models"
    click Data "https://github.com/ai-hackathon-2025/scarecrow/blob/main/disease_detector/dataset/Crop_recommendation.csv"
    click Deploy "https://github.com/ai-hackathon-2025/scarecrow/blob/main/manage.py"
```
