# sandeepgarikapati/cleanindia architecture

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

- Interactive diagram: https://gitdiagram.com/sandeepgarikapati/cleanindia
- Repository: https://github.com/sandeepgarikapati/cleanindia

## Overview

##### Project Identification
- The project is a Next.js web application that leverages Gemini AI for waste classification. Users upload images of waste, which are analyzed to identify the waste type and estimate quantity. A verifier confirms the matching image of the collected waste and, upon validation, rewards the waste collector with points.
- Key features include AI-powered waste classification, user submissions, image verification, reward points, and an admin dashboard. The application emphasizes responsible waste disposal using modern web technologies such as Next.js, Tailwind CSS, TypeScript, Drizzle ORM, and PostgreSQL, with external integrations (Gemini AI, WEB3Auth, Google Maps API).

##### File Structure Analysis
- The top-level directories (like "app", "components", "hook", "lib", and "utils") indicate a separation of concerns:
- The "app" directory contains multiple pages/components such as "collect", "leaderboard", "report", "rewards", and "settings". These represent different views or routes in the Next.js application.
- The "components" directory includes shared UI components such as Header, Sidebar, and several smaller UI widgets (badge, button, dropdown-menu, input) that are likely used across multiple pages.
- The "hook" directory holds custom React hooks (e.g., useMediaQuerty.ts) which manage behavior or state across the application.
- The "utils" and "lib" directories include database configurations and utility functions, such as database actions (dbConfig, actions, schema) that integrate with Drizzle ORM and PostgreSQL.
- Configuration files like next.config.mjs, tailwind.config.ts, tsconfig.json, and drizzle.config.js indicate build and tooling configuration.

##### Identifying System Components
- Frontend (Web Client):
- Pages within the "app" directory: Home page, Collection, Leaderboard, Report, Rewards, and Settings.
- Shared UI components (Header, Sidebar, other UI widgets from the components/ui folder).
- Custom Hooks (e.g., useMediaQuerty) for enhanced interactivity or responsiveness.
- Backend & API Layer:
- Next.js Server-Side Rendering (SSR) and API endpoints that facilitate waste image processing, verification, and integration with Gemini AI.
- Integration with WEB3Auth for authentication.
- Database:
- PostgreSQL, which is managed using Drizzle ORM. The utility functions and schema definitions under "utils/db" illustrate database actions and interactions.
- External Services:
- Gemini AI API for waste classification analysis.
- Google Maps API for any location-based functionality.
- WEB3Auth for user authentication.
- Deployment:
- The Vercel deployment setup (as indicated by the README) which is the hosting platform for the application.

##### Architectural Patterns & Design Principles
- The project uses a modular design, with clear separation between UI components (in the "app" and "components" directories) and business logic (in "utils", "lib", and "hook").
- The use of Next.js implies a hybrid model, supporting both client-side and server-side components.
- Incorporation of external APIs and authentication services shows a clear integration pattern where external dependencies are encapsulated within defined interfaces.
- The use of Drizzle ORM and a dedicated database utils directory highlights a clear abstraction over database interactions.

##### Final Advice
- Be as detailed as possible: break down the application’s routes, UI components, and backend services.
- Do not hesitate to add sub-components where necessary, particularly for complex interactions with external services.
- Remember that the goal is to capture all essential architectural elements and data flows between components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    User["User"]:::frontend

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        HomePage["Home Page"]:::frontend
        CollectionPage["Collection Page"]:::frontend
        LeaderboardPage["Leaderboard Page"]:::frontend
        ReportPage["Report Page"]:::frontend
        RewardsPage["Rewards Page"]:::frontend
        SettingsPage["Settings Page"]:::frontend
        subgraph "UI Components"
            direction TB
            Header["Header Component"]:::frontend
            Sidebar["Sidebar Component"]:::frontend
            UIWidgets["Reusable UI Widgets"]:::frontend
        end
        Hooks["Custom Hook (Media Query)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        API["Next.js API/Server"]:::backend
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        DB["PostgreSQL Database (Drizzle ORM)"]:::database
        subgraph "Database Utils"
            direction TB
            DBActions["Database Actions"]:::database
            DBConfig["Database Configuration"]:::database
            DBSchema["Database Schema Definitions"]:::database
            Drizzle["Drizzle ORM Configuration"]:::database
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Gemini["Gemini AI"]:::external
        Maps["Google Maps API"]:::external
        Auth["WEB3Auth"]:::external
    end

    %% Configuration & Utilities
    subgraph "Configuration & Utilities"
        direction TB
        GlobalLayout["Global Layout & Styles"]:::config
        BuildConfigs["Build & Tooling Configs"]:::config
        Utilities["General Utilities"]:::config
    end

    %% Deployment
    Deployment["Vercel Deployment"]:::deployment

    %% Connections from User to Frontend Pages
    User --> HomePage
    User --> CollectionPage
    User --> LeaderboardPage
    User --> ReportPage
    User --> RewardsPage
    User --> SettingsPage

    %% Connections from Frontend Pages to Backend API
    HomePage -->|"uploadsImage"| API
    CollectionPage -->|"submitImage"| API
    LeaderboardPage -->|"viewData"| API
    ReportPage -->|"reportWaste"| API
    RewardsPage -->|"rewardUpdate"| API
    SettingsPage -->|"updateSettings"| API

    %% Backend API interactions
    API -->|"databaseQuery"| DB
    API -->|"wasteAnalysis"| Gemini
    API -->|"locationLookup"| Maps
    API -->|"userAuth"| Auth
    API -->|"hostedOn"| Deployment

    %% Database Utils connections
    DB --> DBActions
    DB --> DBConfig
    DB --> DBSchema
    DB --> Drizzle

    %% Styles
    classDef frontend fill:#aaddff,stroke:#333,stroke-width:2px;
    classDef backend fill:#ffccaa,stroke:#333,stroke-width:2px;
    classDef database fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef external fill:#ffddaa,stroke:#333,stroke-width:2px;
    classDef config fill:#ddddff,stroke:#333,stroke-width:2px;
    classDef deployment fill:#ddccff,stroke:#333,stroke-width:2px;

    %% Click Events for Frontend Pages
    click HomePage "https://github.com/sandeepgarikapati/cleanindia/blob/main/app/page.tsx"
    click CollectionPage "https://github.com/sandeepgarikapati/cleanindia/blob/main/app/collect/page.tsx"
    click LeaderboardPage "https://github.com/sandeepgarikapati/cleanindia/blob/main/app/leaderboard/page.tsx"
    click ReportPage "https://github.com/sandeepgarikapati/cleanindia/blob/main/app/report/page.tsx"
    click RewardsPage "https://github.com/sandeepgarikapati/cleanindia/blob/main/app/rewards/page.tsx"
    click SettingsPage "https://github.com/sandeepgarikapati/cleanindia/blob/main/app/settings/page.tsx"

    %% Click Events for UI Components and Hooks
    click Header "https://github.com/sandeepgarikapati/cleanindia/blob/main/components/Header.tsx"
    click Sidebar "https://github.com/sandeepgarikapati/cleanindia/blob/main/components/Sidebar.tsx"
    click UIWidgets "https://github.com/sandeepgarikapati/cleanindia/tree/main/components/ui"
    click Hooks "https://github.com/sandeepgarikapati/cleanindia/blob/main/hook/useMediaQuerty.ts"

    %% Click Events for Database Layer & ORM
    click DBActions "https://github.com/sandeepgarikapati/cleanindia/blob/main/utils/db/actions.ts"
    click DBConfig "https://github.com/sandeepgarikapati/cleanindia/blob/main/utils/db/dbConfig.jsx"
    click DBSchema "https://github.com/sandeepgarikapati/cleanindia/blob/main/utils/db/schema.ts"
    click Drizzle "https://github.com/sandeepgarikapati/cleanindia/blob/main/drizzle.config.js"

    %% Click Events for Configuration & Utilities
    click GlobalLayout "https://github.com/sandeepgarikapati/cleanindia/blob/main/app/globals.css"
    click BuildConfigs "https://github.com/sandeepgarikapati/cleanindia/blob/main/next.config.mjs"
    click Utilities "https://github.com/sandeepgarikapati/cleanindia/blob/main/lib/utils.ts"
```
