# inbestigator/messaging architecture

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

- Interactive diagram: https://gitdiagram.com/inbestigator/messaging
- Repository: https://github.com/inbestigator/messaging

## Overview

##### Project type and purpose
- This is a full-stack, end-to-end encrypted messaging service with two client applications (a macOS SwiftUI app and a web Next.js app) communicating in real time through a Deno server.
- Purpose: allow users on Mac or in a browser to exchange messages securely (messages encrypted/decrypted entirely on the clients).

##### File structure
- Top-level directories:
– messaging/ : macOS client app (SwiftUI, MVVM-style)
– server/    : Deno TypeScript server (WebSocket endpoint, message relay)
– www/       : Next.js web client (React + Tailwind CSS)
- Key config files:
– messaging/Info.plist, .entitlements — app identity and sandboxing
– server/deno.json, deno.lock — runtime & permissions for Deno
– www/package.json, next.config.ts, tailwind.config.ts, tsconfig.json — web build & lint setup
- Patterns & protocols:
– WebSockets for real-time communication
– End-to-end encryption performed in clients (Encryption.swift & www/src/enc.ts)
– SwiftUI for Mac UI; React/Next.js for web UI

##### Extract insights from README
- Confirms “end-to-end encrypted messaging service with a web and Mac app.”
- No direct mention of persistent storage, so the server likely acts as a transient message relay only.

a. Main components:
- macOS Client (messaging/)
- Web Client (www/)
- Message Relay Server (server/)
- Internet / Network
b. Relationships & interactions:
1. Both clients generate or retrieve encryption keypairs locally.
2. On login, clients open a WebSocket connection to the server.
3. When User A sends a message:
– Encryption module on client A encrypts message with recipient’s public key.
– Encrypted payload sent over WebSocket to the server.
4. Server relays ciphertext to User B’s open WebSocket.
5. Client B decrypts payload locally.
c. Architectural patterns/design principles:
– MVVM or similar unidirectional data flow on SwiftUI side (AppManager.swift as orchestrator, ChatView/SelectChatView as views).
– Component-based UI in React/Next.js with server-side rendering for pages (layout.tsx, page.tsx, input.tsx).
– Single WebSocket endpoint in Deno; no message persistence (stateless relay).
– Separation of concerns: UI + encryption logic + networking logic decoupled.
d. Important technologies/frameworks:
- SwiftUI (messagingApp.swift, ContentView.swift, ChatView.swift)
- Deno runtime + Oak or built-in WebSocket APIs (main.ts)
- Next.js with React + Tailwind CSS (www/src/app & components)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% macOS Client
    subgraph "macOS SwiftUI Client"
        direction TB
        subgraph "UI Layer"
            direction TB
            LoginView["LoginView"]:::client
            SelectChatView["SelectChatView"]:::client
            ChatView["ChatView"]:::client
            ContentView["ContentView"]:::client
        end
        AppManager["AppManager"]:::client
        EncryptionModule["Encryption Module"]:::crypto
        WSClient["WebSocket Client"]:::network
    end

    %% Web Client
    subgraph "Web Next.js Client"
        direction TB
        subgraph "UI Layer"
            direction TB
            Layout["layout.tsx"]:::client
            Page["page.tsx"]:::client
            InputComponent["Message Input (input.tsx)"]:::client
        end
        WebCrypto["Encryption Module"]:::crypto
        WSWeb["WebSocket Client"]:::network
    end

    %% Network
    Internet["Internet / Network"]:::network

    %% Server
    subgraph "Deno Server"
        direction TB
        Server["main.ts"]:::server
    end

    %% Connections
    WSClient -->|"WebSocket Connect\nEncrypted Payload"| Internet
    Internet -->|"WebSocket Connect"| Server
    Server -->|"Relay Encrypted Payload"| Internet
    Internet -->|"WebSocket Connect\nEncrypted Payload"| WSClient

    WSWeb -->|"WebSocket Connect\nEncrypted Payload"| Internet
    Internet -->|"WebSocket Connect"| Server
    Server -->|"Relay Encrypted Payload"| Internet
    Internet -->|"WebSocket Connect\nEncrypted Payload"| WSWeb

    %% Click Events
    click LoginView "https://github.com/inbestigator/messaging/blob/main/messaging/LoginView.swift"
    click SelectChatView "https://github.com/inbestigator/messaging/blob/main/messaging/SelectChatView.swift"
    click ChatView "https://github.com/inbestigator/messaging/blob/main/messaging/ChatView.swift"
    click ContentView "https://github.com/inbestigator/messaging/blob/main/messaging/ContentView.swift"
    click AppManager "https://github.com/inbestigator/messaging/blob/main/messaging/AppManager.swift"
    click EncryptionModule "https://github.com/inbestigator/messaging/blob/main/messaging/Encryption.swift"
    click WSClient "https://github.com/inbestigator/messaging/blob/main/messaging/Websocket.swift"
    click LoginView "https://github.com/inbestigator/messaging/blob/main/messaging/LoginView.swift"
    click SelectChatView "https://github.com/inbestigator/messaging/blob/main/messaging/SelectChatView.swift"
    click ChatView "https://github.com/inbestigator/messaging/blob/main/messaging/ChatView.swift"
    click ContentView "https://github.com/inbestigator/messaging/blob/main/messaging/ContentView.swift"
    click AppManager "https://github.com/inbestigator/messaging/blob/main/messaging/AppManager.swift"
    click EncryptionModule "https://github.com/inbestigator/messaging/blob/main/messaging/Encryption.swift"
    click WSClient "https://github.com/inbestigator/messaging/blob/main/messaging/Websocket.swift"
    click Server "https://github.com/inbestigator/messaging/blob/main/server/main.ts"
    click Internet "https://github.com/inbestigator/messaging/blob/main/server/deno.json"
    click Layout "https://github.com/inbestigator/messaging/blob/main/www/src/app/layout.tsx"
    click Page "https://github.com/inbestigator/messaging/blob/main/www/src/app/page.tsx"
    click InputComponent "https://github.com/inbestigator/messaging/blob/main/www/src/components/input.tsx"
    click WebCrypto "https://github.com/inbestigator/messaging/blob/main/www/src/enc.ts"
    click WSWeb "https://github.com/inbestigator/messaging/blob/main/www/src/app/globals.css"

    %% Styles
    classDef client fill:#D6EFFF,stroke:#333,stroke-width:1px
    classDef server fill:#D6FFD6,stroke:#333,stroke-width:1px
    classDef network fill:#F0F0F0,stroke:#333,stroke-width:1px
    classDef crypto fill:#FFF2CC,stroke:#333,stroke-width:1px
```
