# biniter1/nt106_-_-n architecture

> Architecture diagram of the GitHub repository biniter1/nt106_-_-n, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/biniter1/nt106_-_-n
- Repository: https://github.com/biniter1/nt106_-_-n

## Overview

##### Project Type and Purpose
- This is a desktop chat application built with WPF (.NET) following the MVVM pattern.
- It provides real-time messaging, voice/video calls, file sharing, notifications, and AI-powered chat features.
- Under the hood it leverages Firebase (Firestore, Realtime Database, Storage), WebSocket signaling, WebRTC peer connections, and an AI service (Gemini).

##### Top-Level Structure
- WpfApp1.sln: Visual Studio solution.
- WpfApp1/: Main WPF project.
- Views/: XAML UI definitions.
- ViewModels/: Presentation logic.
- Models/: Domain entities and data-access helpers.
- Services/: Infrastructure clients (Firebase helpers, WebSocketService, WebRTCService, GeminiService, NotificationService, EventAggregator).
- Converters/: UI value converters.

##### Key Architectural Patterns
- MVVM: clear separation of View ↔ ViewModel ↔ Model.
- Event Aggregator: decouples cross-component events (StartChatEvent, NewMessageEventArgs).
- Service Layer: abstracts external dependencies (Firebase, WebSocket, WebRTC, AI).

a. Presentation Layer
- Views (XAML windows/user controls)
- Converters (value transformations)
b. Application Layer
- ViewModels: AIChatViewModel, ChatViewModel, CallViewModel, etc.
c. Domain Layer
- Models: Message, User, CallSignal, IceCandidateSignal, Group, FriendRequest, etc.
d. Infrastructure/Services
- Firebase Services: FirestoreHelper, RealtimeDatabaseHelper, FirebaseStorageHelper
- WebSocketService: signaling channel for chat and call negotiation
- WebRTCService: peer-to-peer audio/video
- GeminiService: AI chat backend
- NotificationService: UI notifications
- EventAggregator: in-process pub/sub
e. External Systems
- Google Firebase (Firestore, Realtime Database, Storage)
- WebSocket server (if custom)
- TURN/STUN servers for WebRTC
- AI endpoint (Gemini/OpenAI)

##### Relationships and Data Flows
- User interacts with View → bound properties/commands in ViewModel.
- ViewModel invokes Service API → external system (Firebase, WebSocket, AI).
- Service returns data/events → ViewModel (via callbacks or EventAggregator).
- ViewModel updates Model/ObservableCollection → View refreshes.
- For calls: WebSocketService exchanges SDP & ICE → WebRTCService negotiates peer connection → Media streams.
- For file uploads: ViewModel → FirebaseStorageHelper → Storage → returns URL back to ViewModel.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        Views["Views"]:::presentation
        Converters["Converters"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        AIChatVM["AIChatViewModel"]:::application
        ChatVM["ChatViewModel"]:::application
        CallVM["CallViewModel"]:::application
        NewMsgEvent["NewMessageEventArgs"]:::application
        RTDBHelper["RealtimeDatabaseHelper"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        Message["Message"]:::domain
        User["User"]:::domain
        CallSignal["CallSignal"]:::domain
        IceCandidate["IceCandidateSignal"]:::domain
        Group["Group"]:::domain
        FriendRequest["FriendRequest"]:::domain
    end

    %% Infrastructure Services
    subgraph "Infrastructure / Services"
        EventAggregator["EventAggregator"]:::infrastructure
        WSService["WebSocketService"]:::infrastructure
        RTCService["WebRTCService"]:::infrastructure
        FirestoreHelper["FirestoreHelper"]:::infrastructure
        StorageHelper["FirebaseStorageHelper"]:::infrastructure
        GeminiService["GeminiService"]:::infrastructure
        NotificationService["NotificationService"]:::infrastructure
        SecretConfig["SecretConfig"]:::infrastructure
        StartChatEvent["StartChatEvent"]:::infrastructure
    end

    %% External Systems
    subgraph "External Systems"
        Firestore["Firebase Firestore"]:::external
        RTDB["Firebase Realtime Database"]:::external
        Storage["Firebase Storage"]:::external
        WSServer["WebSocket Server"]:::external
        STUNTURN["TURN/STUN Servers"]:::external
        GeminiAPI["Gemini API"]:::external
    end

    %% Flow Relationships
    Converters -->|"transforms values"| Views
    Views -->|"bindings/commands"| ChatVM
    Views -->|"bindings/commands"| AIChatVM
    Views -->|"bindings/commands"| CallVM

    ChatVM -->|"publishes"| StartChatEvent
    ChatVM -->|"uses"| FirestoreHelper
    ChatVM -->|"uses"| RTDBHelper
    ChatVM -->|"uses"| StorageHelper
    ChatVM -->|"uses"| WSService
    AIChatVM -->|"calls"| GeminiService
    CallVM -->|"negotiates via"| WSService
    CallVM -->|"establishes peer"| RTCService
    ChatVM -->|"notifies via"| NotificationService

    StartChatEvent -->|"via"| EventAggregator
    NewMsgEvent -->|"via"| EventAggregator
    EventAggregator -->|"notifies"| ChatVM
    EventAggregator -->|"notifies"| AIChatVM
    EventAggregator -->|"notifies"| CallVM

    FirestoreHelper -->|"reads/writes"| Firestore
    RTDBHelper -->|"reads/writes"| RTDB
    StorageHelper -->|"uploads/downloads"| Storage
    WSService -->|"signals with"| WSServer
    RTCService -->|"media via"| STUNTURN
    GeminiService -->|"requests"| GeminiAPI

    %% Click Events
    click Views "https://github.com/biniter1/nt106_-_-n/tree/main/WpfApp1/Views"
    click Converters "https://github.com/biniter1/nt106_-_-n/tree/main/WpfApp1/Converters"
    click AIChatVM "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/ViewModels/AIChatViewModel.cs"
    click ChatVM "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/ViewModels/ChatViewModel.cs"
    click CallVM "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/ViewModels/CallViewModel.cs"
    click NewMsgEvent "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/ViewModels/NewMessageEventArgs.cs"
    click RTDBHelper "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/ViewModels/RealtimeDatabaseHelper.cs"
    click Message "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Models/Message.cs"
    click User "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Models/User.cs"
    click CallSignal "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Models/CallSignal.cs"
    click IceCandidate "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Models/IceCandidateSignal.cs"
    click Group "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Models/Group.cs"
    click FriendRequest "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Models/FriendRequest.cs"
    click EventAggregator "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Services/EventAggregator.cs"
    click WSService "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Services/WebSocketService.cs"
    click RTCService "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Services/WebRTCService.cs"
    click FirestoreHelper "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Models/FirestoreHelper.cs"
    click StorageHelper "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Models/FirebaseStorageHelper.cs"
    click GeminiService "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Services/GeminiService.cs"
    click NotificationService "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Services/NotificationService.cs"
    click SecretConfig "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Services/SecretConfig.cs"
    click StartChatEvent "https://github.com/biniter1/nt106_-_-n/blob/main/WpfApp1/Services/StartChatEvent.cs"

    %% Styles
    classDef presentation fill:#D0E6FF,stroke:#0366D6,stroke-width:1px
    classDef application fill:#DFFFE0,stroke:#228B22,stroke-width:1px
    classDef domain fill:#FFEFD5,stroke:#FF8C00,stroke-width:1px
    classDef infrastructure fill:#F3E5F5,stroke:#800080,stroke-width:1px
    classDef external fill:#E8E8E8,stroke:#666666,stroke-width:1px!important
```
