# supabase-community/realtime-go architecture

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

- Interactive diagram: https://gitdiagram.com/supabase-community/realtime-go
- Repository: https://github.com/supabase-community/realtime-go

## Overview

- Library Interface: The core client functionality exposed by “realtime_client.go”. This component provides the API for initiating connections and sending/receiving realtime messages.
- Feature Handlers:
- Events Handler: Represented by “events.go”, which manages subscription events or state updates.
- Message Handler: Represented by “messages.go”, handling the actual messaging logic for broadcast and CDC.

##### Relationships and Interactions
- That messages are received, processed, and then forwarded appropriately through the handlers.

##### Architectural Patterns and Technologies
- That this client library abstracts complex realtime interactions, possibly using Go’s concurrency features (goroutines, channels) even if they’re implicit from the language choice.
- Mention that the design follows a modular approach where each file (or module) encapsulates distinct responsibilities (separation of concerns).
- A note that the system relies on external CRDTs for the Presence feature and utilizes Postgres CDC to monitor database changes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    CLIENT["Realtime Client"]:::internal
    EVENTS["Event Handler"]:::internal
    MESSAGES["Message Handler"]:::internal
    SUPABASE["Supabase Realtime Service"]:::external
    POSTGRES["PostgreSQL Database"]:::external

    CLIENT -->|"calls"| EVENTS
    CLIENT -->|"calls"| MESSAGES
    EVENTS -->|"handlesSubscriptions"| SUPABASE
    MESSAGES -->|"handlesMessaging"| SUPABASE
    MESSAGES -->|"CDCto"| POSTGRES
    POSTGRES -->|"changeFeed"| MESSAGES

    click CLIENT "https://github.com/supabase-community/realtime-go/blob/main/realtime/realtime_client.go"
    click EVENTS "https://github.com/supabase-community/realtime-go/blob/main/realtime/events.go"
    click MESSAGES "https://github.com/supabase-community/realtime-go/blob/main/realtime/messages.go"

    classDef internal fill:#e0f7fa,stroke:#006064,stroke-width:2px;
    classDef external fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px;
```
