# jnaraujo/letschat architecture

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

- Interactive diagram: https://gitdiagram.com/jnaraujo/letschat
- Repository: https://github.com/jnaraujo/letschat

## Overview

##### Main Components

A. Client Layer:
- WebSocket Client Component
- Command-line Interface
- Account Management
- Protocol Handling

B. Server Layer:
- WebSocket Server
- Room Management
- Client Management
- Command Handler
- Connection Management

C. Shared Components:
- Protocol Messages
- Security Services
- Account Services

**[Client Tier]**
- ↕
**[Protocol/Message Layer]**
- ↕
**[Server Tier]**

##### Detailed Component Breakdown

Client Tier (from cmd/client and pkg/client):
- Sub-components:
- WebSocket Client Handler
- Command Parser
- Message Formatter
- Account Manager

Protocol/Message Layer (from pkg/protocol):
- Message types:
- Auth Messages
- Chat Messages
- Ping Messages
- Packet Management

Server Tier (from pkg/server):
- Main "WebSocket Server" component
- Sub-components:
- Room Manager
- Client Manager
- Connection Handler
- Command Processor

##### Connection and Data Flow

- Bidirectional WebSocket communication between client and server
- Internal message flow through protocol layer
- Room management operations
- Client-to-room relationships

##### Additional Elements

Supporting services:
- ID Generation Service (pkg/id)
- Security Services (pkg/secure)
- Utility Services (pkg/utils)

Use standard symbols:
- Rectangles: Components/modules
- Diamonds: Decision points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CLI["Command-line Interface"]
        WSClient["WebSocket Client"]
        AccMgmt["Account Management"]
        CmdParser["Command Parser"]
        MsgFmt["Message Formatter"]
    end

    subgraph Protocol
        ProtHandler["Protocol Handler"]
        subgraph Messages
            AuthMsg["Auth Messages"]
            ChatMsg["Chat Messages"]
            PingMsg["Ping Messages"]
        end
        PacketMgmt["Packet Management"]
    end

    subgraph Server
        WSServer["WebSocket Server"]
        RoomMgr["Room Manager"]
        ClientMgr["Client Manager"]
        ConnHandler["Connection Handler"]
        CmdProc["Command Processor"]
    end

    subgraph Services
        IDGen["ID Generation Service"]
        SecServ["Security Services"]
        Utils["Utility Services"]
    end

    %% Connections
    CLI --> WSClient
    WSClient <--> ProtHandler
    WSClient --> CmdParser
    WSClient --> MsgFmt
    WSClient --> AccMgmt

    ProtHandler --> AuthMsg
    ProtHandler --> ChatMsg
    ProtHandler --> PingMsg
    ProtHandler --> PacketMgmt

    ProtHandler <--> WSServer
    WSServer --> RoomMgr
    WSServer --> ClientMgr
    WSServer --> ConnHandler
    WSServer --> CmdProc

    WSServer --> IDGen
    WSServer --> SecServ
    WSServer --> Utils

    %% Styles
    classDef client fill:#a8d1ff
    classDef server fill:#90EE90
    classDef protocol fill:#FFE5B4
    classDef service fill:#FFB6C1

    class CLI,WSClient,AccMgmt,CmdParser,MsgFmt client
    class WSServer,RoomMgr,ClientMgr,ConnHandler,CmdProc server
    class ProtHandler,AuthMsg,ChatMsg,PingMsg,PacketMgmt protocol
    class IDGen,SecServ,Utils service

    %% Click Events
    click CLI "https://github.com/jnaraujo/letschat/blob/main/cmd/client/main.go"
    click WSClient "https://github.com/jnaraujo/letschat/blob/main/pkg/client/client.go"
    click AccMgmt "https://github.com/jnaraujo/letschat/blob/main/pkg/account/account.go"
    click ProtHandler "https://github.com/jnaraujo/letschat/blob/main/pkg/protocol/packet.go"
    click WSServer "https://github.com/jnaraujo/letschat/blob/main/pkg/server/ws-server.go"
    click RoomMgr "https://github.com/jnaraujo/letschat/blob/main/pkg/server/room.go"
    click ClientMgr "https://github.com/jnaraujo/letschat/blob/main/pkg/server/client.go"
    click CmdProc "https://github.com/jnaraujo/letschat/blob/main/pkg/server/commands.go"
    click ConnHandler "https://github.com/jnaraujo/letschat/blob/main/pkg/server/connection.go"
    click AuthMsg "https://github.com/jnaraujo/letschat/blob/main/pkg/protocol/auth-message.go"
    click ChatMsg "https://github.com/jnaraujo/letschat/blob/main/pkg/protocol/chat-message.go"
    click PingMsg "https://github.com/jnaraujo/letschat/blob/main/pkg/protocol/ping-message.go"
    click SecServ "https://github.com/jnaraujo/letschat/blob/main/pkg/secure/random.go"
    click IDGen "https://github.com/jnaraujo/letschat/blob/main/pkg/id/id.go"
    click Utils "https://github.com/jnaraujo/letschat/tree/main/pkg/utils"
```
