# preetam-90/agrkserve architecture

> Architecture diagram of the GitHub repository preetam-90/agrkserve, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/preetam-90/agrkserve
- Repository: https://github.com/preetam-90/agrkserve

## Overview

##### Project Type & Purpose
- Full-stack, server-rendered web application (Next.js App Router)
- Marketplace connecting farmers (“Renters”) with equipment providers and labour services
- Uses Supabase (PostgreSQL + PostGIS) as the primary backend for auth, database, storage, real-time

##### High-Level File Structure Analysis
- src/app/…: Next.js pages & layouts (landing, auth, dashboards for admin/provider/renter/labour)
- src/app/api/…: Next.js API route handlers (serverless functions)
- src/components/: React UI components (layout, landing sections, admin UI, messaging, notifications, primitives)
- src/lib/services/: Business-logic wrappers around Supabase & external services
- src/lib/store/: Zustand state-management stores
- supabase/migrations/: SQL scripts defining database schema & RPCs
- public/: Static assets served via CDN
- scripts/: Dev/ops helper scripts (migrations, env setup, CI)

##### Key Architecture & Data Flows
a. Client Browser
- Renders server- and client-side React pages via Next.js
- Fetches data over Next.js API routes or direct Supabase JS client calls
b. Next.js Server (App Router & API)
- Handles page rendering (SSR/SSG)
- Exposes REST/edge functions in src/app/api/…
- Applies middleware (auth, RLS)
c. Business Logic Layer (src/lib/services)
- Encapsulates CRUD and RPC calls to Supabase
- Implements domain services: auth-service, booking-service, media-service, notification-service, etc.
d. Supabase Backend
- PostgreSQL database with PostGIS extension
- Auth module for email/password, OAuth, phone verification, RLS policies
- Storage buckets for media uploads & chat attachments
- Realtime channels for notifications & direct messaging
e. External Integrations
- Cloudinary for advanced image/video processing (via API routes & service wrappers)
- Vercel (hosting & deployments)

##### Architectural Patterns & Principles
- Jamstack + SSR hybrid: static assets (public/), SSR pages, edgeless API routes
- “API-First” microservices style: each service function lives under src/app/api/…
- Layered separation: UI (components) → state-store (Zustand) → services → database
- Single codebase monorepo with clear module boundaries
- Security via middleware, RLS, separate admin API routes

- Client Browser
- Pages & UI Components
- Zustand store
- Next.js Server
- App Router (SSR & SSG)
- API Routes (serverless functions)
- Middleware (auth, RLS, error handling)
- Business Logic Services
- Auth, Booking, Payment, DM, Notification, Media Audit, etc.
- Supabase
- PostgreSQL + PostGIS
- Auth & RLS
- Storage (uploads)
- Realtime (pub/sub)
- External Services
- Cloudinary API
- Vercel CDN & Functions

- Browser → Next.js App Router (page requests)
- Browser → API Routes (XHR/fetch)
- API Routes → Business Logic → Supabase (queries, RPCs)
- Supabase Realtime → Browser (WebSocket) for notifications & chat
- API Routes ↔ Cloudinary (media operations)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Layer
    subgraph "Browser (Client)" 
        direction TB
        Pages["Pages & UI Components"]:::frontend
        Store["Zustand Store"]:::frontend
        Pages -->|uses| Store
    end

    %% Serverless Environment (Vercel)
    subgraph "Serverless Environment (Vercel)" 
        direction TB
        subgraph "Next.js Server"
            direction TB
            AppRouter["Next.js App Router (Pages & Layouts)"]:::api
            APIRoutes["Next.js API Routes (Serverless Functions)"]:::api
            Middleware["Middleware (Auth, RLS, Error Handling)"]:::api
            AppRouter -->|SSR/SSG| APIRoutes
            APIRoutes --> Middleware
        end

        subgraph "Business Logic Layer"
            direction TB
            Services["Business Logic Services"]:::service
            SupabaseLib["Supabase Client & Middleware"]:::service
            Types["Supabase Types Definitions"]:::service
            Utils["Utility Functions"]:::service
            Hooks["Custom React Hooks"]:::service
            StoreLib["Zustand State Stores"]:::service
            APIRoutes -->|calls| Services
            Services -->|uses| SupabaseLib
            Services -->|types| Types
            Services -->|utils| Utils
            Services -->|hooks| Hooks
        end

        subgraph "Configurations & Scripts"
            direction TB
            NextConfig["next.config.ts"]:::config
            Tailwind["tailwind.config.js & postcss.config.mjs"]:::config
            Scripts["Dev/Ops Helper Scripts"]:::config
            CI["CI/CD Workflows"]:::config
            Docs["README.md & docs/"]:::config
        end
    end

    %% Supabase Backend
    subgraph "Supabase Managed Services"
        direction TB
        DB["PostgreSQL + PostGIS"]:::db
        Auth["Auth & RLS"]:::db
        Storage["Storage (Media Uploads)"]:::db
        Realtime["Realtime (Pub/Sub)"]:::db
        Migrations["Migrations & RPCs"]:::db
        Services -->|queries/RPCs| DB
        Services -->|auth| Auth
        Services -->|storage| Storage
        Realtime -->|WebSocket| Pages
    end

    %% Public Assets
    Public["Static Assets (CDN)"]:::frontend
    Pages -->|assets| Public

    %% External Services
    subgraph "External Integrations"
        direction TB
        Cloudinary["Cloudinary API"]:::external
        VercelHost["Vercel Hosting & CDN"]:::external
        APIRoutes -->|media ops| Cloudinary
        AppRouter -->|deploys| VercelHost
    end

    %% Data Flows
    Pages -->|page requests| AppRouter
    Pages -->|XHR/fetch| APIRoutes

    %% Click Events
    click AppRouter "https://github.com/preetam-90/agrkserve/tree/main/src/app"
    click APIRoutes "https://github.com/preetam-90/agrkserve/tree/main/src/app/api"
    click Pages "https://github.com/preetam-90/agrkserve/tree/main/src/components"
    click Services "https://github.com/preetam-90/agrkserve/tree/main/src/lib/services"
    click StoreLib "https://github.com/preetam-90/agrkserve/tree/main/src/lib/store"
    click Migrations "https://github.com/preetam-90/agrkserve/tree/main/supabase/migrations"
    click SupabaseLib "https://github.com/preetam-90/agrkserve/tree/main/src/lib/supabase"
    click Types "https://github.com/preetam-90/agrkserve/tree/main/src/lib/types"
    click Utils "https://github.com/preetam-90/agrkserve/tree/main/src/lib/utils"
    click Hooks "https://github.com/preetam-90/agrkserve/tree/main/src/lib/hooks"
    click Public "https://github.com/preetam-90/agrkserve/tree/main/public"
    click Scripts "https://github.com/preetam-90/agrkserve/tree/main/scripts"
    click NextConfig "https://github.com/preetam-90/agrkserve/blob/main/next.config.ts"
    click Tailwind "https://github.com/preetam-90/agrkserve/blob/main/tailwind.config.js"
    click CI "https://github.com/preetam-90/agrkserve/blob/main/.github/workflows/ci.yml"
    click Docs "https://github.com/preetam-90/agrkserve/blob/main/README.md"

    %% Styles
    classDef frontend fill:#e0f7e9,stroke:#2e7d32,color:#1b5e20;
    classDef api fill:#e3f2fd,stroke:#1976d2,color:#0d47a1;
    classDef service fill:#fff3e0,stroke:#fb8c00,color:#e65100;
    classDef db fill:#f3e5f5,stroke:#8e24aa,color:#4a148c;
    classDef external fill:#eceff1,stroke:#607d8b,color:#37474f;
    classDef config fill:#f5f5f5,stroke:#9e9e9e,color:#616161;
```
