# martinschaer/nitram architecture

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

- Interactive diagram: https://gitdiagram.com/martinschaer/nitram
- Repository: https://github.com/martinschaer/nitram

## Overview

##### Main Components

a) Server-Side (Rust):
- Core RPC Handler (src/nitram.rs)
- Authentication Module (src/auth.rs)
- WebSocket Manager (src/ws.rs)
- Message Processing (src/messages.rs)
- Error Handling (src/error.rs)
- Models Layer (src/models.rs)

b) Client-Side (TypeScript):
- Bindings Layer (examples/main/bindings/)
- API Interface (examples/main/bindings/API/)
- Request/Response Handlers (NitramRequest.ts, NitramResponse.ts)
- Signal System (NitramSignal.ts)

##### Connection and Data Flow

- Bidirectional WebSocket connection between server and client
- RPC call flow from client to server
- Signal flow from server to client
- Authentication flow

##### Specific Implementation Details

- Blue rectangles for Rust components
- Green rectangles for TypeScript components
- Yellow diamonds for interface points (API bindings)
- Red hexagons for authentication components

**[Client Application Layer]**
- ↕
**[TypeScript Bindings Layer]**
- ↕
**[WebSocket Communication Layer]**
- ↕
**[Rust RPC Server Layer]**

##### Important Elements to Highlight

- The bridge between Rust and TypeScript (bindings)
- WebSocket-based communication channel
- Authentication flow
- Message serialization/deserialization (serde_json)
- Signal system for real-time updates

##### Technical Details

Integration points:
- JSON serialization boundary
- WebSocket protocol layer
- Authentication boundaries
- API interface points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "TypeScript Client"
        direction TB
        UI["Chat Application UI"]:::ui
        Auth["Authentication UI"]:::ui
        Store["Application Store"]:::store
        Backend["Backend Context"]:::context
        Client["Client Implementation"]:::client
        
        subgraph "Bindings Layer"
            direction TB
            API["API Interface"]:::bindings
            ReqHandler["Request Handler"]:::bindings
            ResHandler["Response Handler"]:::bindings
            Signal["Signal System"]:::bindings
        end
        
        UI --> Store
        Auth --> Store
        Store --> Backend
        Backend --> Client
        Client --> API
        API --> ReqHandler
        API --> ResHandler
        API --> Signal
    end

    subgraph "Nitram RPC Server"
        direction TB
        Core["Core RPC Handler"]:::rust
        AuthMod["Authentication Module"]:::rust
        WSManager["WebSocket Manager"]:::rust
        MsgProc["Message Processing"]:::rust
        ErrHandler["Error Handling"]:::rust
        Models["Models Layer"]:::rust

        Core --> AuthMod
        Core --> WSManager
        WSManager --> MsgProc
        MsgProc --> Models
        Core --> ErrHandler
    end

    %% Connections between client and server
    Client <--> WSManager
    
    %% Styling
    classDef rust fill:#B8D7FF,stroke:#1E88E5
    classDef bindings fill:#A5D6A7,stroke:#43A047
    classDef ui fill:#FFE0B2,stroke:#FB8C00
    classDef store fill:#E1BEE7,stroke:#8E24AA
    classDef context fill:#FFCDD2,stroke:#E53935
    classDef client fill:#F5F5F5,stroke:#616161

    %% Click events
    click Core "https://github.com/martinschaer/nitram/blob/main/src/nitram.rs"
    click AuthMod "https://github.com/martinschaer/nitram/blob/main/src/auth.rs"
    click WSManager "https://github.com/martinschaer/nitram/blob/main/src/ws.rs"
    click MsgProc "https://github.com/martinschaer/nitram/blob/main/src/messages.rs"
    click ErrHandler "https://github.com/martinschaer/nitram/blob/main/src/error.rs"
    click Models "https://github.com/martinschaer/nitram/blob/main/src/models.rs"
    click API "https://github.com/martinschaer/nitram/tree/main/examples/main/bindings/API/"
    click ReqHandler "https://github.com/martinschaer/nitram/blob/main/examples/main/bindings/NitramRequest.ts"
    click ResHandler "https://github.com/martinschaer/nitram/blob/main/examples/main/bindings/NitramResponse.ts"
    click Signal "https://github.com/martinschaer/nitram/blob/main/examples/main/bindings/NitramSignal.ts"
    click UI "https://github.com/martinschaer/nitram/blob/main/examples/main/web-app/src/Chat.tsx"
    click Backend "https://github.com/martinschaer/nitram/blob/main/examples/main/web-app/src/BackendContext.tsx"
    click Store "https://github.com/martinschaer/nitram/blob/main/examples/main/web-app/src/store.ts"
    click Auth "https://github.com/martinschaer/nitram/blob/main/examples/main/web-app/src/Login.tsx"
    click Client "https://github.com/martinschaer/nitram/blob/main/examples/main/web-app/src/lib/nitram.ts"
```
