# 0mkarbhosale07/lemon-click architecture

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

- Interactive diagram: https://gitdiagram.com/0mkarbhosale07/lemon-click
- Repository: https://github.com/0mkarbhosale07/lemon-click

## Overview

##### Main Components
- Client/Frontend: Represented by the Next.js pages found under src/app (e.g., home page, about, pricing, policies, checkout, admin, dashboard, public pages). This forms the user interface layer.
- API / Backend Services: Located in src/app/api, these endpoints handle authentication (using NextAuth), payment updates, sending emails, and stats. Mark these as a separate service layer that exposes RESTful (or similar) endpoints.
- Domain Logic & Business Services: The src/actions folder (with multiple actions like for admin, profile, payment, etc.) encapsulates business logic. Also include the models (under src/models) that define the structure for coupons, creators, links, payments, profiles, reports, webhooks, and users.
- Utility & Shared Components: Libraries, hooks (src/hooks), and utility functions (src/lib/utils.ts) form cross-cutting concerns. Additionally, shared UI components (under src/components and src/components/ui) are important in building the visual interface.
- Deployment/Configuration: Files like vercel.json, next.config.mjs, and configuration for tailwind (tailwind.config.ts) indicate deployment and theming configuration. Also include external integrations such as Vercel for hosting and potential NextAuth configurations.
- Emails: The emails folder (with WelcomeEmail.tsx) suggests a subsystem for email templating/notifications.

##### Relationships and Interactions
- API endpoints call business logic (from src/actions) and interact with the database layer (via src/db.ts or src/lib/db.ts) as well as models.
- The admin and dashboard areas (separated in the file tree under src/app/(admin) and src/app/(dashboard)) are integral frontend components that might also have their own dedicated API calls and have distinct user role-based flows.

##### Architectural Patterns and Technologies
- File-Based Routing: Next.js automatically handles routes via the src/app directory.
- Component-Based Architecture: The UI is built using React components (many stored under src/components and src/components/ui) with state management and theming potentially controlled by hooks and providers (src/components/theme-provider.tsx).
- API Routes: Serverless functions (e.g., authentication and payment-update endpoints) are a key part of the backend.
- MVC-like Separation: Although Next.js blends view and API routes, the separation of concerns is maintained with well-organized folders for actions (business logic), models (data structure), and views (React components).
- Use of TypeScript: Indicated by .ts and .tsx files for strong typing, a key consideration in understanding the code base.
- Tailwind CSS & PostCSS: Styling is handled via Tailwind (tailwind.config.ts, postcss.config.mjs), so include a note on front-end theming and design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Client/Browser"]:::client

    subgraph "Frontend Layer"
        F1["Next.js Pages (src/app)"]:::frontend
        F2["UI Components (src/components)"]:::frontend
        F3["UI Components (src/components/ui)"]:::frontend
    end

    subgraph "API & Backend Services"
        B1["API Endpoints (src/app/api)"]:::backend
    end

    subgraph "Business Logic Layer"
        BL1["Actions (src/actions)"]:::business
        BL2["Data Models (src/models)"]:::business
    end

    subgraph "Data Persistence"
        DP1["Database (src/db.ts)"]:::database
        DP2["Database Lib (src/lib/db.ts)"]:::database
    end

    subgraph "Utility & Shared Components"
        U1["Hooks (src/hooks)"]:::utility
        U2["Utility Functions (src/lib/utils.ts)"]:::utility
    end

    subgraph "Deployment & Configuration"
        C1["next.config.mjs"]:::config
        C2["vercel.json"]:::config
        C3["tailwind.config.ts"]:::config
        C4["postcss.config.mjs"]:::config
    end

    subgraph "Email Service"
        E1["Welcome Email Template (emails/WelcomeEmail.tsx)"]:::email
    end

    A -->|"HTTP/AJAX"| F1
    F1 -->|"API_call"| B1
    F1 -->|"uses"| U1
    F1 -->|"uses"| U2
    B1 -->|"calls"| BL1
    BL1 -->|"uses_models"| BL2
    BL1 -->|"CRUD_ops"| DP1
    BL1 -->|"CRUD_ops"| DP2
    BL1 -->|"triggers_email"| E1

    %% Click Events
    click F1 "https://github.com/0mkarbhosale07/lemon-click/tree/main/src/app"
    click F2 "https://github.com/0mkarbhosale07/lemon-click/tree/main/src/components"
    click F3 "https://github.com/0mkarbhosale07/lemon-click/tree/main/src/components/ui"
    click B1 "https://github.com/0mkarbhosale07/lemon-click/tree/main/src/app/api"
    click BL1 "https://github.com/0mkarbhosale07/lemon-click/tree/main/src/actions"
    click BL2 "https://github.com/0mkarbhosale07/lemon-click/tree/main/src/models"
    click DP1 "https://github.com/0mkarbhosale07/lemon-click/blob/main/src/db.ts"
    click DP2 "https://github.com/0mkarbhosale07/lemon-click/blob/main/src/lib/db.ts"
    click U1 "https://github.com/0mkarbhosale07/lemon-click/tree/main/src/hooks"
    click U2 "https://github.com/0mkarbhosale07/lemon-click/blob/main/src/lib/utils.ts"
    click C1 "https://github.com/0mkarbhosale07/lemon-click/blob/main/next.config.mjs"
    click C2 "https://github.com/0mkarbhosale07/lemon-click/blob/main/vercel.json"
    click C3 "https://github.com/0mkarbhosale07/lemon-click/blob/main/tailwind.config.ts"
    click C4 "https://github.com/0mkarbhosale07/lemon-click/blob/main/postcss.config.mjs"
    click E1 "https://github.com/0mkarbhosale07/lemon-click/blob/main/emails/WelcomeEmail.tsx"

    %% Styles
    classDef client fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef frontend fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
    classDef backend fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef business fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef database fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef utility fill:#FAD7A0,stroke:#F39C12,stroke-width:2px;
    classDef config fill:#E5E7E9,stroke:#85929E,stroke-width:2px;
    classDef email fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
```
