# eupston/crystalring architecture

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

- Interactive diagram: https://gitdiagram.com/eupston/crystalring
- Repository: https://github.com/eupston/crystalring

## Overview

##### Project type and purpose
- This is “CrystalRing,” an Electron-based desktop application built with React (renderer) and a Node/Electron main process, paired with a standalone Go gRPC server and MongoDB.
- Its goal is real-time, high-quality peer-to-peer audio calls using WebRTC for connection setup and gRPC for uncompressed audio streaming, with call records saved in MongoDB.

##### File structure
- Top-level Electron config and scripts (.erb folder, webpack configs, ESLint, packaging scripts).
- “src/” holds the Electron renderer (React, TypeScript) and main process code:
- src/main.dev.ts, src/main.prod.js (Electron entry points)
- src/App.tsx, Components, network (WebRTC client wrappers), db (Mongo connection & models)
- src/menu.ts (Electron menu)
- “proto/” and “server/” implement the gRPC service in Go:
- proto/*.proto + generated Go/JS/TS bindings
- server/server.go + services/audiostreamer/audiostreamer.go
- Packaging and build scripts for Electron, plus Go module files (go.mod, go.sum).

##### README for additional insights
- Confirms Electron + React desktop UI, MongoDB for persistence, WebRTC for peer discovery/connection, gRPC for audio streaming.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Electron Client"
        subgraph Renderer
            IDX["index.tsx"]:::ui
            APP["App.tsx"]:::ui
            COMPS["Components/"]:::ui
        end
        subgraph "Main Process"
            MAINDEV["main.dev.ts"]:::logic
            MAINPROD["main.prod.js.LICENSE.txt"]:::logic
            MENU["menu.ts"]:::logic
        end
    end

    subgraph "Network Adapters"
        P2P["p2pconnection.ts"]:::logic
        AUDIO_CLI["audiostreamer.ts"]:::logic
        CLIENT["client.ts"]:::logic
    end

    subgraph "Protocol Buffers"
        PROTO["audiostreamer.proto"]:::infra
        PBJS["audiostreamer_pb.js"]:::infra
        PBDTS["audiostreamer_pb.d.ts"]:::infra
        GRPCJS["audiostreamer_grpc_pb.js"]:::infra
        GRPCDTS["audiostreamer_grpc_pb.d.ts"]:::infra
        PBGOPROTO["audiostreamer.pb.go"]:::infra
        PBGOGRPC["audiostreamer_grpc.pb.go"]:::infra
    end

    subgraph "Go gRPC Server"
        SRV["server.go"]:::logic
        SERVICE["audiostreamer.go"]:::logic
    end

    subgraph "Persistence"
        DBCONN["dbConnection.js"]:::logic
        CALLSMOD["Calls.js"]:::logic
    end

    MongoDB["MongoDB (Call Metadata)"]:::infra
    STUN["STUN/TURN Servers"]:::external

    subgraph "Build & Packaging"
        WEBPACK[".erb/configs/webpack.config.*.babel.js"]:::logic
        SCRIPTS[".erb/scripts/"]:::logic
        BUILDSH["build.sh"]:::logic
    end

    IDX -->|IPC| MAINDEV
    APP -->|IPC| MAINDEV
    MAINDEV -->|IPC| IDX
    MAINDEV -->|IPC| APP

    IDX -->|uses| P2P
    APP -->|uses| AUDIO_CLI
    CLIENT -->|uses| AUDIO_CLI

    P2P -->|STUN/TURN negotiation| STUN
    P2P -->|signaling| SRV

    AUDIO_CLI -->|gRPC bi-stream| SRV
    CLIENT -->|gRPC calls| SRV

    PROTO --> PBJS
    PROTO --> PBDTS
    PROTO --> PBGOPROTO
    PROTO --> PBGOGRPC
    GRPCJS --> CLIENT
    GRPCDTS --> CLIENT

    SRV --> SERVICE
    SERVICE -->|writes| MongoDB
    SERVICE -->|reads/writes| DBCONN

    APP -->|persists metadata| DBCONN
    APP -->|manages schema| CALLSMOD
    DBCONN -->|connects| MongoDB
    CALLSMOD -->|writes| MongoDB

    WEBPACK --> MAINDEV
    SCRIPTS --> MAINDEV
    BUILDSH -->|packages| MAINPROD

    classDef ui fill:#AEDFF7,stroke:#333,stroke-width:1px;
    classDef logic fill:#CDECA8,stroke:#333,stroke-width:1px;
    classDef infra fill:#F6D186,stroke:#333,stroke-width:1px;
    classDef external fill:#E8E8E8,stroke:#333,stroke-width:1px;

    click IDX "https://github.com/eupston/crystalring/blob/master/src/index.tsx"
    click APP "https://github.com/eupston/crystalring/blob/master/src/App.tsx"
    click COMPS "https://github.com/eupston/crystalring/tree/master/src/Components/"
    click MAINDEV "https://github.com/eupston/crystalring/blob/master/src/main.dev.ts"
    click MAINPROD "https://github.com/eupston/crystalring/blob/master/src/main.prod.js.LICENSE.txt"
    click MENU "https://github.com/eupston/crystalring/blob/master/src/menu.ts"
    click P2P "https://github.com/eupston/crystalring/blob/master/src/network/p2pconnection.ts"
    click AUDIO_CLI "https://github.com/eupston/crystalring/blob/master/src/network/audiostreamer.ts"
    click CLIENT "https://github.com/eupston/crystalring/blob/master/src/network/client.ts"
    click DBCONN "https://github.com/eupston/crystalring/blob/master/src/db/dbConnection.js"
    click CALLSMOD "https://github.com/eupston/crystalring/blob/master/src/db/models/Calls.js"
    click PROTO "https://github.com/eupston/crystalring/blob/master/proto/audiostreamer.proto"
    click PBJS "https://github.com/eupston/crystalring/blob/master/proto/audiostreamer_pb.js"
    click PBDTS "https://github.com/eupston/crystalring/blob/master/proto/audiostreamer_pb.d.ts"
    click GRPCJS "https://github.com/eupston/crystalring/blob/master/proto/audiostreamer_grpc_pb.js"
    click GRPCDTS "https://github.com/eupston/crystalring/blob/master/proto/audiostreamer_grpc_pb.d.ts"
    click PBGOPROTO "https://github.com/eupston/crystalring/blob/master/proto/audiostreamer.pb.go"
    click PBGOGRPC "https://github.com/eupston/crystalring/blob/master/proto/audiostreamer_grpc.pb.go"
    click SRV "https://github.com/eupston/crystalring/blob/master/server/server.go"
    click SERVICE "https://github.com/eupston/crystalring/blob/master/server/services/audiostreamer/audiostreamer.go"
    click WEBPACK "https://github.com/eupston/crystalring/blob/master/.erb/configs/webpack.config.*.babel.js"
    click SCRIPTS "https://github.com/eupston/crystalring/tree/master/.erb/scripts/"
    click BUILDSH "https://github.com/eupston/crystalring/blob/master/build.sh"
```
