# sanidhyy/canva-clone architecture

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

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

## Overview

##### Project type and purpose
- This is a full-stack, single-monorepo web application built on Next.js (App Router) with React/TypeScript on the front end, Next.js API routes on the back end, Drizzle ORM + PostgreSQL for data persistence, and several external services (AI via Replicate, image storage via UploadThing, Unsplash for photos, Stripe for billing, OAuth via GitHub/Google).
- The app is a “Canva clone” featuring customizable templates, a Fabric.js-based editor, AI-powered image generation/removal, user authentication, project management, and subscription billing.

##### File structure
- Top-level config and scripts (.env, next.config.mjs, drizzle.config.ts, postcss.config.mjs, tailwind.config.ts, tsconfig.json).
- `drizzle/` folder contains SQL migration scripts and snapshots (Drizzle ORM migrations).
- `public/` holds static assets and JSON template definitions.
- `src/app/` contains Next.js App Router routes:
- `(auth)` and `(dashboard)` layouts and pages for routing between sign-in/up and the dashboard.
- `editor/[projectId]` for the editing canvas.
- `api/` for all Next.js serverless endpoints (`[[...route]]`, `auth`, `uploadthing`).
- Global error, not-found, CSS, layout, etc.
- `src/components/` UI atoms/molecules and providers (Auth, React Query).
- `src/features/` domain modules:
- `ai/`, `auth/`, `editor/`, `images/`, `projects/`, `subscriptions/`.
- `src/lib/` wrappers for external services (hono server, replicate, stripe, unsplash, uploadthing).
- `src/db/` and `drizzle` config/schema for ORM.
- `auth.*` and `middleware.ts` for NextAuth/Hono integration.

##### README for additional insights
- Clearly calls out Tech Stack: React, Next.js, TypeScript, PostgreSQL, Tailwind, Vercel.
- Describes features: Fabric.js editor, AI integration, templates, file upload, OAuth, billing.
- Lists environment variables for external services.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend/UI
    subgraph "Frontend (UI)" 
        direction TB
        Browser["Client (Browser)"]:::ui
        subgraph "Next.js App Router"
            direction TB
            AuthLayout["(auth) Layout & Pages"]:::ui
            DashboardLayout["(dashboard) Layout & Pages"]:::ui
            EditorPage["editor/[projectId] Page"]:::ui
            Layout["layout.tsx"]:::ui
            Styles["globals.css"]:::ui
        end
        subgraph "Shared UI Components"
            direction TB
            UICompDir["src/components/ui/"]:::ui
            ModalProv["modal-provider.tsx"]:::ui
            QueryProv["query-provider.tsx"]:::ui
            Providers["providers.tsx"]:::ui
        end
    end

    %% API Layer
    subgraph "API Layer" 
        direction TB
        Proxy["[[...route]] API Proxy"]:::api
        AuthAPI["NextAuth API Route"]:::api
        UploadAPI["UploadThing API Route"]:::api
    end

    %% Domain Feature Modules
    subgraph "Domain Modules" 
        direction TB
        AI["AI Features (src/features/ai)"]:::domain
        AuthFeat["Auth Features (src/features/auth)"]:::domain
        EditorFeat["Editor Features (src/features/editor)"]:::domain
        ImagesFeat["Images Features (src/features/images)"]:::domain
        ProjectsFeat["Projects Features (src/features/projects)"]:::domain
        SubsFeat["Subscriptions Features (src/features/subscriptions)"]:::domain
    end

    %% Data Layer
    subgraph "Data Access & ORM" 
        direction TB
        DrizzleConf["drizzle.config.ts"]:::db
        DrizzleTS["src/db/drizzle.ts"]:::db
        Schema["src/db/schema.ts"]:::db
        Migrations["drizzle migrations"]:::db
        PostgreSQL["PostgreSQL (Neon)"]:::db
    end

    %% External Services
    subgraph "External Services" 
        direction TB
        ReplicateLib["replicate.ts"]:::external
        UnsplashLib["unsplash.ts"]:::external
        UploadThingLib["uploadthing.ts"]:::external
        StripeLib["stripe.ts"]:::external
        OAuthProv["OAuth Providers (GitHub/Google)"]:::external
    end

    %% Authentication Infrastructure
    subgraph "Auth Infrastructure" 
        direction TB
        NextAuthCfg["auth.config.ts"]:::infra
        AuthTs["src/auth.ts"]:::infra
        Middleware["middleware.ts"]:::infra
    end

    %% Configuration
    subgraph "Global Configuration" 
        direction TB
        NextConfig["next.config.mjs"]:::config
        TailwindCfg["tailwind.config.ts"]:::config
        PostCSSCfg["postcss.config.mjs"]:::config
        TSConfig["tsconfig.json"]:::config
        EnvExample[".env.example"]:::config
    end

    %% Connections
    Browser --> AuthLayout
    Browser --> DashboardLayout
    Browser --> EditorPage
    AuthLayout --> Proxy
    DashboardLayout --> Proxy
    EditorPage --> Proxy
    AuthLayout --> AuthAPI
    DashboardLayout --> AuthAPI
    EditorPage --> UploadAPI

    Proxy --> AI
    Proxy --> ImagesFeat
    Proxy --> ProjectsFeat
    Proxy --> SubsFeat

    AuthAPI --> AuthFeat
    UploadAPI --> UploadThingLib

    AI --> ReplicateLib
    ImagesFeat --> UnsplashLib
    ProjectsFeat --> DrizzleTS
    SubsFeat --> StripeLib

    DrizzleTS --> Schema
    Schema --> PostgreSQL
    Migrations --> PostgreSQL

    Middleware --> AuthAPI
    AuthAPI --> OAuthProv
    AuthFeat --> Middleware

    %% Click Events - UI
    click AuthLayout "https://github.com/sanidhyy/canva-clone/tree/main/src/app/(auth)"
    click DashboardLayout "https://github.com/sanidhyy/canva-clone/tree/main/src/app/(dashboard)"
    click EditorPage "https://github.com/sanidhyy/canva-clone/tree/main/src/app/editor/[projectId]"
    click Layout "https://github.com/sanidhyy/canva-clone/blob/main/src/app/layout.tsx"
    click Styles "https://github.com/sanidhyy/canva-clone/blob/main/src/app/globals.css"
    click UICompDir "https://github.com/sanidhyy/canva-clone/tree/main/src/components/ui/"
    click ModalProv "https://github.com/sanidhyy/canva-clone/blob/main/src/components/modal-provider.tsx"
    click QueryProv "https://github.com/sanidhyy/canva-clone/blob/main/src/components/query-provider.tsx"
    click Providers "https://github.com/sanidhyy/canva-clone/blob/main/src/components/providers.tsx"

    %% Click Events - API
    click Proxy "https://github.com/sanidhyy/canva-clone/blob/main/src/app/api/[[...route]]/route.ts"
    click AuthAPI "https://github.com/sanidhyy/canva-clone/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click UploadAPI "https://github.com/sanidhyy/canva-clone/blob/main/src/app/api/uploadthing/route.ts"

    %% Click Events - Domain
    click AI "https://github.com/sanidhyy/canva-clone/tree/main/src/features/ai"
    click AuthFeat "https://github.com/sanidhyy/canva-clone/tree/main/src/features/auth"
    click EditorFeat "https://github.com/sanidhyy/canva-clone/tree/main/src/features/editor"
    click ImagesFeat "https://github.com/sanidhyy/canva-clone/tree/main/src/features/images"
    click ProjectsFeat "https://github.com/sanidhyy/canva-clone/tree/main/src/features/projects"
    click SubsFeat "https://github.com/sanidhyy/canva-clone/tree/main/src/features/subscriptions"

    %% Click Events - Data
    click DrizzleConf "https://github.com/sanidhyy/canva-clone/blob/main/drizzle.config.ts"
    click DrizzleTS "https://github.com/sanidhyy/canva-clone/blob/main/src/db/drizzle.ts"
    click Schema "https://github.com/sanidhyy/canva-clone/blob/main/src/db/schema.ts"
    click Migrations "https://github.com/sanidhyy/canva-clone/blob/main/drizzle/0000_*.sql"

    %% Click Events - External
    click ReplicateLib "https://github.com/sanidhyy/canva-clone/blob/main/src/lib/replicate.ts"
    click UnsplashLib "https://github.com/sanidhyy/canva-clone/blob/main/src/lib/unsplash.ts"
    click UploadThingLib "https://github.com/sanidhyy/canva-clone/blob/main/src/lib/uploadthing.ts"
    click StripeLib "https://github.com/sanidhyy/canva-clone/blob/main/src/lib/stripe.ts"

    %% Click Events - Auth Infra
    click NextAuthCfg "https://github.com/sanidhyy/canva-clone/blob/main/auth.config.ts"
    click AuthTs "https://github.com/sanidhyy/canva-clone/blob/main/src/auth.ts"
    click Middleware "https://github.com/sanidhyy/canva-clone/blob/main/src/middleware.ts"

    %% Click Events - Config
    click NextConfig "https://github.com/sanidhyy/canva-clone/blob/main/next.config.mjs"
    click TailwindCfg "https://github.com/sanidhyy/canva-clone/blob/main/tailwind.config.ts"
    click PostCSSCfg "https://github.com/sanidhyy/canva-clone/blob/main/postcss.config.mjs"
    click TSConfig "https://github.com/sanidhyy/canva-clone/blob/main/tsconfig.json"
    click EnvExample "https://github.com/sanidhyy/canva-clone/blob/main/.env.example"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef api fill:#E0F7FA,stroke:#00838F,color:#006064
    classDef domain fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32
    classDef db fill:#FFF3E0,stroke:#EF6C00,color:#E65100
    classDef external fill:#FFF8E1,stroke:#F57F17,color:#F57F17
    classDef infra fill:#F3E5F5,stroke:#6A1B9A,color:#4A148C
    classDef config fill:#ECEFF1,stroke:#607D8B,color:#455A64
```
