# shivamsharma-1996/piechatapp architecture

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

- Interactive diagram: https://gitdiagram.com/shivamsharma-1996/piechatapp
- Repository: https://github.com/shivamsharma-1996/piechatapp

## Overview

##### Project type and purpose
- Project type: Android mobile application
- Purpose: Real-time chat app with offline message queuing using PieSocket WebSocket service
- Architecture style: MVVM + Clean Architecture + SOLID principles

##### File structure
Top-level directories and important files
- app/src/main/java/com/shivam/piechatapp/presentation – Jetpack Compose UI components, screens, ViewModels, navigation
- app/src/main/java/com/shivam/piechatapp/domain – Entities, repository interfaces, use cases, domain services (message queue service)
- app/src/main/java/com/shivam/piechatapp/data – Implementations of repositories, network monitors, queue managers, handlers
- app/src/main/java/com/shivam/piechatapp/di – Dagger-Hilt module for wiring dependencies
- manifest, resources (themes, layouts, drawables) under app/src/main/res
- test and androidTest for unit and instrumented tests
Configuration and build
- build.gradle.kts files (project and app level), gradle wrapper, proguard rules

##### README for additional insights
- Tech stack: Kotlin, Jetpack Compose, Material Design, Coroutines + Flow, Dagger-Hilt, PieSocket SDK
- Core features: real-time messaging over WebSocket, offline queuing, auto-retry, network status alerts
- Data flow overview: UI → ViewModel → UseCase → Repository → DataSource (network or queue) → external WebSocket → back up through layers via Flow

##### Main components
a. Presentation Layer
– UI Screens (ConversationsScreen, ChatScreen)
– UI Components (AppTopBar, ConversationItem, ChatMessageItem, NetworkAlert)
– ViewModels (ConversationsViewModel, ChatViewModel)
– Navigation Graph (PieChatNavigation)
b. Domain Layer
– Models (ChatMessage, Conversation, ConnectionStatus, MessageStatus)
– Repository Interfaces (ConversationRepository, WebSocketRepository)
– Use Cases (GetConversationsUseCase, SendMessageUseCase, GetConnectionStatusUseCase)
– Domain Services (MessageQueueService)
c. Data Layer
– Repository Implementations (ConversationRepositoryImpl, PieSocketWebSocketRepository)
– Network Monitoring (NetworkMonitor, NetworkStatusManager)
– Message Handling (MessageHandler)
– Offline Queue Management (MessageQueue, QueueSimulationManager)
d. Infrastructure/DI
– Dagger-Hilt AppModule providing bindings for repositories, services, managers
e. External Services
– PieSocket WebSocket endpoint (wss://…/chat-shivam)
– Device network connectivity

##### Relationships and interactions
- UI emits user actions (send message, load conversations) → ViewModel
- ViewModel calls UseCase → interacts with Repository Interface
- Repository implementation delegates to:
– Online: PieSocketWebSocketRepository (WebSocket send/receive)
– Offline: MessageQueueService + MessageQueue (local in-memory or persistent store)
- NetworkStatusManager monitors connectivity → notifies domain/service layer → triggers queue flush when back online
- Handlers (MessageHandler) process incoming and outgoing messages, map DTOs to domain models
- All asynchronous communication via Kotlin Flow → observed by ViewModels → UI updates

##### Important architectural patterns and design principles
- Clean Architecture separation: presentation, domain, data
- MVVM in presentation with unidirectional data flow
- Dependency Injection with Dagger-Hilt for decoupling
- Repository pattern for data sources
- Service layer for queue management and network operations
- Use of Coroutines + Flow for reactive, asynchronous streams
- SOLID principles for single responsibility, open/closed modules

3. In Domain layer, show UseCases and Domain Services; link ViewModels to UseCases
4. In Data layer, group repository implementations, network manager, queue manager, handlers; link UseCases to appropriate repos/services

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        CS["ConversationsScreen"]:::presentation
        ChS["ChatScreen"]:::presentation
        ATB["AppTopBar"]:::presentation
        CI["ConversationItem"]:::presentation
        CMI["ChatMessageItem"]:::presentation
        NA["NetworkAlert"]:::presentation
        CVM["ConversationsViewModel"]:::presentation
        ChVM["ChatViewModel"]:::presentation
        Nav["PieChatNavigation"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        DM["ChatMessage"]:::domain
        DConv["Conversation"]:::domain
        DCS["ConnectionStatus"]:::domain
        DMS["MessageStatus"]:::domain
        ConvRepoI["ConversationRepository"]:::domain
        WSRepoI["WebSocketRepository"]:::domain
        GCUC["GetConversationsUseCase"]:::domain
        SMUC["SendMessageUseCase"]:::domain
        GCSUC["GetConnectionStatusUseCase"]:::domain
        MQS["MessageQueueService"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        ConvRepoImpl["ConversationRepositoryImpl"]:::data
        WSRepoImpl["PieSocketWebSocketRepository"]:::data
        NetMon["NetworkMonitor"]:::data
        NetSM["NetworkStatusManager"]:::data
        MH["MessageHandler"]:::data
        MQ["MessageQueue"]:::data
        QSim["QueueSimulationManager"]:::data
    end

    %% External Services
    subgraph "External"
        direction TB
        PS["PieSocket WebSocket Endpoint"]:::external
        DN["Device Network"]:::external
    end

    %% DI Module
    AppMod["AppModule"]:::di

    %% Connections Presentation -> Domain
    CS -->|"User action"| CVM
    ChS -->|"User action"| ChVM
    CVM -->|"invoke"| GCUC
    ChVM -->|"invoke"| SMUC
    ChVM -->|"invoke"| GCSUC
    Nav --> CVM
    Nav --> ChVM

    %% Presentation UI Components
    CS --> ATB
    CS --> CI
    CS --> NA
    ChS --> ATB
    ChS --> CMI
    ChS --> NA

    %% Domain UseCases -> Repository Interfaces / Services
    GCUC --> ConvRepoI
    SMUC --> WSRepoI
    GCSUC --> MQS
    MQS --> MQS

    %% Data Layer implementations
    ConvRepoI --> ConvRepoImpl
    WSRepoI --> WSRepoImpl
    MQS --> MQ
    MQS --> QSim
    WSRepoImpl --> MH
    MH --> ConvRepoImpl

    %% Data Layer -> External
    WSRepoImpl -->|"WebSocket"| PS
    NetSM -->|"monitor"| DN
    NetMon --> NetSM
    NetSM --> QSim
    QSim -->|"flush"| WSRepoImpl

    %% DI wiring
    AppMod --> ConvRepoImpl
    AppMod --> WSRepoImpl
    AppMod --> NetMon
    AppMod --> NetSM
    AppMod --> MH
    AppMod --> MQ
    AppMod --> QSim
    AppMod --> CVM
    AppMod --> ChVM
    AppMod --> GCUC
    AppMod --> SMUC
    AppMod --> GCSUC
    AppMod --> MQS

    %% Click Events
    click CS "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/presentation/ui/screens/convesation/ConversationsScreen.kt"
    click ChS "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/presentation/ui/screens/chat/ChatScreen.kt"
    click ATB "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/presentation/ui/components/AppTopBar.kt"
    click CI "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/presentation/ui/components/ConversationItem.kt"
    click CMI "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/presentation/ui/components/ChatMessageItem.kt"
    click NA "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/presentation/ui/components/alerts/network/NetworkAlert.kt"
    click CVM "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/presentation/ui/screens/convesation/ConversationsViewModel.kt"
    click ChVM "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/presentation/ui/screens/chat/ChatViewModel.kt"
    click Nav "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/presentation/navigation/PieChatNavigation.kt"
    click DM "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/domain/model/ChatMessage.kt"
    click DConv "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/domain/model/Conversation.kt"
    click DCS "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/domain/model/ConnectionStatus.kt"
    click DMS "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/domain/model/MessageStatus.kt"
    click ConvRepoI "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/domain/repository/ConversationRepository.kt"
    click WSRepoI "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/domain/repository/WebSocketRepository.kt"
    click GCUC "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/domain/usecase/GetConversationsUseCase.kt"
    click SMUC "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/domain/usecase/SendMessageUseCase.kt"
    click GCSUC "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/domain/usecase/GetConnectionStatusUseCase.kt"
    click MQS "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/domain/service/messagequeue/MessageQueueService.kt"
    click ConvRepoImpl "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/data/repository/ConversationRepositoryImpl.kt"
    click WSRepoImpl "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/data/repository/PieSocketWebSocketRepository.kt"
    click NetMon "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/data/network/NetworkMonitor.kt"
    click NetSM "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/data/network/NetworkStatusManager.kt"
    click MH "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/data/handler/MessageHandler.kt"
    click MQ "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/data/messagequeue/MessageQueue.kt"
    click QSim "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/data/manager/QueueSimulationManager.kt"
    click AppMod "https://github.com/shivamsharma-1996/piechatapp/blob/main/app/src/main/java/com/shivam/piechatapp/di/AppModule.kt"

    %% Styles
    classDef presentation fill:#AED6F1,stroke:#21618C,color:#000
    classDef domain fill:#A9DFBF,stroke:#196F3D,color:#000
    classDef data fill:#F5CBA7,stroke:#B9770E,color:#000
    classDef external fill:#D5D8DC,stroke:#566573,color:#000
    classDef di fill:#FCF3CF,stroke:#B7950B,color:#000
```
