# datpham0412/go-realtime-chat architecture

> Architecture diagram of the GitHub repository datpham0412/go-realtime-chat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/datpham0412/go-realtime-chat
- Repository: https://github.com/datpham0412/go-realtime-chat

## Overview

##### Main Components
- Frontend:
- Represented by the "frontend" directory and all Vue.js components. This layer includes the main application (App.vue), components for chat features (ChatRoom, MessageList, MessageForm, Login, etc.), and routing configuration.
- Backend:
- Represented by main.go and the "server" directory containing the Go code for handling GraphQL calls, resolvers, authentication, and other server logic.
- GraphQL API:
- GraphQL layer which uses gqlgen. Include both queries and subscriptions handling.
- Redis:
- An external component for Redis since it is used for persisting chat messages and enabling real-time capabilities.
- GitHub OAuth:
- GitHub as an OAuth external authentication provider integrated into the backend.
- Docker & Deployment Orientation:
- Docker containerization elements – Dockerfiles for both the backend and frontend, and docker-compose configurations. Also include the deployment configuration for Fly.io.
- External Communication / WebSockets:

##### Relationships and Data Flow
- Clients (web browsers) interact with the Frontend (Vue.js) which communicates with the Backend via HTTP/GraphQL over WebSockets.
- The GraphQL API in the backend interfaces with Redis to store and retrieve chat history.
- The authentication layer interfaces with GitHub via OAuth, and the backend manages these auth requests.

##### Architectural Patterns and Key Technologies
- The client/server separation is distinct. On the client side, use component-based design as seen with Vue.js.
- The backend encapsulates GraphQL APIs using gqlgen, following a modular design (resolvers, models, custom directives) evident from the files in the server directory.
- Containerization is present. Emphasize Docker, docker-compose, and additional deployment scripts (fly.toml, render.yaml).
- Use of GitHub OAuth for secure authentication in a microservices-like setup.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend (Vue.js)"
        F1["App.vue & Components (ChatRoom, MessageList, MessageForm, Login, GitHubLogin)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Go Server)"
        B1["main.go & Server Logic"]:::backend
        B2["GraphQL API (gqlgen)"]:::backend
        B3["GitHub OAuth (server/auth.go)"]:::backend
        B4["WebSocket Communication (Real-Time Subscriptions)"]:::backend
    end

    %% External Services and Deployment
    R["Redis (Data Persistence)"]:::external
    G["GitHub (OAuth Provider)"]:::external
    D["Docker & Deployment (Dockerfile, docker-compose.yaml, fly.toml, render.yaml)"]:::deployment

    %% Data Flow Connections
    F1 -->|"GraphQL/API / WebSocket"| B1
    B1 -->|"Uses" | B2
    B1 -->|"Handles" | B3
    B1 -->|"Manages" | B4
    B2 -->|"Stores/Retrieves" | R
    B3 -->|"Auth with" | G
    D -->|"Deploys" | F1
    D -->|"Deploys" | B1

    %% Click Events
    click F1 "https://github.com/datpham0412/go-realtime-chat/tree/main/frontend/"
    click B1 "https://github.com/datpham0412/go-realtime-chat/blob/main/main.go"
    click B2 "https://github.com/datpham0412/go-realtime-chat/tree/main/server/"
    click B3 "https://github.com/datpham0412/go-realtime-chat/blob/main/server/auth.go"
    click D "https://github.com/datpham0412/go-realtime-chat/blob/main/docker-compose.yaml"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#ccf,stroke:#333,stroke-width:2px;
    classDef external fill:#cfc,stroke:#333,stroke-width:2px;
    classDef deployment fill:#fcc,stroke:#333,stroke-width:2px;
```
