# prakharjain345/smart-crop architecture

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

- Interactive diagram: https://gitdiagram.com/prakharjain345/smart-crop
- Repository: https://github.com/prakharjain345/smart-crop

## Overview

##### Project type and purpose
- This is a full-stack, mobile-responsive web application called **Smart Crop Management System**.
- Purpose: provide AI-driven crop advice, pest detection via images, farmer profile management, and advice history tracking.

##### File structure
- Top-level directories:
- backend/ – FastAPI server (server.py, requirements.txt)
- frontend/ – React + Tailwind CSS UI (src/, public/, package.json, config files)
- tests/ – backend and frontend test stubs
- .emergent/ – AI/LLM agent configuration (emergent.yml)
- Patterns & artifacts:
- Frontend uses CRA (craco.config.js), Tailwind (tailwind.config.js), Radix UI components under src/components/ui, custom hooks under src/hooks, utility libs under src/lib.
- Backend is a single FastAPI app with Pydantic models, Motor async MongoDB driver, CORS middleware, OpenAI/Emergent integration, PIL for image processing.
- No separate microservices—everything is in one FastAPI process, but AI calls and database calls are external integrations.
- Deployment hints: Docker-ready, environment variables (.env), emergent agent config.

##### README insights
- Confirms tech stack: React 19, Tailwind, Radix UI, Axios on frontend; FastAPI, Pydantic, Motor, dotenv, PIL, CORS on backend; MongoDB async; emergentintegrations and OpenAI GPT-4o mini for AI.
- Lists API endpoints under /api: crop-advice, pest-detection, farmer-profile, farmer-profiles, advice-history.
- Emphasizes mobile-first UI, hackathon origins, AI features, and testing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        FrontendClient["Frontend Client (Browser)"]:::frontend
        ReactApp["React App"]:::frontend
        UIComponents["UI Components (Radix UI)"]:::frontend
        Hooks["Custom Hooks"]:::frontend
        HTTPClient["HTTP Client (Axios)"]:::frontend
        Styling["Styling & Config"]:::frontend

        FrontendClient -->|uses| ReactApp
        ReactApp -->|renders| UIComponents
        ReactApp -->|uses| Hooks
        ReactApp -->|uses| HTTPClient
        ReactApp -->|configured by| Styling
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        APIServer["FastAPI Server"]:::backend
        BusinessLogic["Business Logic & Controllers"]:::backend
        DataModels["Data Models & Validation"]:::backend
        ImageProcessing["Image Processing (PIL)"]:::backend
        DBLayer["Database Layer (MongoDB/Motor)"]:::db
        AIIntegration["AI/LLM Integrator"]:::external

        APIServer -->|routes to| BusinessLogic
        BusinessLogic -->|validates with| DataModels
        BusinessLogic -->|processes image| ImageProcessing
        BusinessLogic -->|calls| AIIntegration
        BusinessLogic -->|reads/writes| DBLayer
    end

    %% External AI Services
    subgraph "External AI Services"
        direction TB
        Emergent["Emergent Agent"]:::external
        OpenAI["OpenAI GPT-4o mini"]:::external
    end

    AIIntegration -->|configured by| Emergent
    AIIntegration -->|calls| OpenAI

    %% Database
    MongoDB["MongoDB"]:::db
    DBLayer -->|connects to| MongoDB

    %% Configuration & Secrets
    subgraph "Configuration & Secrets"
        direction TB
        ConfigEnv["Environment Variables (.env)"]:::config
        EmergentConfig["Emergent Config (emergent.yml)"]:::config
    end

    ConfigEnv -->|used by| APIServer
    ConfigEnv -->|used by| DBLayer
    EmergentConfig -->|used by| AIIntegration

    %% HTTP Flow
    FrontendClient -->|HTTP requests| APIServer

    %% Test Suite
    Tests["Test Suite"]:::tests
    Tests -->|tests| APIServer
    Tests -->|tests| ReactApp

    %% Click Events
    click FrontendClient "https://github.com/prakharjain345/smart-crop/tree/main/frontend/src"
    click ReactApp "https://github.com/prakharjain345/smart-crop/blob/main/frontend/src/App.js"
    click UIComponents "https://github.com/prakharjain345/smart-crop/tree/main/frontend/src/components/ui/"
    click Hooks "https://github.com/prakharjain345/smart-crop/blob/main/frontend/src/hooks/use-toast.js"
    click HTTPClient "https://github.com/prakharjain345/smart-crop/blob/main/frontend/src/lib/utils.js"
    click Styling "https://github.com/prakharjain345/smart-crop/blob/main/frontend/tailwind.config.js"
    click Styling "https://github.com/prakharjain345/smart-crop/blob/main/frontend/craco.config.js"
    click APIServer "https://github.com/prakharjain345/smart-crop/blob/main/backend/server.py"
    click BusinessLogic "https://github.com/prakharjain345/smart-crop/blob/main/backend/server.py"
    click DataModels "https://github.com/prakharjain345/smart-crop/blob/main/backend/server.py"
    click ImageProcessing "https://github.com/prakharjain345/smart-crop/blob/main/backend/server.py"
    click DBLayer "https://github.com/prakharjain345/smart-crop/blob/main/backend/server.py"
    click EmergentConfig "https://github.com/prakharjain345/smart-crop/blob/main/.emergent/emergent.yml"
    click ConfigEnv "https://github.com/prakharjain345/smart-crop/blob/main/backend/.env"
    click Tests "https://github.com/prakharjain345/smart-crop/tree/main/tests/"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef db fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef config fill:#FFFFE0,stroke:#000,stroke-width:1px
    classDef tests fill:#E6E6FA,stroke:#000,stroke-width:1px
```
