# sumankhan18/kissan_helper architecture

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

- Interactive diagram: https://gitdiagram.com/sumankhan18/kissan_helper
- Repository: https://github.com/sumankhan18/kissan_helper

## Overview

##### Project type and purpose
- This is a full-stack web application comprised of two parallel portals:
– An Admin portal (React + Vite frontend, Node/Express backend) for managing users, payments, broadcasts, shipments, policies, etc.
– A User portal (React + Vite frontend) with an AI-agent sub-application (Next.js) for interactive agricultural guidance (crop advice, weather, disease detection, etc.).
- Key use cases: Admins log in to configure and monitor the system; end users browse features, interact with the AI agent, view dashboards, and transact (payments, notifications).

##### File structure
Top-level modules:
- Admin/
– backend/ (Express server.js, Twilio service, phone utils)
– server/ (Express routes for auth, database utils, email service)
– src/ (React/Vite app + components, pages, context, services: Firebase, Twilio, Razorpay, EmailJS)
- User/
– src/ (React/Vite app with features for crop yield, sensors, disease detection, etc.)
– src/ai-agent/ (Next.js application for chat & domain pages, caching, SSR build artifacts)
Common patterns:
– MVC-like separation in Admin (server/routes, server/utils)
– Feature-driven structure in User/src/features
– Service modules to abstract external integrations (Twilio, EmailJS, Razorpay, Firebase)
Deployment/config: Vite configs (vite.config.js), ESLint, CORS, package.json at each module.

##### Insights from README
– The README is minimal, so infer architecture from folder names and code organization.

##### Final recommendations
– Be exhaustive: include every service folder (e.g., twilioService.js) to show how external interactions occur
– Capture context providers (AuthContext) and their role in the UI flow
– Represent the AI agent’s build and runtime artifacts as a micro-service sub-system

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        AdminUI["Admin Web Client"]:::frontend
        UserUI["User Web Client"]:::frontend
        AIUI["AI Agent Service"]:::frontend
    end

    %% Admin Web Client details
    subgraph "Admin UI Details"
        direction TB
        AM["main.jsx"]:::frontend
        AA["App.jsx"]:::frontend
        AV["vite.config.js"]:::frontend
        APC["pages/"]:::frontend
        ACC["components/"]:::frontend
        AAuth["AuthContext.jsx"]:::frontend
        ASvc["services/"]:::frontend
        ACfg["config/"]:::frontend
    end

    AdminUI --> AM
    AdminUI --> AA
    AdminUI --> AV
    AdminUI --> APC
    AdminUI --> ACC
    AdminUI --> AAuth
    AdminUI --> ASvc
    AdminUI --> ACfg

    %% User Web Client details
    subgraph "User UI Details"
        direction TB
        UM["main.jsx"]:::frontend
        UV["vite.config.js"]:::frontend
        UPC["pages/"]:::frontend
        UCC["components/"]:::frontend
        UFe["features/"]:::frontend
        UMe["media/"]:::frontend
        UN["notifications/"]:::frontend
        UFb["firebase.js"]:::frontend
    end

    UserUI --> UM
    UserUI --> UV
    UserUI --> UPC
    UserUI --> UCC
    UserUI --> UFe
    UserUI --> UMe
    UserUI --> UN
    UserUI --> UFb

    %% AI Agent Service details
    subgraph "AI Agent Service Details"
        direction TB
        AApp["app/"]:::frontend
        ALayout["layout.tsx"]:::frontend
        AGem["lib/gemini.ts"]:::frontend
        ANext[".next/"]:::frontend
    end

    AIUI --> AApp
    AIUI --> ALayout
    AIUI --> AGem
    AIUI --> ANext

    %% Backend Services Layer
    subgraph "Backend Services" 
        direction TB
        subgraph "Admin API" 
            direction TB
            Srv["server.js"]:::backend
            subgraph "External SMS & Utils"
                direction TB
                TS["twilioService.js"]:::backend
                PU["phoneUtils.js"]:::backend
            end
        end

        subgraph "Admin Routes & Utils"
            direction TB
            AuthR["auth.js"]:::backend
            DBU["database.js"]:::backend
            EmailU["emailService.js"]:::backend
        end

        subgraph "ML/LLM Backend"
            direction TB
            LLM["Gemini LLM Backend"]:::backend
        end
    end

    %% Data Layer
    subgraph "Data & Auth Store"
        direction TB
        FAdminJS["Admin/firebase.js"]:::data
        FAdminTS["Admin/src/services/firebase.ts"]:::data
        FUserJS["User/src/firebase.js"]:::data
        Firebase["Firebase Auth & Firestore/Realtime"]:::data
    end

    FAdminJS --> Firebase
    FAdminTS --> Firebase
    FUserJS --> Firebase

    %% External Providers
    subgraph "External Services"
        direction TB
        Twilio["Twilio SMS"]:::external
        RazorCfg["Razorpay Config"]:::external
        RazorSvc["Razorpay Service"]:::external
        EmailJSConf["EmailJS Config"]:::external
        EmailJSvc["EmailJS Services"]:::external
    end

    %% Interactions
    AdminUI -->|"HTTP CRUD"| Srv
    UserUI -->|"REST/GraphQL"| AIUI
    AdminUI -->|"Auth & Data"| Firebase
    UserUI -->|"Auth & Data"| Firebase
    AIUI -->|"Chat Requests"| LLM
    Srv -->|"SMS"| Twilio
    Srv -->|"Payments"| RazorSvc
    Srv -->|"Email"| EmailJSvc

    %% Click Events
    click AM "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/src/main.jsx"
    click AA "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/src/App.jsx"
    click AV "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/vite.config.js"
    click APC "https://github.com/sumankhan18/kissan_helper/tree/master/Admin/src/pages/"
    click ACC "https://github.com/sumankhan18/kissan_helper/tree/master/Admin/src/components/"
    click AAuth "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/src/context/AuthContext.jsx"
    click ASvc "https://github.com/sumankhan18/kissan_helper/tree/master/Admin/src/services/"
    click ACfg "https://github.com/sumankhan18/kissan_helper/tree/master/Admin/src/config/"
    click UM "https://github.com/sumankhan18/kissan_helper/blob/master/User/src/main.jsx"
    click UV "https://github.com/sumankhan18/kissan_helper/blob/master/User/vite.config.js"
    click UPC "https://github.com/sumankhan18/kissan_helper/tree/master/User/src/pages/"
    click UCC "https://github.com/sumankhan18/kissan_helper/tree/master/User/src/components/"
    click UFe "https://github.com/sumankhan18/kissan_helper/tree/master/User/src/features/"
    click UMe "https://github.com/sumankhan18/kissan_helper/tree/master/User/src/media/"
    click UN "https://github.com/sumankhan18/kissan_helper/tree/master/User/src/notifications/"
    click UFb "https://github.com/sumankhan18/kissan_helper/blob/master/User/src/firebase.js"
    click AApp "https://github.com/sumankhan18/kissan_helper/tree/master/User/src/ai-agent/app/"
    click ALayout "https://github.com/sumankhan18/kissan_helper/blob/master/User/src/ai-agent/app/layout.tsx"
    click AGem "https://github.com/sumankhan18/kissan_helper/blob/master/User/src/ai-agent/lib/gemini.ts"
    click ANext "https://github.com/sumankhan18/kissan_helper/tree/master/User/src/ai-agent/.next/"
    click Srv "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/backend/server.js"
    click TS "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/backend/services/twilioService.js"
    click PU "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/backend/utils/phoneUtils.js"
    click AuthR "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/server/routes/auth.js"
    click DBU "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/server/utils/database.js"
    click EmailU "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/server/utils/emailService.js"
    click FAdminJS "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/src/firebase.js"
    click FAdminTS "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/src/services/firebase.ts"
    click FUserJS "https://github.com/sumankhan18/kissan_helper/blob/master/User/src/firebase.js"
    click RazorCfg "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/src/config/razorpay.ts"
    click RazorSvc "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/src/services/razorpay.ts"
    click Twilio "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/backend/services/twilioService.js"
    click EmailJSConf "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/src/config/emailjs.ts"
    click EmailJSvc "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/src/services/emailjs.ts"
    click EmailJSvc "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/src/services/email.ts"
    click EmailJSvc "https://github.com/sumankhan18/kissan_helper/blob/master/Admin/src/services/emailOTP.ts"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#2a6f97,color:#0c2d48
    classDef backend fill:#d4edda,stroke:#27632a,color:#144a23
    classDef data fill:#e2e3e5,stroke:#6c757d,color:#343a40
    classDef external fill:#fff3cd,stroke:#856404,color:#664d03
```
