# bpup-suite/messanger_client architecture

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

- Interactive diagram: https://gitdiagram.com/bpup-suite/messanger_client
- Repository: https://github.com/bpup-suite/messanger_client

## Overview

##### Main Components
- User Interface (UI) Layer:
- Screens/Pages organized under the /app directory (including ChatList, ChatContent, Search, VocalContent, and several authentication screens in /loginSignup).
- Route management (using expo-router with _layout.jsx) that handles screen layout and navigation (including dynamically routed messages pages in /messages).
- Component Library:
- Reusable UI components located in /app/components (e.g., CreateGroupModal, SidebarItem).
- State & Context Management:
- The /context directory (ThemeContext.js) to handle the app’s themes.
- EventEmitter (in /app/utils/EventEmitter.js) to broadcast changes between components (for instance, updating chat lists when a new message arrives).
- Utility Services:
- API Methods (/utils/APImethods.js) for handling backend REST API calls.
- Websocket Methods (/utils/webSocketMethods.js) for managing realtime communication sessions.
- Local Database Methods (/utils/localDatabaseMethods.js) for session management via AsyncStorage and caching.
- Supplementary utilities such as JSON parsing (/utils/JsonParser.js) to handle API responses.
- Static Assets & Constants:
- Assets (images, fonts under /assets).

##### Relationships and Interactions
- The UI layer consumes the utility services. For example, when a user logs in via /loginSignup/LoginPassword, after successful authentication the app:
- Saves session data in a local database.
- Opens a WebSocket connection using methods from /utils/webSocketMethods.js.
- Uses EventEmitter to update the ChatList with any new message alerts.
- The dynamic routing visible in /messages handles navigation to specific chat screens based on chatId, thus linking both the ChatList and ChatContent functionalities.
- The context layer (ThemeContext) supplies theming and styling data to various screens and components.
- All API interactions are abstracted into dedicated methods from /utils/APImethods.js, ensuring separation of concerns.

##### Architectural Patterns and Design Principles
- Separation of Concerns: There’s a clear distinction between UI screens, utility functions, static assets, and configuration.
- Modular Design: The division into directories like /loginSignup, /messages, and /utils shows a modular structure that aids in scalability and maintainability.
- Responsive Layout: The ChatList component adapts its layout based on screen size—demonstrating responsive design principles.
- Event-Driven Updates: The use of an EventEmitter simplifies how data flow and events (such as incoming messages) update the UI.

##### Relevant Technologies and Frameworks
- React Native (with Expo given the app.json and _layout.jsx for expo-router).
- API calls likely utilize modern JavaScript (Fetch or Axios) for asynchronous operations.
- WebSocket communications managed by custom utility methods, ensuring realtime messaging.
- AsyncStorage for maintaining session persistence on the client.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        _layout["_layout.jsx"]:::ui
        ChatList["ChatList Screen"]:::ui
        ChatContent["ChatContent Screen"]:::ui
        Search["Search Screen"]:::ui
        Vocal["VocalContent Screen"]:::ui
        Login["Login/Signup Screens"]:::ui
        MessageRoutes["Dynamic Message Routes"]:::ui
    end

    %% Component Library
    subgraph "Component Library"
        CompLib["Reusable UI Components"]:::comp
    end

    %% State & Context Management
    subgraph "State & Context Management"
        ThemeContext["ThemeContext"]:::ctx
        EventEmitter["EventEmitter"]:::ctx
    end

    %% Utility Services
    subgraph "Utility Services"
        APIMethods["API Methods"]:::util
        WSMethods["WebSocket Methods"]:::util
        LocalDB["Local Database Methods"]:::util
        JsonParser["JSON Parser Utility"]:::util
    end

    %% Static Assets & Constants
    subgraph "Static Assets & Constants"
        Assets["Assets"]:::assets
        ThemingConstants["Theming Constants"]:::assets
    end

    %% Interactions and Dataflows
    %% Routing and Navigation within UI
    _layout -->|"routes to"| ChatList
    _layout -->|"routes to"| ChatContent
    _layout -->|"routes to"| Search
    _layout -->|"routes to"| Vocal
    _layout -->|"routes to"| Login
    _layout -->|"routes to"| MessageRoutes

    %% UI Layer using Reusable Components
    ChatList -->|"renders"| CompLib
    ChatContent -->|"renders"| CompLib
    Search -->|"renders"| CompLib
    Vocal -->|"renders"| CompLib
    Login -->|"renders"| CompLib
    MessageRoutes -->|"renders"| CompLib

    %% Theming context used by UI components
    ThemeContext -->|"supplies theme"| _layout
    ThemeContext -->|"supplies theme"| ChatList
    ThemeContext -->|"supplies theme"| ChatContent
    ThemeContext -->|"supplies theme"| Search
    ThemeContext -->|"supplies theme"| Vocal
    ThemeContext -->|"supplies theme"| Login
    ThemeContext -->|"supplies theme"| MessageRoutes

    %% Login flow: initiating API calls and services
    Login -->|"loginCall"| APIMethods
    APIMethods -->|"parses response"| JsonParser
    APIMethods -->|"store session"| LocalDB
    Login -->|"initWebSocket"| WSMethods
    WSMethods -->|"trigger event"| EventEmitter
    EventEmitter -->|"update chat list"| ChatList

    %% Assets and Constants used across UI
    Assets -->|"support assets"| _layout
    ThemingConstants -->|"defines UI colors"| ThemeContext

    %% Class Definitions for styling
    classDef ui fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef comp fill:#F9E79F,stroke:#7D6608,stroke-width:2px;
    classDef ctx fill:#D5F5E3,stroke:#1D8348,stroke-width:2px;
    classDef util fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef assets fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;

    %% Click Events
    click _layout "https://github.com/bpup-suite/messanger_client/blob/main/Messanger/app/_layout.jsx"
    click ChatList "https://github.com/bpup-suite/messanger_client/blob/main/Messanger/app/ChatList.jsx"
    click ChatContent "https://github.com/bpup-suite/messanger_client/blob/main/Messanger/app/ChatContent.jsx"
    click Search "https://github.com/bpup-suite/messanger_client/blob/main/Messanger/app/Search.jsx"
    click Vocal "https://github.com/bpup-suite/messanger_client/blob/main/Messanger/app/VocalContent.jsx"
    click Login "https://github.com/bpup-suite/messanger_client/tree/main/Messanger/app/loginSignup"
    click MessageRoutes "https://github.com/bpup-suite/messanger_client/tree/main/Messanger/app/messages"
    click CompLib "https://github.com/bpup-suite/messanger_client/tree/main/Messanger/app/components"
    click ThemeContext "https://github.com/bpup-suite/messanger_client/blob/main/Messanger/context/ThemeContext.js"
    click EventEmitter "https://github.com/bpup-suite/messanger_client/blob/main/Messanger/app/utils/EventEmitter.js"
    click APIMethods "https://github.com/bpup-suite/messanger_client/blob/main/Messanger/app/utils/APImethods.js"
    click WSMethods "https://github.com/bpup-suite/messanger_client/blob/main/Messanger/app/utils/webSocketMethods.js"
    click LocalDB "https://github.com/bpup-suite/messanger_client/blob/main/Messanger/app/utils/localDatabaseMethods.js"
    click JsonParser "https://github.com/bpup-suite/messanger_client/blob/main/Messanger/app/utils/JsonParser.js"
    click Assets "https://github.com/bpup-suite/messanger_client/tree/main/Messanger/assets"
    click ThemingConstants "https://github.com/bpup-suite/messanger_client/blob/main/Messanger/constants/Colors.ts"
```
