# chunkangwong/miro-clone architecture

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

- Interactive diagram: https://gitdiagram.com/chunkangwong/miro-clone
- Repository: https://github.com/chunkangwong/miro-clone

## Overview

##### Main Components
- Client (Frontend): Represented by the Next.js application. There are two primary pages to highlight:
- Dashboard: Found under app/(dashboard) which includes components for navigation, board cards, sidebars, and various states (empty boards, search, etc.).
- Board: Located in app/boards/[boardId] which contains interactive components related to the board, such as the canvas, drawing tools (ellipse, rectangle, text, cursor, etc.), toolbars, and selection controls.
- API/Authentication: The app/api/liveblocks-auth component indicates a dedicated authentication/API endpoint which likely handles Liveblocks authentication for real-time features.
- Real-Time & Data Backends:
- Liveblocks: Configured by liveblocks.config.ts and plays a role in enabling real-time, collaborative editing.
- Convex: The convex folder (with its generated APIs, server schema, and configuration) is used to manage the data model and server-side logic for persistent data and business operations.
- Supporting Components:
- Shared UI Components: The components directory (with various UI elements like buttons, dialogs, input, etc.) builds on shadcn/ui for a cohesive design system.
- Custom Hooks & Utilities: The hooks folder (and others like lib/utils.ts) encapsulates reusable logic for API mutations, layer deletion, scroll bounce, etc.
- Providers: The providers (or “provders” in the tree) such as convexClientProvider and modalProvider, which handle context and state management across the app.

##### Relationships and Interactions
- The User’s Browser interacts with the Next.js client, which is rendered through the Dashboard and Board pages.
- From the Dashboard, users can navigate into specific boards. This routing is controlled by Next.js’s file-system routing (e.g., page.tsx files) and layouts.
- Within a Board, the various components (canvas, tools, user avatar, etc.) interact to provide a rich drawing and collaboration experience.
- API calls and real-time events: The frontend communicates with:
- Liveblocks endpoints (via app/api/liveblocks-auth) to ensure real-time collaboration.
- Convex functions (through the convex folder’s API and schema) to persist changes and manage collaboration state.
- Custom hooks and providers are used to manage state and side effects, linking the UI components with backend services.

##### Architectural Patterns and Design Principles
- Modular Design: The project is partitioned into a clear separation between the “dashboard” (overview, board listings, navigation) and individual “board” pages (interactive drawing canvas).
- Component Reusability: The extensive use of subdirectories and components (especially under app/(dashboard) and app/boards/[boardId]) shows a high level of component reuse.
- API and Service Separation: Dedicated folders for API endpoints, real-time authentication, and backend logic (Convex) indicate clean separation of concerns.
- Integration of Real-Time and Persistent Data: The use of Liveblocks (for real-time state) alongside Convex (for persistent data) should be clearly indicated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["User Browser"]:::client

    subgraph "Next.js Client"
        DashboardPage["Dashboard Page"]:::client
        DashboardComponents["Dashboard Components"]:::client
        BoardPage["Board Page"]:::client
        BoardComponents["Board Components"]:::client
        Providers["Global Providers"]:::provider
        SharedUI["Shared UI Components"]:::ui
        CustomHooks["Custom Hooks & Utilities"]:::utility
    end

    subgraph "API Service Layer"
        LiveblocksAPI["Liveblocks API Auth"]:::api
        LiveblocksConfig["Liveblocks Config"]:::api
    end

    subgraph "Backend Layer"
        ConvexBackend["Convex Backend Service"]:::backend
    end

    %% Connections from Browser to Client Pages
    Browser -->|"accesses"| DashboardPage
    Browser -->|"accesses"| BoardPage

    %% Connections within Next.js Client
    DashboardPage -->|"uses"| DashboardComponents
    BoardPage -->|"uses"| BoardComponents
    DashboardPage -->|"wrapped by"| Providers
    BoardPage -->|"wrapped by"| Providers
    DashboardPage -->|"integrates"| SharedUI
    BoardPage -->|"integrates"| SharedUI
    DashboardPage -->|"utilizes"| CustomHooks
    BoardPage -->|"utilizes"| CustomHooks

    %% Connections from Client Pages to API Service Layer and Backend
    DashboardPage -->|"calls"| LiveblocksAPI
    BoardPage -->|"calls"| LiveblocksAPI
    DashboardPage -->|"calls"| ConvexBackend
    BoardPage -->|"calls"| ConvexBackend

    %% Internal API Connection
    LiveblocksConfig -->|"configures"| LiveblocksAPI

    %% Styling and Colors
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef api fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef backend fill:#ffcccb,stroke:#000,stroke-width:2px;
    classDef provider fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef ui fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef utility fill:#FFA07A,stroke:#000,stroke-width:2px;

    %% Click Events
    click DashboardPage "https://github.com/chunkangwong/miro-clone/blob/main/app/(dashboard)/page.tsx"
    click DashboardComponents "https://github.com/chunkangwong/miro-clone/tree/main/app/(dashboard)/_components"
    click BoardPage "https://github.com/chunkangwong/miro-clone/blob/main/app/boards/[boardId]/page.tsx"
    click BoardComponents "https://github.com/chunkangwong/miro-clone/tree/main/app/boards/[boardId]/_components"
    click LiveblocksAPI "https://github.com/chunkangwong/miro-clone/blob/main/app/api/liveblocks-auth/route.ts"
    click LiveblocksConfig "https://github.com/chunkangwong/miro-clone/blob/main/liveblocks.config.ts"
    click ConvexBackend "https://github.com/chunkangwong/miro-clone/tree/main/convex"
    click SharedUI "https://github.com/chunkangwong/miro-clone/tree/main/components/ui"
    click CustomHooks "https://github.com/chunkangwong/miro-clone/tree/main/hooks"
    click Providers "https://github.com/chunkangwong/miro-clone/tree/main/provders"
```
