# niochat/nio architecture

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

- Interactive diagram: https://gitdiagram.com/niochat/nio
- Repository: https://github.com/niochat/nio

## Overview

##### Project type and purpose
- This is a full‑stack iOS application (Nio) that implements a Matrix chat client in Swift, using SwiftUI (NioApp.swift, Views, SceneDelegate) and a custom core library (NioKit) for the domain and networking layers. It also provides a share extension (NioShareExtension).

##### High‑level architecture overview
- UI Layer (SwiftUI Views + ViewModels)
– Uses MVVM: each View has an accompanying ViewModel (e.g., MessageViewModel).
- Domain & Networking Layer (NioKit)
– Configuration: loading API endpoints and client settings.
– Session: AccountStore (keychain), MXClient publishers, authentication flows.
– Models: events, room summaries, custom events (edits, reactions).
– Extensions for convenience (Combine wrappers, URL utilities).
- Data & Storage
– AccountStore persists credentials (Keychain).
– No local database; state lives in memory and is rebuilt from server events.
- External Services
– Matrix homeserver via HTTP REST and WebSocket connections.
– Localization service (translate.riot.im for translations).
- Auxiliary Components
– NioShareExtension: separate target/process to capture URLs from share sheet, communicates with the same domain layer.
– Resources: Assets.xcassets, Localizable.strings for i18n.
– CI/CD: GitHub Workflows for iOS build and SwiftLint, Fastlane for automated releases.

##### Diagramming conventions
– Blue: UI components
– Green: Domain/SDK
– Yellow: Networking & storage
– Orange: External services
– Purple: Share extension

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer" 
        class UIContainer ui
        subgraph "Authentication Views"
            LoginView["LoginView"] 
            LoadingView["LoadingView"] 
        end
        subgraph "Conversation Views"
            RoomView["RoomView"]
            RecentRoomsView["RecentRoomsView"]
            RoomListItemView["RoomListItemView"]
            MessageComposerView["MessageComposerView"]
            TypingIndicatorView["TypingIndicatorView"]
            EventViews["Event Views"]
            ContextMenu["ContextMenu"]
        end
        NewConversationView["NewConversationView"]
        SettingsView["SettingsView"]
        AppIcon["AppIcon"]
        SharedViews["Shared Views"]
        Shapes["IndividuallyRoundedRectangle"]
        Utilities["Utilities"]
    end

    %% Domain & Networking Layer
    subgraph "NioKit (Domain & Networking)" 
        class DomainContainer domain
        Configuration["Configuration"]
        Session["Session & AccountStore"]
        Models["Models"]
        Extensions["Extensions"]
        HTTPClient["HTTP REST Client"]
        WebSocketClient["WebSocket Client"]
    end

    %% Storage
    Storage[(Keychain Storage)]:::storage

    %% External Services
    subgraph "External Services"
        MatrixHomeserver["Matrix Homeserver"]
        TranslationService["Translation Service"]
    end

    %% Share Extension
    subgraph "Share Extension"
        class ShareContainer share
        ShareContentView["ShareContentView"]
        ShareViewController["ShareViewController"]
        GetURL["GetURL.js"]
    end

    %% Data flows
    LoginView -->|"user action"| Session
    LoadingView --> Session
    RoomView --> Session
    RecentRoomsView --> Session
    RoomListItemView --> Session
    MessageComposerView --> Session
    TypingIndicatorView --> Session
    EventViews --> Session
    ContextMenu --> Session
    NewConversationView --> Session
    SettingsView --> Session
    SharedViews --> Session
    Shapes --> Session
    Utilities --> Session

    Session --> HTTPClient
    Session --> WebSocketClient
    HTTPClient -->|Request/Response| MatrixHomeserver
    WebSocketClient -->|Live Events| MatrixHomeserver
    MatrixHomeserver -->|Events Stream| WebSocketClient
    WebSocketClient --> Session
    Session -->|publishes events| LoginView
    Session -->|publishes events| RoomView

    Session --> Storage
    Storage --> Session

    TranslationService -->|Translation API| HTTPClient

    %% Share extension flows
    ShareContentView --> Session
    ShareViewController --> Session
    GetURL --> ShareViewController

    %% Click Events
    click LoginView "https://github.com/niochat/nio/blob/stable/Nio/Authentication/LoginView.swift"
    click LoadingView "https://github.com/niochat/nio/blob/stable/Nio/Authentication/LoadingView.swift"
    click RoomView "https://github.com/niochat/nio/blob/stable/Nio/Conversations/RoomView.swift"
    click RecentRoomsView "https://github.com/niochat/nio/blob/stable/Nio/Conversations/RecentRoomsView.swift"
    click RoomListItemView "https://github.com/niochat/nio/blob/stable/Nio/Conversations/RoomListItemView.swift"
    click MessageComposerView "https://github.com/niochat/nio/blob/stable/Nio/Conversations/MessageComposerView.swift"
    click TypingIndicatorView "https://github.com/niochat/nio/blob/stable/Nio/Conversations/TypingIndicatorView.swift"
    click EventViews "https://github.com/niochat/nio/tree/stable/Nio/Conversations/Event Views/"
    click ContextMenu "https://github.com/niochat/nio/tree/stable/Nio/Conversations/ContextMenu/"
    click NewConversationView "https://github.com/niochat/nio/blob/stable/Nio/NewConversation/NewConversationView.swift"
    click SettingsView "https://github.com/niochat/nio/blob/stable/Nio/Settings/SettingsView.swift"
    click AppIcon "https://github.com/niochat/nio/blob/stable/Nio/Settings/AppIcon.swift"
    click SharedViews "https://github.com/niochat/nio/tree/stable/Nio/Shared Views/"
    click Shapes "https://github.com/niochat/nio/blob/stable/Nio/Shapes/IndividuallyRoundedRectangle.swift"
    click Utilities "https://github.com/niochat/nio/tree/stable/Nio/Utility/"
    click Configuration "https://github.com/niochat/nio/blob/stable/NioKit/Configuration/Configuration.swift"
    click Session "https://github.com/niochat/nio/blob/stable/NioKit/Session/AccountStore.swift"
    click Models "https://github.com/niochat/nio/tree/stable/NioKit/Models/"
    click Extensions "https://github.com/niochat/nio/tree/stable/NioKit/Extensions/"
    click ShareContentView "https://github.com/niochat/nio/blob/stable/NioShareExtension/ShareContentView.swift"
    click ShareViewController "https://github.com/niochat/nio/blob/stable/NioShareExtension/ShareViewController.swift"
    click GetURL "https://github.com/niochat/nio/blob/stable/NioShareExtension/GetURL.js"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#024
    classDef domain fill:#D0FFD6,stroke:#060
    classDef net fill:#FFF4C1,stroke:#AA0
    classDef storage fill:#FFF4C1,stroke:#AA0
    classDef external fill:#FFE2B3,stroke:#D67
    classDef share fill:#F6D0FF,stroke:#A0
    class LoginView,LoadingView,RoomView,RecentRoomsView,RoomListItemView,MessageComposerView,TypingIndicatorView,EventViews,ContextMenu,NewConversationView,SettingsView,AppIcon,SharedViews,Shapes,Utilities ui
    class Configuration,Session,Models,Extensions domain
    class HTTPClient,WebSocketClient net
    class Storage storage
    class MatrixHomeserver,TranslationService external
    class ShareContentView,ShareViewController,GetURL share
```
