# y-exe/discord-token-webclient architecture

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

- Interactive diagram: https://gitdiagram.com/y-exe/discord-token-webclient
- Repository: https://github.com/y-exe/discord-token-webclient

## Overview

##### Project type and purpose
- This is a full-stack, client-server web application (“Discord Web Token Client”).
- Purpose: Provide a lightweight browser‐based Discord client that connects to Discord via bot/user tokens.

##### High-level architecture overview
- Frontend: React (Vite) + Tailwind CSS
- Backend: Node.js + Express + Socket.io + discord.js
- External service: Discord’s official REST and Gateway APIs

##### Main components and their roles
a. Browser (end user)
- Hosts the React/Vite app, renders UI components, initiates auth and real-time events
b. React Frontend (Vite dev server or static build)
- Authentication pages (login)
- Channel/forum views, message components, overlays, etc.
- Uses socket.io-client to open a WebSocket to the backend
c. Node.js + Express + Socket.io Server
- HTTP endpoints (if any) for initial page serve or token submission
- Socket.io namespace/rooms for realtime events
- Manages discord.js client instances (one per token/session)
- Translates UI actions → discord.js API calls
- Streams Discord events (messages, reactions, threads) back to UI over WebSockets
d. discord.js client
- Maintains a Discord Gateway connection on behalf of the user or bot
- Exposes REST calls to fetch channels, send messages, react, etc.
e. Discord External API
- Official Discord REST API
- Official Discord Gateway (WebSocket)

##### Interactions & data flows
1. User opens browser → loads React app (HTTP GET)
2. React app establishes a Socket.io connection to Express server
3. User submits token via UI → sent over WebSocket to server
4. Server boots a discord.js client using provided token → connects to Discord Gateway
5. Discord events (message create, thread events, reactions) flow from Discord Gateway → discord.js → Socket.io → React UI
6. UI actions (send message, react) flow back the same route in reverse

##### Architectural patterns & design principles
- Separation of concerns: UI layer (React) vs. business logic and API orchestration (Node.js/Express)
- Real-time messaging pattern: WebSocket (Socket.io) for bidirectional, low-latency communication
- Adapter pattern: socket.io events adapt to discord.js calls and back
- Statelessness on backend aside from discord.js instances; no persistent database (in-memory per session)

##### Technologies & frameworks
- Frontend: React, Vite, Tailwind CSS, socket.io-client
- Backend: Node.js, Express, Socket.io, discord.js
- Build Tools: npm, vite.config.js, postcss, eslint, Tailwind config

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Codebase
    subgraph "Frontend Code (frontend/)" 
        direction TB
        ViteConfig["vite.config.js"]:::ui
        TailwindConfig["tailwind.config.js"]:::ui
        PostCSS["postcss.config.js"]:::ui
        IndexHTML["index.html"]:::ui
        MainJS["src/main.jsx"]:::ui
        AppJS["src/App.jsx"]:::ui
        subgraph "UI Components" 
            direction TB
            DiscordClient["components/DiscordClient.jsx"]:::ui
            Login["components/auth/Login.jsx"]:::ui
            HeaderComp["components/auth/Header.jsx"]:::ui
            FooterComp["components/auth/Footer.jsx"]:::ui
            ServerList["components/server/ServerList.jsx"]:::ui
            ChannelSidebar["components/channel/ChannelSidebar.jsx"]:::ui
            ForumView["components/chat/ForumView.jsx"]:::ui
            ChatInput["components/chat/ChatInput.jsx"]:::ui
            MessageComponent["components/chat/MessageComponent.jsx"]:::ui
            MessageContent["components/chat/MessageContent.jsx"]:::ui
            MessageEmbed["components/chat/MessageEmbed.jsx"]:::ui
            ReactionList["components/chat/ReactionList.jsx"]:::ui
            MessageToolbar["components/chat/MessageToolbar.jsx"]:::ui
            ImageViewer["components/chat/ImageViewer.jsx"]:::ui
            MemberList["components/member/MemberList.jsx"]:::ui
            ContextMenu["components/overlay/MessageContextMenu.jsx"]:::ui
            UserPopout["components/overlay/UserPopout.jsx"]:::ui
            HeadSEO["components/seo/Head.jsx"]:::ui
            UIControls["components/ui/"]:::ui
            WindowHeader["components/window/WindowHeader.jsx"]:::ui
        end
        Utils1["src/lib/utils.js"]:::ui
        Utils2["src/utils/helpers.js"]:::ui
        Emojis["src/utils/emojis.js"]:::ui
    end

    %% Runtime Layers
    Browser["Browser (User)"]:::ui
    ViteServer["Vite Dev Server / Static Host"]:::ui
    Browser -->|"HTTP GET: load React app"| ViteServer

    Browser <-->|"Socket.io"| ExpressServer["Express + Socket.io\nServer"]:::server

    ExpressServer -->|"instantiate discord.js client"| DiscordJS["discord.js Client Module"]:::server
    DiscordJS -->|"REST calls (POST /channels/:id/messages, etc.)"| DiscordAPI["Discord External Service\n(REST API)"]:::external
    DiscordJS -->|"Gateway (WSS) MESSAGE_CREATE, REACTION_ADD"| DiscordAPI

    ExpressServer -->|"Discord events via socket.io"| Browser
    Browser -->|"UI Actions (sendMessage, react) via socket.io"| ExpressServer

    %% Click Events
    click ViteConfig "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/vite.config.js"
    click TailwindConfig "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/tailwind.config.js"
    click PostCSS "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/postcss.config.js"
    click IndexHTML "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/index.html"
    click MainJS "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/main.jsx"
    click AppJS "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/App.jsx"
    click DiscordClient "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/DiscordClient.jsx"
    click Login "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/auth/Login.jsx"
    click HeaderComp "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/auth/Header.jsx"
    click FooterComp "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/auth/Footer.jsx"
    click ServerList "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/server/ServerList.jsx"
    click ChannelSidebar "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/channel/ChannelSidebar.jsx"
    click ForumView "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/chat/ForumView.jsx"
    click ChatInput "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/chat/ChatInput.jsx"
    click MessageComponent "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/chat/MessageComponent.jsx"
    click MessageContent "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/chat/MessageContent.jsx"
    click MessageEmbed "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/chat/MessageEmbed.jsx"
    click ReactionList "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/chat/ReactionList.jsx"
    click MessageToolbar "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/chat/MessageToolbar.jsx"
    click ImageViewer "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/chat/ImageViewer.jsx"
    click MemberList "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/member/MemberList.jsx"
    click ContextMenu "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/overlay/MessageContextMenu.jsx"
    click UserPopout "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/overlay/UserPopout.jsx"
    click HeadSEO "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/seo/Head.jsx"
    click UIControls "https://github.com/y-exe/discord-token-webclient/tree/main/frontend/src/components/ui/"
    click WindowHeader "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/components/window/WindowHeader.jsx"
    click Utils1 "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/lib/utils.js"
    click Utils2 "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/utils/helpers.js"
    click Emojis "https://github.com/y-exe/discord-token-webclient/blob/main/frontend/src/utils/emojis.js"
    click ExpressServer "https://github.com/y-exe/discord-token-webclient/blob/main/backend/server.js"
    click DiscordJS "https://github.com/y-exe/discord-token-webclient/blob/main/backend/server.js"
    click DiscordAPI "https://github.com/y-exe/discord-token-webclient/blob/main/backend/server.js"

    %% Styles
    classDef ui fill:#D0E6FF,stroke:#4287f5,color:#000;
    classDef server fill:#DFFFD0,stroke:#7ac142,color:#000;
    classDef external fill:#FFE6CC,stroke:#f58f42,color:#000;
```
