# gitshanu/urban-roof-plantation architecture

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

- Interactive diagram: https://gitdiagram.com/gitshanu/urban-roof-plantation
- Repository: https://github.com/gitshanu/urban-roof-plantation

## Overview

##### Project Overview
- This is a full-stack web application built using Flask. Its primary purpose is to provide rooftop crop recommendations based on user inputs (area, water, sunlight) and offer an AI-powered chatbot for gardening questions.
- The key technologies include Flask (for backend handling), pandas (for data processing on crop_data.csv), Together AI (for the chatbot), and standard HTML/CSS/JavaScript (for the frontend interface). The application is deployed on Render.

##### Analyzing the File Structure
- At the top level you have important files such as README.md, app.py, crop_data.csv, and requirements.txt.
- The app.py file serves as the main entry point for the Flask application.
- The crop_data.csv file contains the dataset used for crop recommendation.
- The static directory includes necessary client-side assets (chat.js and style.css) that power the interactive parts of the application.
- The templates directory holds HTML files (index.html and result.html) that render the UI.

##### Elements
a. Main Components of the System:
- Frontend (Client Side): Represents the browser-based UI which loads HTML pages, applies CSS, and executes JavaScript (including the chat widget functionality).
- Backend Server (Flask Application): Handles HTTP routing, processes user inputs, performs crop filtering using pandas on the CSV data, and manages the endpoints related to both crop recommendation and the AI chatbot.
- Data Component: The crop_data.csv file, which is read and processed to generate recommendations.
- External Service: Together AI service which is used by the chatbot component for natural language processing and providing real-time responses.
- Deployment Environment: Render deployment (with Gunicorn) on which the application is hosted.

b. Relationships and Interactions:
- The user interacts with the frontend (via forms and chat widget) in the web browser.
- The frontend sends data (like form input for crop recommendation or chat input) through HTTP requests to the Flask backend.
- The Flask backend routes the requests appropriately: one route processes crop recommendations using pandas (reading crop_data.csv) and another route (/chat) forwards user queries to the Together AI API.
- The backend receives responses from the Together AI service and then sends back the responses to be displayed on the client.
- Static assets and HTML templates are served from their respective folders ensuring the UI renders correctly.

c. Architectural Patterns and Principles:
- MVC-like Structure: The separation between templates (view) and app.py (controller/logic) hints at a model-view-controller separation, even if it is simple and not formally structured.
- RESTful interactions: The communication between the frontend and backend using HTTP endpoints.
- External API Integration: Clear demarcation where the backend acts as a mediator between the client and the Together AI service.

d. Relevant Technologies and Their Roles:
- Flask: Core framework for handling HTTP requests and routing.
- pandas: Data processing library used for filtering crop recommendations.
- Together AI: External NLP service for powering the chatbot.
- HTML/CSS/JavaScript: Basic web technologies for the UI.
- Render (and Gunicorn): Deployment and production serving.

##### Emphasizing Detail
- Every component, even if small, is represented.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    UB["User Browser"]:::user
    subgraph "Frontend (HTML/CSS/JS)"
        direction TB
        IT["Index Template"]:::frontend
        RT["Result Template"]:::frontend
        CJ["chat.js"]:::frontend
        SC["style.css"]:::frontend
    end
    FB["Flask Backend"]:::backend
    CR["Crop Recommendation Module"]:::module
    TA["Together AI API"]:::external
    CD["Data: crop_data.csv"]:::data
    DEP["Deployment (Render/Gunicorn)"]:::deployment

    %% Connections
    UB -->|"loads_UI"| IT
    UB -->|"loads_UI"| RT
    UB -->|"loads_UI"| CJ
    UB -->|"loads_UI"| SC
    UB -->|"sends_HTTP_requests"| FB
    FB -->|"processes_recommendation"| CR
    CR -->|"reads_data_from"| CD
    CR -->|"returns_results"| FB
    FB -->|"forwards_chat_request"| TA
    TA -->|"returns_chat_response"| FB
    FB -->|"renders_response"| UB
    DEP -->|"hosts"| FB

    %% Click Events
    click IT "https://github.com/gitshanu/urban-roof-plantation/blob/main/templates/index.html"
    click RT "https://github.com/gitshanu/urban-roof-plantation/blob/main/templates/result.html"
    click CJ "https://github.com/gitshanu/urban-roof-plantation/blob/main/static/chat.js"
    click SC "https://github.com/gitshanu/urban-roof-plantation/blob/main/static/style.css"
    click FB "https://github.com/gitshanu/urban-roof-plantation/blob/main/app.py"
    click CD "https://github.com/gitshanu/urban-roof-plantation/blob/main/crop_data.csv"

    %% Styles
    classDef user fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef frontend fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef backend fill:#f5b7b1,stroke:#333,stroke-width:2px;
    classDef module fill:#abebc6,stroke:#333,stroke-width:2px;
    classDef external fill:#f5cba7,stroke:#333,stroke-width:2px;
    classDef data fill:#d5f5e3,stroke:#333,stroke-width:2px;
    classDef deployment fill:#d6eaf8,stroke:#333,stroke-width:2px;
```
