# davronov-alimardon/canva-clone architecture

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

- Interactive diagram: https://gitdiagram.com/davronov-alimardon/canva-clone
- Repository: https://github.com/davronov-alimardon/canva-clone

## Overview

##### Main Components
a. Frontend Client:
- Next.js App – Organized under the “src/app” directory, which includes separate routes for authentication (sign-in, sign-up) and dashboard functionalities.
- Editor – A dedicated section under “src/features/editor” and “src/app/editor/[projectId]” using multiple UI components and hooks for drawing, image handling, and text functionality.
- UI Components – Found in “src/components” and “src/features/*/components”, representing reusable pieces like buttons, avatars, modals, sidebars, etc.

b. Backend API:
- API Routes – Implemented in “src/app/api” that cover multiple endpoints. Specific API endpoints include:
- General application endpoints (under /[[...route]] with endpoints for AI, images, projects, subscriptions, and users).
- Auth endpoints (managed through the NextAuth route in “src/app/api/auth/[...nextauth]”).
- Upload endpoints (using Uploadthing located in “src/app/api/uploadthing”).

c. Database Layer:
- Drizzle ORM & Migrations – Located in “drizzle” (with SQL migration files) and “src/db” (with the Drizzle setup and schema definitions). This is the core for database interactions.

d. Features and Business Logic:
- Authentication-related features – In “src/features/auth” (components, hooks, utilities for sign-in/up flows).
- Projects and Subscriptions – With their own APIs, hooks, and UI components under “src/features/projects” and “src/features/subscriptions”.
- AI and Images – Found in “src/features/ai” and “src/features/images”, adding image generation and manipulation capabilities.

e. External Services/Integrations:
- Payment processing using Stripe (integration code in “src/lib/stripe”).
- Image service integrations (Unsplash, Replicate, Uploadthing, etc. in “src/lib”).

f. Other Configurations and Tools:
- Global CSS and theme configurations (“src/app/globals.css”, tailwind.config.ts).
- Next.js configurations (e.g., “next.config.mjs”, “tsconfig.json”).
- Environment settings (e.g., “.env.example” for env variables).

##### Relationships and Interactions
- The Frontend renders pages (like the Dashboard and Editor) that call API routes to fetch or update data.
- API endpoints safely orchestrate business logic, handling authentication (via NextAuth), project management, AI image generation, image uploading, and subscriptions.
- The Database layer (managed with Drizzle ORM) underpins persistent storage for user data, projects, templates, and subscription details.
- Integration components (under “src/lib”) wrap third-party services and propagate data to/from API endpoints.
- Components and hooks in “features” interact heavily with the API and database as well as the UX provided by UI components.
- Data flow (e.g., user actions from the Editor, subscriptions, project updates) moves from UI components → custom hooks → API routes → database operations, with results reflected back in the UI.

##### Architectural Patterns & Principles
- Modular and Feature-Driven Structure: Organizing functionality by features (auth, editor, projects, subscriptions) promotes separation of concerns.
- Client-Server Separation: The Next.js app uses both server-rendered pages and API routes, separating frontend view logic from backend business logic.
- Reusable UI Components: The UI is built using a set of atomic components for consistency and reusability.
- Integration with External Services: Encapsulation of third-party integrations in dedicated “src/lib” modules.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Frontend Client
    subgraph "Frontend Client"
        NxtApp["Next.js App"] 
        AuthPage["Authentication Pages & Layouts"]
        Dashboard["Dashboard Components"]
        EditorPage["Editor - Routing and Page"]
        EditorFeatures["Editor Features & UI Components"]
        ReusableUI["Reusable UI Components"]
    end

    %% Backend API
    subgraph "Backend API"
        APIGeneral["API Routes - General Endpoints"]
        APINextAuth["API - NextAuth"]
        APIUploadthing["API - Uploadthing"]
    end

    %% Database Layer
    subgraph "Database Layer"
        DBMigrations["Drizzle ORM & Migrations"]
        DBSchema["Database Setup & Schema"]
    end

    %% External Services
    subgraph "External Services"
        Stripe["Stripe Integration"]
        Replicate["Replicate Integration"]
        Unsplash["Unsplash Integration"]
        UploadthingInt["Uploadthing Integration"]
    end

    %% Features/Business Logic
    subgraph "Features/Business Logic"
        AuthLogic["Authentication Feature Logic"]
        ProjectsLogic["Projects Feature Logic"]
        SubsLogic["Subscriptions Feature Logic"]
        AILogic["AI Feature Logic"]
        ImagesLogic["Images Feature Logic"]
    end

    %% Global Configurations
    subgraph "Global Configurations"
        GlobalConfig["Global Styles & Settings"]
    end

    %% Connections between Frontend and API
    NxtApp -->|"renders"| AuthPage
    NxtApp -->|"renders"| Dashboard
    NxtApp -->|"renders"| EditorPage
    NxtApp -->|"uses"| ReusableUI

    AuthPage -->|"calls"| APINextAuth
    EditorPage -->|"calls"| APIGeneral
    Dashboard -->|"calls"| APIGeneral

    %% Connection within Frontend
    EditorPage -->|"enhanced_by"| EditorFeatures
    EditorFeatures -->|"leverages"| ReusableUI

    %% API to Database interactions
    APIGeneral -->|"CRUD"| DBSchema
    APINextAuth -->|"auth_queries"| DBSchema
    APIUploadthing -->|"upload_ops"| DBSchema

    %% API and External Services
    APIGeneral -->|"integrates_with"| Stripe
    APIGeneral -->|"integrates_with"| Replicate
    APIGeneral -->|"integrates_with"| Unsplash
    APIGeneral -->|"integrates_with"| UploadthingInt

    %% Features/Business Logic interactions
    AuthLogic -->|"supports"| AuthPage
    ProjectsLogic -->|"supports"| EditorPage
    ProjectsLogic -->|"calls"| APIGeneral
    SubsLogic -->|"calls"| APIGeneral
    AILogic -->|"calls"| APIGeneral
    ImagesLogic -->|"calls"| APIGeneral

    %% Global configuration influences Frontend
    GlobalConfig -->|"configures"| NxtApp

    %% Styling
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px;
    classDef api fill:#d4edda,stroke:#333,stroke-width:1px;
    classDef db fill:#f8d7da,stroke:#333,stroke-width:1px;
    classDef external fill:#fff3cd,stroke:#333,stroke-width:1px;
    classDef feature fill:#e2e3e5,stroke:#333,stroke-width:1px;
    classDef config fill:#d1ecf1,stroke:#333,stroke-width:1px;

    class NxtApp,AuthPage,Dashboard,EditorPage,EditorFeatures,ReusableUI frontend;
    class APIGeneral,APINextAuth,APIUploadthing api;
    class DBMigrations,DBSchema db;
    class Stripe,Replicate,Unsplash,UploadthingInt external;
    class AuthLogic,ProjectsLogic,SubsLogic,AILogic,ImagesLogic feature;
    class GlobalConfig config;

    %% Click Events
    click NxtApp "https://github.com/davronov-alimardon/canva-clone/tree/main/src/app"
    click AuthPage "https://github.com/davronov-alimardon/canva-clone/tree/main/src/app/(auth)"
    click Dashboard "https://github.com/davronov-alimardon/canva-clone/tree/main/src/app/(dashboard)"
    click EditorPage "https://github.com/davronov-alimardon/canva-clone/blob/main/src/app/editor/[projectId]/page.tsx"
    click EditorFeatures "https://github.com/davronov-alimardon/canva-clone/tree/main/src/features/editor"
    click ReusableUI "https://github.com/davronov-alimardon/canva-clone/tree/main/src/components"
    click APIGeneral "https://github.com/davronov-alimardon/canva-clone/blob/main/src/app/api/[[...route]]"
    click APINextAuth "https://github.com/davronov-alimardon/canva-clone/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click APIUploadthing "https://github.com/davronov-alimardon/canva-clone/tree/main/src/app/api/uploadthing"
    click DBMigrations "https://github.com/davronov-alimardon/canva-clone/tree/main/drizzle"
    click DBSchema "https://github.com/davronov-alimardon/canva-clone/tree/main/src/db"
    click AuthLogic "https://github.com/davronov-alimardon/canva-clone/tree/main/src/features/auth"
    click ProjectsLogic "https://github.com/davronov-alimardon/canva-clone/tree/main/src/features/projects"
    click SubsLogic "https://github.com/davronov-alimardon/canva-clone/tree/main/src/features/subscriptions"
    click AILogic "https://github.com/davronov-alimardon/canva-clone/tree/main/src/features/ai"
    click ImagesLogic "https://github.com/davronov-alimardon/canva-clone/tree/main/src/features/images"
    click Stripe "https://github.com/davronov-alimardon/canva-clone/blob/main/src/lib/stripe.ts"
    click Replicate "https://github.com/davronov-alimardon/canva-clone/blob/main/src/lib/replicate.ts"
    click Unsplash "https://github.com/davronov-alimardon/canva-clone/blob/main/src/lib/unsplash.ts"
    click UploadthingInt "https://github.com/davronov-alimardon/canva-clone/blob/main/src/lib/uploadthing.ts"
    click GlobalConfig "https://github.com/davronov-alimardon/canva-clone/blob/main/src/app/globals.css"
```
