# rohanshrma222/inksync architecture

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

- Interactive diagram: https://gitdiagram.com/rohanshrma222/inksync
- Repository: https://github.com/rohanshrma222/inksync

## Overview

##### Project type and purpose
- This is a TypeScript‐based Turborepo monorepo hosting a full-stack, collaborative canvas application.
- It consists of three “apps”:
- `main-frontend` – a Next.js React app for the UI (sign-in, sign-up, room selection, drawing canvas).
- `http-backend` – a Node/Express (or similar) HTTP API for authentication, user management, room metadata, and database interactions.
- `ws-backend` – a WebSocket server that handles real-time drawing events in each room.
- Shared code lives under `packages/` (common types, Prisma DB layer, shared UI, lint/ts configs).

##### File structure
- Top-level `apps/`: three deployments
- Each has its own `package.json` and `tsconfig` → independent services.
- `main-frontend` contains Next.js pages under `app/` and reusable React components under `components/`.
- `http-backend` exposes REST endpoints (`src/index.ts`, `middleware.ts`).
- `ws-backend` exposes WebSocket endpoints (`src/index.ts`).
- `packages/` contains:
- `common` – shared TypeScript types.
- `backend-common` – shared server utilities (error handling, middleware).
- `db` – Prisma schema + migrations + database client.
- `ui` – shared React UI library.
- `eslint-config`, `typescript-config` – repo-wide linting and TS settings.
- `docker/` folder with three Dockerfiles → containerization of each app.
- CI/CD pipelines in `.github/workflows` for each app → separate build/deploy jobs.

##### README for additional insights
- The generic Turborepo README doesn’t describe this custom canvas app, but confirms the use of Next.js, TypeScript, ESLint, Prettier, and remote caching via Turborepo.

a. Main components:
- User’s Browser (UI)
- Next.js Frontend (`main-frontend`)
- HTTP API Server (`http-backend`)
- WebSocket Server (`ws-backend`)
- Database (PostgreSQL via Prisma in `packages/db`)
- Shared Libraries (Type definitions, UI components, backend utilities)
- CI/CD Platform (GitHub Actions + Turborepo caching)
- Container Registry / Deployment Platform (e.g., Docker Hub, Kubernetes, Vercel)

b. Relationships and interactions:
- Browser ←→ Next.js Frontend (HTTP + SSR)
- Frontend → HTTP API Server (REST for login, room list, save/load canvas state)
- Frontend ↔ WS Server (WebSocket for real-time drawing events)
- HTTP Server ↔ Database (Prisma ORM for user/room meta)
- WS Server ↔ Database (optionally, for persisting drawing logs)
- Apps share code by importing from `packages/`
- CI/CD pushes built Docker images from each `dockerfile.*` to the registry and deploys them.

c. Architectural patterns & design principles:
- Micro-services style: separate deployable units for HTTP and WS
- Monorepo code-sharing via Turborepo & pnpm workspaces
- Layered separation: UI layer, API layer, real-time layer, persistence layer
- Shared type safety (TypeScript across all layers)

d. Key technologies/frameworks:
- Next.js (React, app router)
- Node.js with TypeScript for both backends
- WebSocket (e.g., ws or socket.io)
- Prisma ORM + PostgreSQL
- Turborepo for monorepo task orchestration & caching
- pnpm workspaces
- GitHub Actions for CI/CD
- Docker for containerization

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "Web UI"
        Browser["User Browser"]:::ui
        Next["Next.js Frontend"]:::ui
    end

    subgraph "API Layer"
        HTTP["HTTP API Server"]:::api
    end

    subgraph "Realtime Layer"
        WS["WebSocket Server"]:::realtime
    end

    subgraph "Data Layer"
        DB["PostgreSQL Database"]:::db
    end

    subgraph "Shared Packages"
        common["common"]:::shared
        backendCommon["backend-common"]:::shared
        dbPackage["db"]:::shared
        uiPkg["ui"]:::shared
        eslintCfg["eslint-config"]:::shared
        tsConfig["typescript-config"]:::shared
    end

    CI["CI/CD Pipeline"]:::ci
    Registry["Container Registry"]:::ci

    %% Interactions
    Browser <--> Next
    Next -->|REST API| HTTP
    Next <-->|WebSocket| WS
    HTTP -->|Prisma ORM| DB
    WS -->|Optional persistence| DB

    %% Code-sharing
    common -.-> Next
    common -.-> HTTP
    common -.-> WS

    backendCommon -.-> HTTP
    backendCommon -.-> WS

    dbPackage -.-> HTTP
    dbPackage -.-> WS

    uiPkg -.-> Next

    eslintCfg -.-> Next
    eslintCfg -.-> HTTP
    eslintCfg -.-> WS

    tsConfig -.-> Next
    tsConfig -.-> HTTP
    tsConfig -.-> WS

    %% DevOps
    CI -. thick dashed .-> Registry
    CI -->|"build docker images"| Next
    CI -->|"build docker images"| HTTP
    CI -->|"build docker images"| WS

    %% Click Events
    click Next "https://github.com/rohanshrma222/inksync/tree/main/apps/main-frontend"
    click HTTP "https://github.com/rohanshrma222/inksync/blob/main/apps/http-backend/src/index.ts"
    click WS "https://github.com/rohanshrma222/inksync/blob/main/apps/ws-backend/src/index.ts"
    click common "https://github.com/rohanshrma222/inksync/blob/main/packages/common/src/types.ts"
    click backendCommon "https://github.com/rohanshrma222/inksync/blob/main/packages/backend-common/src/index.ts"
    click dbPackage "https://github.com/rohanshrma222/inksync/tree/main/packages/db"
    click uiPkg "https://github.com/rohanshrma222/inksync/tree/main/packages/ui/src/"
    click eslintCfg "https://github.com/rohanshrma222/inksync/tree/main/packages/eslint-config"
    click tsConfig "https://github.com/rohanshrma222/inksync/tree/main/packages/typescript-config"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#3399ff,color:#03396c;
    classDef api fill:#d4edda,stroke:#28a745,color:#155724;
    classDef realtime fill:#fff3cd,stroke:#ffcc00,color:#856404;
    classDef db fill:#f5e1da,stroke:#a52a2a,color:#4b2e2e;
    classDef ci fill:#e2e3e5,stroke:#6c757d,color:#343a40;
    classDef shared fill:#e8daef,stroke:#8e44ad,color:#4a235a;
```
