# piyush-ouch/rootify architecture

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

- Interactive diagram: https://gitdiagram.com/piyush-ouch/rootify
- Repository: https://github.com/piyush-ouch/rootify

## Overview

##### Project type and purpose
- Rootify is a full-stack web application (single-page/admin pages + backend proxy server) that empowers farmers and admins with agricultural insights.
- Key features include two roles (user/admin), a multimodal AI assistant for text/image queries, Firebase for auth and data storage, and a Node/Express proxy to the Google Generative AI (Gemini) API.

##### File structure
- Top-level “public” folder holds all static assets (HTML, CSS, JS, images).
- “server” folder contains the Node/Express proxy (app.js) plus package.json/lock.
- No monolithic framework: vanilla JS + Express, Firebase SDKs, and the `@google/generative-ai` SDK.

##### README insights
- Frontend communicates directly with Firebase Auth & Firestore via client SDKs.
- Backend server is used as a proxy to secure the Generative AI API key and forward chat/image requests to the Gemini API.
- Deployment can bundle static files and the Express app on platforms like Vercel, Netlify (Functions), or Firebase Hosting + Functions.

##### Main components & interactions
a. Components
- Static Hosting (e.g. Vercel/Netlify/Firebase Hosting)
- Frontend UI (public/index.html, user.html, admin.html + JS modules)
- Client-side Firebase SDKs (Auth & Firestore)
- Node.js/Express Proxy (“server/app.js”)
- Google Generative AI (Gemini) API
- Firebase Firestore Database
- Firebase Authentication Service
b. Relationships & Data Flow
1. Browser loads static assets from Hosting.
2. Frontend JS ↔ Firebase Auth (login/signup flows).
3. Authenticated Frontend JS ↔ Firestore (read/update soil/distributor data).
4. For AI queries: Frontend JS → Express Proxy → Gemini API → Proxy → Frontend.
c. Architectural patterns
- BFF (Backend-for-Frontend) via Node/Express proxy to secure AI API key.
- Client-side BaaS (Firebase) for authentication and real-time data.
- Separation of concerns: static UI vs. API proxy vs. data layer.
d. Technologies
- Frontend: HTML5, CSS3 (glassmorphism), ES6 modules.
- Backend: Node.js, Express.js, dotenv, `@google/generative-ai`.
- BaaS: Firebase Auth & Firestore.
- External AI: Google Gemini API.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Browser and Hosting
    Browser["Browser UI"]:::frontend
    Hosting["Static Hosting\n(public/)"]:::frontend
    
    Browser -->|"loads assets"| Hosting

    subgraph "Frontend (Client-side)" 
        direction TB
        UIUser["User Page\n(user.html)"]:::frontend
        UIAdmin["Admin Page\n(admin.html)"]:::frontend
        MainJS["Main JS Module\n(main-frontend.js)"]:::frontend
        UserJS["User Logic\n(user-script.js)"]:::frontend
        AdminJS["Admin Logic\n(admin-script.js)"]:::frontend
        Styles["Stylesheet\n(styles.css)"]:::frontend
        FirebaseInit["Firebase Init\n(firebase-init.js)"]:::frontend
    end

    Hosting --> UIUser
    Hosting --> UIAdmin
    Hosting --> MainJS
    Hosting --> UserJS
    Hosting --> AdminJS
    Hosting --> Styles
    Hosting --> FirebaseInit

    %% Client to BaaS
    UIUser -->|"Auth/Firestore SDK"| FirebaseAuth
    UIAdmin -->|"Auth/Firestore SDK"| FirebaseAuth
    MainJS -->|"Auth/Firestore SDK"| FirebaseAuth
    FirebaseInit --> FirebaseAuth

    UIUser -->|"Auth/Firestore SDK"| Firestore
    UIAdmin -->|"Auth/Firestore SDK"| Firestore
    MainJS -->|"Auth/Firestore SDK"| Firestore
    FirebaseInit --> Firestore

    %% Client to Proxy for AI
    MainJS -->|"GET/POST /api/chat or /api/image"| Proxy
    UserJS -->|"GET/POST /api/chat or /api/image"| Proxy
    AdminJS -->|"GET/POST /api/chat or /api/image"| Proxy

    %% Serverless/Node Layer
    subgraph "Server (Node/Express Proxy)" 
        direction TB
        Proxy["Express Proxy\n(app.js)"]:::backend
        PackageJSON["package.json"]:::config
        PackageLock["package-lock.json"]:::config
    end

    Proxy -->|"forwards to"| GeminiAPI
    GeminiAPI["Google Gemini API"]:::external
    GeminiAPI -->|"response"| Proxy
    Proxy -->|"response"| Browser

    %% BaaS Services
    subgraph "Firebase Services"
        direction TB
        FirebaseAuth["Firebase Authentication"]:::baas
        Firestore["Firestore Database"]:::baas
    end

    %% Configuration and Docs
    subgraph "Configuration & Docs"
        direction TB
        Readme["README.md"]:::config
        Gitignore[".gitignore"]:::config
    end

    %% Click Events
    click Hosting "https://github.com/piyush-ouch/rootify/tree/main/public/"
    click UIUser "https://github.com/piyush-ouch/rootify/blob/main/public/user.html"
    click UIAdmin "https://github.com/piyush-ouch/rootify/blob/main/public/admin.html"
    click MainJS "https://github.com/piyush-ouch/rootify/blob/main/public/main-frontend.js"
    click UserJS "https://github.com/piyush-ouch/rootify/blob/main/public/user-script.js"
    click AdminJS "https://github.com/piyush-ouch/rootify/blob/main/public/admin-script.js"
    click Styles "https://github.com/piyush-ouch/rootify/blob/main/public/styles.css"
    click FirebaseInit "https://github.com/piyush-ouch/rootify/blob/main/public/firebase-init.js"
    click Proxy "https://github.com/piyush-ouch/rootify/blob/main/server/app.js"
    click PackageJSON "https://github.com/piyush-ouch/rootify/blob/main/server/package.json"
    click PackageLock "https://github.com/piyush-ouch/rootify/blob/main/server/package-lock.json"
    click Readme "https://github.com/piyush-ouch/rootify/blob/main/README.md"
    click Gitignore "https://github.com/piyush-ouch/rootify/blob/main/.gitignore"

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#006064,stroke-width:1px
    classDef backend fill:#e8f5e9,stroke:#1b5e20,stroke-width:1px
    classDef baas fill:#fff3e0,stroke:#ef6c00,stroke-width:1px
    classDef external fill:#f3e5f5,stroke:#4a148c,stroke-width:1px
    classDef config fill:#eceff1,stroke:#455a64,stroke-width:1px
```
