# tusharchawre/week-22-excelidraw architecture

> Architecture diagram of the GitHub repository tusharchawre/week-22-excelidraw, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tusharchawre/week-22-excelidraw
- Repository: https://github.com/tusharchawre/week-22-excelidraw

## Overview

##### Project Type and Purpose
- The project is a full-stack/monorepo application dedicated to a collaborative drawing environment.
- The frontend (found under apps/excelidraw-frontend) is responsible for rendering the drawing canvas (see canvas/Canvas.tsx and RoomCanvas.tsx), user interfaces (components like Navbar, Footer, etc.) and manages interactive elements.
- Two backends are provided:
– The HTTP backend (apps/http-backend) likely handles RESTful API calls such as user authentication (login, register) and room management.
– The WebSocket backend (apps/ws-backend) facilitates real-time, bidirectional communication crucial for live drawing sessions.
- Shared packages include common utilities, type definitions, and a UI component library that are used across the different apps.

##### File Structure
- Top-level directories such as apps and packages clearly separate concerns: apps contains runtime code (frontend and backend services) while packages hold shared libraries, configurations, and UI components.
- The frontend app structure suggests a Next.js application with pages corresponding to features like signing in, signing up, room creation, and a dashboard.
- The presence of a prisma schema and migration scripts in packages/db indicates the use of an ORM to manage a database, likely storing user or session data.
- The use of Turborepo (turbo.json and pnpm-workspace.yaml) signifies strong build orchestration and modularization across components.

##### README and Assignment
- The README focuses on adding fine-grained interactive features (pencil functionality, panning, and zooming) — these will have implications on the frontend canvas component’s responsibilities and the data exchanged via WebSockets to synchronize drawing actions.
- Although minimal, the assignment implies that the canvas interaction and real-time collaboration are key architectural concerns.

a. Main Components to Include:
- Frontend Application:
– Next.js based, handling UI rendering and drawing interactions.
– Canvas module (for pencil, pan, and zoom functionality).
– Components for authentication, room management, and layout.
- HTTP Backend Service:
– API endpoints for authenticating users, handling room creation, and managing user data.
- WebSocket Backend Service:
– Real-time messaging server facilitating live updates on drawing sessions.
- Database Layer:
– Managed via Prisma (inside packages/db) responsible for persistence (user data, sessions, room data, etc.).
- Shared Packages:
– Common (for shared types and utilities).
– UI (for reusable components that standardize the look and feel across apps).
– Configuration packages (TS and ESLint configs that define the project code standards).

b. Relationships and Interactions:
- The frontend communicates with the HTTP backend for non-real-time operations such as login, register, and room management.
- Simultaneously, it establishes a WebSocket connection to the WS backend to send live drawing events (e.g., pencil strokes, panning, zooming).
- Both backend services can interact with the database to store and retrieve persisted information.
- Shared packages (common types, UI components) are referenced by all applications to ensure consistent behavior and appearance.

c. Architectural Patterns and Design Principles:
- Modular separation: Clear demarcation of responsibilities between frontend, HTTP REST operations, and live WebSocket communication.
- Monorepo management: Using Turborepo and pnpm workspaces to orchestrate builds and streamline dependencies.
- Use of component-based UI design promoting reusability.
- Real-time data flow design to handle collaborative drawing interactions.

d. Relevant Technologies/Frameworks:
- Next.js for the frontend, leveraging its file-based routing and server-side rendering capabilities.
- Node.js (with TypeScript) for both HTTP and WS backends.
- Prisma for database interactions.
- Turborepo/pnpm for build orchestration and dependency management.
- Tailwind CSS (indicated by tailwind.config.js) for styling.
- ESLint and TypeScript configuration packages to ensure code consistency.

##### Elements
- Each component (frontend, HTTP backend, WS backend, Database, and Shared Packages) should be clearly labeled.
– Client request and response flows between the frontend and the HTTP backend.
– Real-time, bidirectional data flow between the frontend and the WS backend.
– Data querying and updating between both backends and the Database layer.
- Annotations to highlight the assignment-specific areas (pencil, pan, zoom functionality) that affect the canvas.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        FE("Frontend Application (Next.js)"):::frontend
        CST("Canvas.tsx"):::frontendSub
        CR("RoomCanvas.tsx"):::frontendSub
        %% Connections within Frontend
        FE -->|"renders"| CST
        FE -->|"renders"| CR
        CST ---|"related"| CR
    end

    %% Application Layer
    subgraph "Application Layer"
        HTTP("HTTP Backend Service"):::backend
        WS("WebSocket Backend Service"):::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        DB("Database (Prisma)"):::database
    end

    %% Shared Packages
    subgraph "Shared Packages"
        CP("Common Utilities & Types"):::shared
        UI("UI Component Library"):::shared
    end

    %% Inter-layer Interactions
    FE -->|"REST_API"| HTTP
    FE -->|"WebSocket"| WS
    HTTP -->|"DB_ops"| DB
    WS -->|"DB_ops"| DB

    %% Dependencies on Shared Packages
    FE ---|"uses"| CP
    FE ---|"uses"| UI
    HTTP ---|"uses"| CP
    WS ---|"uses"| CP

    %% Click Events
    click FE "https://github.com/tusharchawre/week-22-excelidraw/tree/main/apps/excelidraw-frontend/"
    click CST "https://github.com/tusharchawre/week-22-excelidraw/blob/main/apps/excelidraw-frontend/canvas/Canvas.tsx"
    click CR "https://github.com/tusharchawre/week-22-excelidraw/blob/main/apps/excelidraw-frontend/canvas/RoomCanvas.tsx"
    click HTTP "https://github.com/tusharchawre/week-22-excelidraw/blob/main/apps/http-backend/src/index.ts"
    click WS "https://github.com/tusharchawre/week-22-excelidraw/blob/main/apps/ws-backend/src/index.ts"
    click DB "https://github.com/tusharchawre/week-22-excelidraw/blob/main/packages/db/prisma/schema.prisma"
    click CP "https://github.com/tusharchawre/week-22-excelidraw/blob/main/packages/common/src/types.ts"
    click UI "https://github.com/tusharchawre/week-22-excelidraw/tree/main/packages/ui/src/"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef frontendSub fill:#B0E0E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#F08080,stroke:#000,stroke-width:2px;
    classDef database fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef shared fill:#90EE90,stroke:#000,stroke-width:2px;
```
