# mahender-reddy85/dropin architecture

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

- Interactive diagram: https://gitdiagram.com/mahender-reddy85/dropin
- Repository: https://github.com/mahender-reddy85/dropin

## Overview

##### Project type & purpose (what you’re diagramming)
**DropIn** is a **small full-stack web application** for **temporary, code/QR-based file transfer**:
- **Frontend:** static HTML/CSS/JS (drag/drop upload, code display, QR gen/scan).
- **Backend:** Node.js + Express API (upload/download endpoints), uses **Multer** to receive files, generates a **unique 5-digit code** (README says UUID is used in backend deps, likely adapted/shortened), stores **files + metadata on local disk**, and enforces **1-hour expiration**.

- The **browser UI** and its flows (upload, receive, scan).
- The **Express API** and endpoints.
- The **storage model** (uploads dir + metadata dir) and **expiry cleanup**.
- Deployment split: **static hosting (Vercel)** vs **Node server hosting**.

From the tree:

##### Frontend (`frontend/`)
- `index.html` → UI entry point (tabs: send/receive, QR modal/button likely)
- `script.js` → core client logic: calls API, manages progress, QR libraries
- `styles.css` → theming (CSS variables, dark mode)
- `vercel.json` → indicates typical deployment to **Vercel static hosting**

##### Backend (`backend/`)
- `index.js` → single-server entry: Express app, routes, middleware, expiry logic
- `package.json` / lock → deps: Express, Multer, UUID, CORS, etc.

README also references `uploads/` and `metadata/` directories created at runtime.

- REST endpoints (`/api/upload`, `/api/info/:code`, `/api/download/...`)
- File persistence to disk
- Metadata persistence (likely JSON files per code, or a simple store)
- Cleanup/expiry mechanism (timer/cron-like interval, or on-read checks)

##### User Device (Browser)
- Runs: `frontend/index.html + script.js + styles.css`
- QR libs: **QRCode.js** (generate), **Html5-QRCode** (scan)
- Responsibilities: select files, upload with progress, render code/QR, request metadata, download

##### Static Hosting / CDN (Vercel)
- Serves the frontend assets
- `frontend/vercel.json` implies rewrites/headers may exist—worth reflecting if it proxies to backend (check file)

##### Backend API (Node.js / Express)
- `backend/index.js`
- Middleware: **CORS**, **Multer** multipart handling, file size limits
- Responsibilities: code generation, metadata creation, download streaming, expiry enforcement

##### Storage (Local Filesystem)
- `uploads/` directory: actual file blobs
- `metadata/` directory: per-code metadata (filenames, sizes, mime types, timestamps, expiry)
- (If metadata is in-memory instead of disk, show that—but README strongly implies disk)

##### Expiry/Cleanup Worker (logical component)
- deletes expired upload groups after 1 hour
- may run periodically or on each request

##### Backend (Multer): writes files to `uploads/`
3. **Backend → Metadata store**: writes metadata to `metadata/` (includes `code`, file list, createdAt, expiresAt)

##### Download all flow (group)
- If it’s only metadata, keep it as “list”.
- If it creates an archive, show a “zip/pack” step (CPU/IO) inside backend.

##### Expiration flow
- **Cleanup Worker → uploads/ + metadata/**: delete expired entries
- **Backend request path** performing TTL checks (reject/404 expired code)

##### Architectural patterns worth highlighting (specific to this project)
- **Two-tier web app**: Static client + REST API server.
- **Ephemeral storage with TTL**: Files are not permanent; lifecycle management is a core architectural element.

##### Labels
- Use explicit names that match the repo:
- “backend/index.js (Express API)”
- “frontend/script.js (client logic)”
- “uploads/ (file blobs)”
- “metadata/ (JSON metadata by code)”

##### File size limits (Multer limits; mention in component notes)

- **[User Browser]**
- loads → **[Vercel Static Hosting: frontend/]**
- calls → **[Node/Express API: backend/index.js]**
- **[Node/Express API]**
- writes/reads ↔ **[uploads/ (filesystem)]**
- writes/reads ↔ **[metadata/ (filesystem)]**
- runs → **[TTL Cleanup / Expiration]** (logical subcomponent)
- `POST /api/upload (multipart)`
- `GET /api/info/:code (json)`
- `GET /api/download/:code/:filename (stream)`
- `GET /api/download/:code (list/zip?)`

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =========================================================
  %% Diagram 1 — System Context (C4 L1)
  %% =========================================================
  subgraph "System Context (C4 L1)"
    direction TB

    Sender["Sender (User)"]:::actor
    Receiver["Receiver (User)"]:::actor

    subgraph "DropIn (System)"
      direction TB
      DropIn["DropIn: Temporary code/QR-based file transfer"]:::system
    end

    Camera["Browser Camera/MediaDevices\n(QR scan capability)"]:::external
    Internet["Internet (HTTPS)"]:::external
  end

  Sender -->|"uses"| DropIn
  Receiver -->|"uses"| DropIn
  DropIn -->|"relies_on"| Internet
  DropIn -->|"uses_for_QR_scan"| Camera

  %% =========================================================
  %% Diagram 2 — Container Diagram (C4 L2) (Primary)
  %% =========================================================
  subgraph "Container Diagram (C4 L2)"
    direction TB

    subgraph "Client Device (Trust Boundary: Browser)"
      direction TB
      Browser["User Browser\n(static HTML/CSS/JS)"]:::client

      subgraph "Frontend Static App (served assets)"
        direction TB
        FE_HTML["frontend/index.html\n(UI entry: send/receive tabs, QR modal)"]:::frontend
        FE_JS["frontend/script.js\n(Client logic: upload/receive, progress, QR gen/scan)"]:::frontend
        FE_CSS["frontend/styles.css\n(Theme, CSS vars, dark mode)"]:::frontend

        QRGen["QRCode.js\n(QR generation)"]:::lib
        QRScan["Html5-QRCode\n(QR scanning)"]:::lib
      end
    end

    subgraph "Static Hosting / CDN (Trust Boundary: Vercel)"
      direction TB
      Vercel["Vercel Static Hosting/CDN\n(serves frontend/)"]:::hosting
      VercelCfg["frontend/vercel.json\n(rewrites/headers; may proxy API)"]:::config
    end

    subgraph "Backend Hosting (Trust Boundary: Node Host)"
      direction TB
      API["Node.js + Express API\nbackend/index.js"]:::api

      subgraph "Backend Runtime (Logical Components)"
        direction TB
        CORS["CORS Middleware"]:::component
        Multer["Multer Multipart Handler\n(file size limits)"]:::component
        CodeGen["5-digit Code Generator\n(UUID-derived or random)"]:::component
        TTLCheck["Expiration Validator\n(1-hour TTL checks on requests)"]:::component
        MetaMgr["Metadata Manager\n(read/write per-code JSON)"]:::component
        Streamer["Download/Streaming Handler"]:::component
        Cleanup["TTL Cleanup Worker\n(interval/cron-like)"]:::worker
      end

      subgraph "Local Filesystem Storage (No DB)"
        direction TB
        Uploads[("uploads/\n(file blobs)")]:::datastore
        Metadata[("metadata/\n(JSON metadata by code)")]:::datastore
      end

      BackendDeps["backend/package.json\n(Express, Multer, UUID, CORS, etc.)"]:::config
      BackendLock["backend/package-lock.json"]:::config
      BackendIgnore["backend/.gitignore\n(runtime artifacts: uploads/metadata)"]:::config
    end

    Docs["README.md\n(Architecture + API description)"]:::doc

    %% Relationships: hosting + asset delivery
    Vercel -->|"serves_static_assets"| Browser
    VercelCfg -->|"configures"| Vercel

    %% Frontend runtime relationships
    Browser -->|"loads"| FE_HTML
    FE_HTML -->|"loads"| FE_CSS
    FE_HTML -->|"loads"| FE_JS
    FE_JS -->|"uses"| QRGen
    FE_JS -->|"uses"| QRScan

    %% API calls (key flows)
    Browser -->|"POST_/api/upload\nmultipart/form-data files[]"| API
    Browser -->|"GET_/api/info/:code\napplication/json"| API
    Browser -->|"GET_/api/download/:code/:filename\nstream (octet-stream)"| API
    Browser -->|"GET_/api/download/:code\n(list_or_zip?)"| API

    %% Backend internal wiring
    API -->|"applies"| CORS
    API -->|"parses_uploads_with"| Multer
    API -->|"generates"| CodeGen
    API -->|"validates"| TTLCheck
    API -->|"reads/writes"| MetaMgr
    API -->|"streams_files_via"| Streamer
    API -->|"schedules"| Cleanup

    %% Persistence
    Multer -->|"writes"| Uploads
    MetaMgr -->|"writes/reads"| Metadata
    Streamer -->|"reads"| Uploads

    %% Expiration behavior
    TTLCheck -->|"rejects_expired_code"| API
    Cleanup -->|"deletes_expired"| Uploads
    Cleanup -->|"deletes_expired"| Metadata

    %% Notes about deployment uncertainty (from repo guidance)
    ProxyNote["Note: API domain vs Vercel proxy\n(confirm in frontend/vercel.json)"]:::note
    ZipNote["Note: /api/download/:code behavior\n(confirm: list vs zip archive?)"]:::note
    VercelCfg -->|"affects"| ProxyNote
    API -->|"implements"| ZipNote

    %% Docs and configs
    BackendDeps -->|"declares_deps_for"| API
    BackendLock -->|"locks_deps_for"| API
    BackendIgnore -->|"ignores_runtime_dirs"| Uploads
    BackendIgnore -->|"ignores_runtime_dirs"| Metadata
    Docs -->|"documents"| API
    Docs -->|"documents"| Vercel
  end

  %% =========================================================
  %% Diagram 3 — Backend Component Diagram (C4 L3) for backend/index.js
  %% =========================================================
  subgraph "Backend Components (C4 L3) — backend/index.js (Logical View)"
    direction TB

    Entry["Express App Init\n(listen, middleware, routes)"]:::api

    subgraph "Routing Layer"
      direction TB
      RUpload["POST /api/upload"]:::route
      RInfo["GET /api/info/:code"]:::route
      RDownload1["GET /api/download/:code/:filename"]:::route
      RDownloadAll["GET /api/download/:code\n(list_or_zip?)"]:::route
    end

    subgraph "Handlers & Services"
      direction TB
      UploadHandler["Upload Handler\n(Multer + validation)"]:::component
      CodeService["Code Service\n(5-digit capability token)"]:::component
      MetadataService["Metadata Service\n(JSON persistence)"]:::component
      DownloadHandler["Download Handler\n(stream response)"]:::component
      TTLService["TTL Service\n(expiresAt enforcement)"]:::component
      CleanupScheduler["Cleanup Scheduler\n(periodic deletion)"]:::worker
    end

    subgraph "Data Stores (Filesystem)"
      direction TB
      DSUploads[("uploads/")]:::datastore
      DSMetadata[("metadata/")]:::datastore
    end

    Entry -->|"registers"| RUpload
    Entry -->|"registers"| RInfo
    Entry -->|"registers"| RDownload1
    Entry -->|"registers"| RDownloadAll

    RUpload -->|"calls"| UploadHandler
    UploadHandler -->|"uses"| CodeService
    UploadHandler -->|"writes_files"| DSUploads
    UploadHandler -->|"writes_metadata"| MetadataService
    MetadataService -->|"persists_to"| DSMetadata

    RInfo -->|"calls"| TTLService
    TTLService -->|"reads_metadata"| MetadataService
    MetadataService -->|"reads_from"| DSMetadata

    RDownload1 -->|"calls"| TTLService
    RDownload1 -->|"calls"| DownloadHandler
    DownloadHandler -->|"reads_file"| DSUploads

    RDownloadAll -->|"calls"| TTLService
    RDownloadAll -->|"calls"| MetadataService

    Entry -->|"starts"| CleanupScheduler
    CleanupScheduler -->|"deletes_expired"| DSUploads
    CleanupScheduler -->|"deletes_expired"| DSMetadata
  end

  %% =========================================================
  %% Click Events (from component_mapping)
  %% =========================================================
  click FE_HTML "https://github.com/mahender-reddy85/dropin/blob/main/frontend/index.html"
  click FE_JS "https://github.com/mahender-reddy85/dropin/blob/main/frontend/script.js"
  click FE_CSS "https://github.com/mahender-reddy85/dropin/blob/main/frontend/styles.css"
  click VercelCfg "https://github.com/mahender-reddy85/dropin/blob/main/frontend/vercel.json"
  click API "https://github.com/mahender-reddy85/dropin/blob/main/backend/index.js"
  click BackendDeps "https://github.com/mahender-reddy85/dropin/blob/main/backend/package.json"
  click BackendLock "https://github.com/mahender-reddy85/dropin/blob/main/backend/package-lock.json"
  click BackendIgnore "https://github.com/mahender-reddy85/dropin/blob/main/backend/.gitignore"
  click Docs "https://github.com/mahender-reddy85/dropin/blob/main/README.md"

  %% =========================================================
  %% Styles
  %% =========================================================
  classDef actor fill:#FDE68A,stroke:#B45309,stroke-width:1px,color:#111827
  classDef system fill:#A7F3D0,stroke:#065F46,stroke-width:1px,color:#064E3B
  classDef external fill:#E5E7EB,stroke:#6B7280,stroke-width:1px,color:#111827
  classDef client fill:#BFDBFE,stroke:#1D4ED8,stroke-width:1px,color:#0F172A
  classDef frontend fill:#93C5FD,stroke:#1D4ED8,stroke-width:1px,color:#0B1220
  classDef hosting fill:#C7D2FE,stroke:#4338CA,stroke-width:1px,color:#111827
  classDef api fill:#60A5FA,stroke:#1E40AF,stroke-width:2px,color:#071A2B
  classDef component fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#0F172A
  classDef route fill:#BAE6FD,stroke:#0284C7,stroke-width:1px,color:#0F172A
  classDef datastore fill:#86EFAC,stroke:#166534,stroke-width:2px,color:#052E16
  classDef worker fill:#FDBA74,stroke:#C2410C,stroke-width:2px,stroke-dasharray:5 3,color:#111827
  classDef lib fill:#DDD6FE,stroke:#6D28D9,stroke-width:1px,color:#111827
  classDef config fill:#FBCFE8,stroke:#9D174D,stroke-width:1px,color:#111827
  classDef doc fill:#FEF08A,stroke:#A16207,stroke-width:1px,color:#111827
  classDef note fill:#F3F4F6,stroke:#6B7280,stroke-width:1px,stroke-dasharray:3 3,color:#111827
```
