# trevorwrightdev/gather-clone architecture

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

- Interactive diagram: https://gitdiagram.com/trevorwrightdev/gather-clone
- Repository: https://github.com/trevorwrightdev/gather-clone

## Overview

##### Main Components
- Frontend Application:
- Next.js directory structure with several pages/components (app, auth, editor, play, manage, etc.).
- UI components for authentication, video chat, tile-based editor (using Pixi.js), and real-time management of realms, rooms, and customizable spaces.
- Integration with external services through utility modules.
- Backend Service:
- API endpoints and route handling for user management, sessions, and real-time events.
- Socket.io integration for handling multiplayer networking and chat events.
- Supabase integration (database and authentication) to support user and session data.
- External Services:
- Supabase for managing the database and real-time subscriptions.
- Agora used for enabling video chat capabilities.

##### Relationships and Interactions
- The Frontend communicates with:
- The Backend using HTTP requests (via API calls) and WebSocket connections (using Socket.io) for real-time interactions.
- External services indirectly by sending data from the backend or directly, for example, Supabase for real-time updates, and Agora for video chat.
- The Backend receives requests from the Frontend, processes them, and interacts with Supabase for data needs.
- Real-time functionality is a critical pattern: socket connections for multiplayer interactions and proximity-based chat.
- Authentication flows that start at the frontend and are validated via the backend with Supabase credentials.

##### Architectural Patterns and Design Principles
- Separation of concerns: clear division between frontend (client-side rendering, UI/UX) and backend (API, socket servers, session management).
- Real-time communication: using Socket.io for event-driven updates.
- Modular design: separate directories for routes, sockets, and utility functions.
- Integration with managed services (Supabase and Agora) which separate core infrastructure responsibilities.
- Use of modern web development patterns with Next.js and TailwindCSS for fast iteration and responsive design.

##### Relevant Technologies and Frameworks
- Frontend: Next.js, React, TypeScript, TailwindCSS, Pixi.js, and Agora for video chat.
- Backend: Node.js/TypeScript, Socket.io, Supabase client libraries.
- Deployment: Procfile (suggesting deployment on platforms like Heroku) and configuration files for both frontend and backend integration.

- The API endpoints in the Backend for data and session management.
- WebSocket connections to the Backend’s Socket service for real-time interactions.
- API requests/responses to Supabase for data persistence and auth verification.
- Invocation of external services like Agora for video chat functionalities.

## Diagram (Mermaid)

```mermaid
graph TD
    User["User"]
    
    Front["Frontend (Next.js App)"]:::frontend

    subgraph "Frontend Modules"
        Auth["Authentication"]:::module
        Editor["Editor (Pixi.js)"]:::module
        PixiUtils["Pixi Utils"]:::module
        Play["Play Module"]:::module
        VideoChatUtils["Video Chat Utils"]:::module
        Realms["Realms & Management"]:::module
        Manage["Management"]:::module
        UI["UI Components"]:::module
        SupFrontend["Supabase (Frontend)"]:::module
    end

    subgraph "Backend (API & Socket Server)"
        API["API Endpoints"]:::module
        Socket["Socket.io Service"]:::module
        Session["Session Management"]:::module
        SupBackend["Supabase (Backend)"]:::module
    end

    SupabaseDB["Supabase (DB & Auth Service)"]:::external
    Agora["Agora (Video Chat Service)"]:::external

    User -->|"Interaction"| Front
    Front -->|"HTTP_Request"| API
    Front -->|"Supabase_Client"| SupFrontend
    Play -->|"WebSocket"| Socket
    Auth -->|"Auth_Request"| API
    Manage -->|"Management_Request"| API
    SupFrontend -->|"Realtime_Data"| SupabaseDB
    SupBackend -->|"Data/Auth"| SupabaseDB
    VideoChatUtils -->|"VideoChat"| Agora

    click Front "https://github.com/trevorwrightdev/gather-clone/tree/main/frontend/app"
    click Auth "https://github.com/trevorwrightdev/gather-clone/tree/main/frontend/app/auth"
    click Editor "https://github.com/trevorwrightdev/gather-clone/tree/main/frontend/app/editor"
    click PixiUtils "https://github.com/trevorwrightdev/gather-clone/tree/main/frontend/utils/pixi"
    click Play "https://github.com/trevorwrightdev/gather-clone/tree/main/frontend/app/play"
    click VideoChatUtils "https://github.com/trevorwrightdev/gather-clone/tree/main/frontend/utils/video-chat"
    click Realms "https://github.com/trevorwrightdev/gather-clone/tree/main/frontend/app/app/RealmsMenu"
    click Manage "https://github.com/trevorwrightdev/gather-clone/tree/main/frontend/app/manage"
    click UI "https://github.com/trevorwrightdev/gather-clone/tree/main/frontend/components"
    click SupFrontend "https://github.com/trevorwrightdev/gather-clone/tree/main/frontend/utils/supabase"
    
    click API "https://github.com/trevorwrightdev/gather-clone/tree/main/backend/src/routes"
    click Socket "https://github.com/trevorwrightdev/gather-clone/tree/main/backend/src/sockets"
    click Session "https://github.com/trevorwrightdev/gather-clone/blob/main/backend/src/session.ts"
    click SupBackend "https://github.com/trevorwrightdev/gather-clone/blob/main/backend/src/supabase.ts"

    click Agora "https://github.com/trevorwrightdev/gather-clone/tree/main/frontend/utils/video-chat"

    classDef frontend fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef external fill:#A9DFBF,stroke:#333,stroke-width:2px;
    classDef module fill:#D5F5E3,stroke:#333,stroke-width:2px;
```
