# ananth-swamy/discord-storage architecture

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

- Interactive diagram: https://gitdiagram.com/ananth-swamy/discord-storage
- Repository: https://github.com/ananth-swamy/discord-storage

## Overview

##### Project type and purpose
- This is a full-stack web application ("Discord Storage") that lets users upload/download files via a Discord bot, using PocketBase as a metadata store.
- Key indicators:
- `frontend/` contains a React app (Vite, Tailwind).
- `backend/` holds Node.js scripts (`commands.js`, `index.js`) and env config.
- `pocketbase/` folder runs a local PocketBase server for persistent storage.
- README describes steps to wire up Discord, run PocketBase, start backend, then frontend.

##### File structure
- Top-level directories:
- frontend – React components, Vite config, styles.
- backend – Node.js bot commands and Express/Koa HTTP server (likely in `index.js`).
- pocketbase – embedded Go-based database server with migrations.
- preview – static screenshot for documentation.
- Patterns: Simple two-tier service: presentation (React) → application (Node.js) → data (PocketBase + Discord API).

##### Extract architecture details from the README
- The README calls out three runtime processes: PocketBase server, backend Node.js (bot + API), and frontend dev server.
- External dependency: Discord Developer Bot (REST/WebSocket API) used by backend.
- Data flows:
- User uploads file in browser → frontend POST to backend → backend splits chunks and stores as Discord messages + metadata in PocketBase.
- User requests file → backend re-assembles chunks from Discord and returns to frontend.

##### Main components & their interactions
a. Frontend (React/Vite)
- Serves UI for file upload/download.
- Calls backend HTTP endpoints (e.g., `/upload`, `/download`).
b. Backend (Node.js)
- HTTP API (Express or similar) exposed on localhost (default port from `index.js`).
- Discord Bot client (via `commands.js`) that:
- Listens for file-storage commands.
- Uploads file chunks to a Discord channel.
- Interacts with PocketBase SDK to store/retrieve file metadata (chunk IDs, order).
c. PocketBase (embedded Go service)
- Stores metadata collections (“files”, chunk mapping).
- Exposes its own REST API on `http://127.0.0.1:8090/_/`.
d. External service – Discord API
- Bot uses Discord REST/WebSocket to store and fetch message attachments as file chunks.

##### Key architectural patterns and design principles
- Three-tier architecture: Presentation, Application, Data.
- Separation of concerns:
- Frontend focuses solely on UI and HTTP integration.
- Backend encapsulates business logic: chunking, Discord bot commands, metadata orchestration.
- PocketBase is pure storage for metadata, not file blobs.
- Extensibility: You could swap PocketBase for another DB or swap Discord for any file-hosting API by abstracting the storage adapter in the backend.

- Three running processes (containers or local services):
- pocketbase:8090
- backend:3000 (or as configured)
- frontend:5173

##### Final checklist
- Components: Frontend, Backend, PocketBase, Discord.
- Patterns: Three-tier separation, external service adapter.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Local Dev Environment"
        direction TB
        ReactApp["React App (Vite/Tailwind UI)"]:::frontend
        subgraph "Node.js API & Discord Bot"
            direction TB
            API["HTTP API (upload/download endpoints)"]:::backend
            Bot["Discord Bot (chunking & message handling)"]:::backend
        end
        PocketBase["PocketBase (Metadata Store)"]:::database
    end

    Discord["Discord REST/WebSocket"]:::external

    ReactApp -->|"/upload" POST| API
    API -->|"file assembly response"| ReactApp

    API -->|"Store metadata"| PocketBase
    API -->|"Retrieve metadata"| PocketBase

    Bot -->|"Send chunk attachments"| Discord
    Bot -->|"Fetch chunks"| Discord

    classDef frontend fill:#ADD8E6,stroke:#000,color:#000
    classDef backend fill:#90EE90,stroke:#000,color:#000
    classDef database fill:#FFA500,stroke:#000,color:#000
    classDef external fill:#D8BFD8,stroke:#000,color:#000

    click ReactApp "https://github.com/ananth-swamy/discord-storage/tree/master/frontend/"
    click API "https://github.com/ananth-swamy/discord-storage/blob/master/backend/index.js"
    click Bot "https://github.com/ananth-swamy/discord-storage/blob/master/backend/commands.js"
    click PocketBase "https://github.com/ananth-swamy/discord-storage/tree/master/pocketbase/"
```
