# partykulhad/kulhad architecture

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

- Interactive diagram: https://gitdiagram.com/partykulhad/kulhad
- Repository: https://github.com/partykulhad/kulhad

## Overview

##### Main System Components

A. Frontend Layer:
- Public Routes (/(public))
- Protected Routes (/(private))
- UI Components
- Client-side State Management

B. API Layer:
- Next.js API Routes
- Authentication Middleware
- External API Integrations

C. Data Layer:
- "Convex Database" integration with its collections:
- Users
- Vendors
- Machines
- Delivery Agents
- Kitchens
- IoT Data

D. IoT Integration Layer:
- "IoT Services" showing:
- Canister Level Monitoring
- Machine Data Collection
- QR Code Generation System

##### Specific Implementation Details

Key architectural elements:
**Frontend (Next.js)**
- Public Zone
- Landing Page
- Private Zone
- Dashboard
- Shared Components
- UI Library
- API Integration Layer

**API Routes**
- User Management
- Machine Management
- Vendor Management
- Delivery Management
- IoT Integration

**Convex Database**
- Data Models
- Real-time Subscriptions

**IoT Integration**
- Canister Monitoring
- Machine Telemetry
- QR System

##### Technical Stack Indicators

- Next.js 13+ (App Router)
- Convex Database
- TypeScript
- Tailwind CSS
- IoT Protocols

##### Data Flow Patterns

Key flows:
- User authentication process
- IoT data ingestion
- Delivery agent tracking
- Vendor management
- Kitchen operations

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Frontend Layer"
        CS["Client Side (Next.js App)"]
        PR["Public Routes"]:::frontend
        PVR["Private Routes"]:::frontend
        UI["UI Components"]:::frontend
        CSM["Client State Management"]:::frontend
        DI["Dashboard Interface"]:::frontend
        CP["Client Provider"]:::frontend
    end

    subgraph "API Layer"
        API["Next.js API Routes"]
        AUTH["Authentication"]:::auth
        MIDDLEWARE["API Middleware"]:::auth
        
        subgraph "API Endpoints"
            UM["User Management"]:::api
            VM["Vendor Management"]:::api
            DM["Delivery Management"]:::api
            KO["Kitchen Operations"]:::api
            MM["Machine Management"]:::api
            QR["QR System"]:::api
        end
    end

    subgraph "Data Layer"
        DB[(Convex Database)]
        SCHEMA["Database Schema"]:::db
        
        subgraph "Collections"
            USERS[(Users)]:::db
            VENDORS[(Vendors)]:::db
            MACHINES[(Machines)]:::db
            AGENTS[(Delivery Agents)]:::db
            KITCHENS[(Kitchens)]:::db
            IOT_DATA[(IoT Data)]:::db
        end
    end

    subgraph "IoT Integration Layer"
        IOT["IoT Services"]:::iot
        CLM["Canister Level Monitoring"]:::iot
        MDC["Machine Data Collection"]:::iot
        QRS["QR Code Generation"]:::iot
    end

    %% Connections
    CS --> API
    API --> DB
    IOT --> DB
    AUTH --> DB
    MIDDLEWARE --> AUTH
    CSM --> DB
    
    %% IoT Data Flow
    CLM --> IOT_DATA
    MDC --> IOT_DATA
    QRS --> MACHINES

    %% Component Relationships
    PR --> AUTH
    PVR --> AUTH
    DI --> CSM
    CP --> DB

    %% Style Definitions
    classDef frontend fill:#3b82f6,color:white
    classDef api fill:#22c55e,color:white
    classDef db fill:#eab308,color:white
    classDef iot fill:#ef4444,color:white
    classDef auth fill:#a855f7,color:white

    %% Click Events
    click PR "https://github.com/partykulhad/kulhad/tree/main/app/(public)"
    click PVR "https://github.com/partykulhad/kulhad/tree/main/app/(private)"
    click UI "https://github.com/partykulhad/kulhad/tree/main/components/ui"
    click CP "https://github.com/partykulhad/kulhad/blob/main/app/ConvexClientProvider.tsx"
    click CLM "https://github.com/partykulhad/kulhad/tree/main/app/api/check-canister-levels"
    click MDC "https://github.com/partykulhad/kulhad/tree/main/app/api/machine-data"
    click UM "https://github.com/partykulhad/kulhad/blob/main/convex/users.ts"
    click VM "https://github.com/partykulhad/kulhad/blob/main/convex/vendors.ts"
    click DM "https://github.com/partykulhad/kulhad/blob/main/convex/deliveryAgents.ts"
    click KO "https://github.com/partykulhad/kulhad/blob/main/convex/kitchens.ts"
    click MM "https://github.com/partykulhad/kulhad/blob/main/convex/machines.ts"
    click QR "https://github.com/partykulhad/kulhad/tree/main/app/api/generate-qr"
    click SCHEMA "https://github.com/partykulhad/kulhad/blob/main/convex/schema.ts"
    click AUTH "https://github.com/partykulhad/kulhad/blob/main/convex/auth.config.ts"
    click DI "https://github.com/partykulhad/kulhad/tree/main/app/(private)/dashboard"
```
