# elazzouzihassan/imageeditor architecture

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

- Interactive diagram: https://gitdiagram.com/elazzouzihassan/imageeditor
- Repository: https://github.com/elazzouzihassan/imageeditor

## Overview

##### Project type and purpose
- SmartCanvas AI Editor is a full-stack, SaaS image-editing platform.
- Frontend: Next.js (App Router, TypeScript, Tailwind CSS, Shadcn/ui).
- Backend: Bun-powered Next.js API routes.
- Database: MongoDB via Mongoose.
- External services: Clerk (authentication), Cloudinary (AI image processing), Stripe (billing/webhooks).

##### File structure
- Top-level “app” folder: Next.js App Router pages and API routes (`app/api/webhooks/clerk`, `app/api/webhooks/stripe`).
- “components” and “components/ui”: UI layer, shared React components and design system.
- “lib”: domain logic – `actions/` (business operations), `database/` (mongoose models & connection), `utils.ts`.
- Config files: `next.config.mjs`, `tsconfig.json`, `tailwind.config.ts`, `middleware.ts`.
- “constants” and “types”: global constants and TypeScript definitions.

##### Key insights from README
- Features: auth, image upload/gallery, advanced AI editing tools.
- Architecture call-out: main app → Clerk → MongoDB → Cloudinary.

##### Main components
a. Client (Browser)
b. Next.js Frontend (UI) & Server (App Router + API routes)
c. Authentication service (Clerk)
d. Business-logic layer (`lib/actions`)
e. Data-access layer (Mongoose + MongoDB)
f. External AI service (Cloudinary)
g. Payment service (Stripe)

##### Relationships and data flows
- User interacts with the Next.js UI.
- UI invokes Clerk for sign-in/sign-up flows.
- Authenticated requests hit Next.js API routes (e.g., `/api/webhooks/...`, `/api/...`).
- API handlers call `lib/actions` to orchestrate operations.
- Data-access calls go through Mongoose to MongoDB.
- Image-processing actions call Cloudinary’s REST API.
- Stripe webhook endpoints in Next.js receive events (billing, subscriptions).

##### Architectural patterns and design principles
- Monolithic full-stack using Next.js App Router – co-located UI + API routes.
- Layered architecture:
- Presentation (React/Next.js pages)
- Application (API handlers + actions)
- Data (Mongoose models + MongoDB)
- External service integration via well-defined adapters (Cloudinary, Clerk, Stripe).
- Use of middleware (`middleware.ts`) for cross-cutting (e.g., auth guard).

##### Technologies and frameworks to annotate
- Next.js (App Router)
- Bun runtime
- React + Shadcn/ui + TypeScript
- Tailwind CSS
- Mongoose + MongoDB
- Clerk SDK
- Cloudinary REST API
- Stripe Webhooks

##### Essential elements to capture
- API entry points (`app/api/...`) and middleware for authentication.
- React pages under `app/(root)` and `app/(auth)` showing public vs. protected routes.
- `lib/database/mongoose.ts` as the DB connection initializer.
- Webhook handlers for Clerk & Stripe as separate entry points.
- Cloudinary calls embedded in `lib/actions/image.actions.ts`.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client"
        direction TB
        Browser["User Browser"]:::internal
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        UI["Next.js UI (App Router)"]:::internal
        ClerkUI["Authentication UI (Clerk)"]:::auth
        SharedComp["Shared React Components"]:::ui
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        API["Next.js API Routes"]:::internal
        MW["Middleware (middleware.ts)"]:::internal
        ImageActions["Image Actions"]:::internal
        TransactionActions["Transaction Actions"]:::internal
        UserActions["User Actions"]:::internal
        Utils["Utils (lib/utils.ts)"]:::utils
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MongooseConn["Mongoose Connector (lib/database/mongoose.ts)"]:::db
        UserModel["User Model (user.model.ts)"]:::db
        ImageModel["Image Model (image.model.ts)"]:::db
        TransactionModel["Transaction Model (transaction.model.ts)"]:::db
        MongoDB["MongoDB"]:::db
    end

    %% External Services
    subgraph "External Services"
        direction TB
        ClerkService["Clerk Auth Service"]:::auth
        Cloudinary["Cloudinary AI Service"]:::ai
        StripeService["Stripe Payment Service"]:::payment
    end

    %% Connections
    Browser --> UI
    UI --> ClerkUI
    ClerkUI --> ClerkService
    UI -->|"Authenticated Request"| API
    API --> MW
    MW --> ImageActions
    MW --> TransactionActions
    MW --> UserActions
    ImageActions --> UserModel
    ImageActions --> ImageModel
    TransactionActions --> TransactionModel
    UserActions --> UserModel
    UserActions --> ImageModel
    ImageActions --> Cloudinary
    ImageActions --> MongooseConn
    TransactionActions --> MongooseConn
    UserActions --> MongooseConn
    MongooseConn --> MongoDB
    UserModel --> MongooseConn
    ImageModel --> MongooseConn
    TransactionModel --> MongooseConn
    StripeService --> API
    ClerkService --> API

    %% Click Events
    click UI "https://github.com/elazzouzihassan/imageeditor/blob/main/app/(root)/layout.tsx"
    click ClerkUI "https://github.com/elazzouzihassan/imageeditor/blob/main/app/(auth)/sign-in/[[...sign-in]]/page.tsx"
    click SharedComp "https://github.com/elazzouzihassan/imageeditor/tree/main/components/shared/"
    click API "https://github.com/elazzouzihassan/imageeditor/blob/main/app/api/webhooks/clerk/route.ts"
    click API "https://github.com/elazzouzihassan/imageeditor/blob/main/app/api/webhooks/stripe/route.ts"
    click MW "https://github.com/elazzouzihassan/imageeditor/blob/main/middleware.ts"
    click ImageActions "https://github.com/elazzouzihassan/imageeditor/blob/main/lib/actions/image.actions.ts"
    click TransactionActions "https://github.com/elazzouzihassan/imageeditor/blob/main/lib/actions/transaction.actions.ts"
    click UserActions "https://github.com/elazzouzihassan/imageeditor/blob/main/lib/actions/user.actions.ts"
    click Utils "https://github.com/elazzouzihassan/imageeditor/blob/main/lib/utils.ts"
    click MongooseConn "https://github.com/elazzouzihassan/imageeditor/blob/main/lib/database/mongoose.ts"
    click UserModel "https://github.com/elazzouzihassan/imageeditor/blob/main/lib/database/models/user.model.ts"
    click ImageModel "https://github.com/elazzouzihassan/imageeditor/blob/main/lib/database/models/image.model.ts"
    click TransactionModel "https://github.com/elazzouzihassan/imageeditor/blob/main/lib/database/models/transaction.model.ts"

    %% Styles
    classDef internal fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef auth fill:#d4edda,stroke:#333,stroke-width:1px
    classDef payment fill:#d4edda,stroke:#333,stroke-width:1px
    classDef ai fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef db fill:#ececec,stroke:#333,stroke-width:1px
    classDef utils fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef ui fill:#e2f0fb,stroke:#333,stroke-width:1px
```
