# crux-bphc/cms-android architecture

> Architecture diagram of the GitHub repository crux-bphc/cms-android, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/crux-bphc/cms-android
- Repository: https://github.com/crux-bphc/cms-android

## Overview

##### Project Type Analysis
This is a native Android application that interfaces with a Moodle-based CMS system. It's a client-side mobile application with features like course management, content downloading, and push notifications.

##### Main Components

A. Client-Side Components:
- UI Layer (Activities & Fragments)
- View Models Layer
- Data Management Layer
- Network Layer
- Background Services
- File Management System

B. External Services:
- Moodle Server
- Google Authentication
- Firebase Cloud Messaging

**[User Interface Layer]**
- Activities (MainActivity, CourseDetailActivity, TokenActivity)
- Fragments (CourseContent, Notifications, etc.)
- Adapters & Delegates

**[Business Logic Layer]**
- ViewModels (FilesViewModel, TokenViewModel)
- Helper Classes (CourseDataHandler, NotificationHelper)
- Core Components (FileManager, PushNotifRegManager)

**[Data Layer]**
- Models
- Course Models
- Forum Models
- User Models
- Local Storage

**[Network Layer]**
- API Client
- Moodle Services
- Firebase Services

**[External Services]**
- Moodle Server
- Google Auth
- Firebase Cloud Messaging

##### Key Relationships to Highlight

- Data flow between UI and ViewModels (MVVM pattern)
- Network requests from API Client to Moodle server
- File download and storage flow
- Push notification handling path
- Authentication flow with Google services

##### Implementation Details

- Use of Kotlin and Java files
- Use of WorkManager for background tasks
- Integration with Firebase for notifications
- Local storage mechanisms
- File management system

##### Additional Notes

- Offline capability architecture
- Course content synchronization mechanism
- Error handling paths
- Notification system architecture

This system design should clearly communicate how the app interfaces with the Moodle server while maintaining local data and providing offline access to downloaded content.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef business fill:#2ecc71,stroke:#27ae60,color:white
    classDef data fill:#f1c40f,stroke:#f39c12,color:black
    classDef network fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white

    %% User Interface Layer
    subgraph UI
        Activities["Activities"]:::ui
        Fragments["Fragments"]:::ui
        Adapters["Adapters & Delegates"]:::ui
    end

    %% Business Logic Layer
    subgraph BusinessLogic
        ViewModels["ViewModels"]:::business
        HelperClasses["Helper Classes"]:::business
        CoreComponents["Core Components"]:::business
        FileManager["File Manager"]:::business
    end

    %% Data Layer
    subgraph Data
        Models["Data Models"]:::data
        LocalStorage["Local Storage"]:::data
    end

    %% Network Layer
    subgraph Network
        APIClient["API Client"]:::network
        MoodleServices["Moodle Services"]:::network
        FirebaseServices["Firebase Services"]:::network
    end

    %% External Services
    subgraph External
        MoodleServer["Moodle Server"]:::external
        GoogleAuth["Google Auth"]:::external
        FCM["Firebase Cloud Messaging"]:::external
    end

    %% Background Services
    subgraph Background
        WorkManager["WorkManager"]:::business
        NotificationService["Notification Service"]:::business
        DataMigration["Data Migration"]:::business
    end

    %% Relationships
    Activities --> ViewModels
    Fragments --> ViewModels
    ViewModels --> Models
    ViewModels --> APIClient
    APIClient --> MoodleServer
    MoodleServices --> MoodleServer
    FirebaseServices --> FCM
    CoreComponents --> LocalStorage
    FileManager --> LocalStorage
    WorkManager --> DataMigration
    NotificationService --> FirebaseServices
    HelperClasses --> Models
    Models --> LocalStorage

    %% Click events
    click Activities "https://github.com/crux-bphc/cms-android/tree/development/app/src/main/java/crux/bphc/cms/activities/"
    click Fragments "https://github.com/crux-bphc/cms-android/tree/development/app/src/main/java/crux/bphc/cms/fragments/"
    click Adapters "https://github.com/crux-bphc/cms-android/tree/development/app/src/main/java/crux/bphc/cms/adapters/"
    click ViewModels "https://github.com/crux-bphc/cms-android/tree/development/app/src/main/java/crux/bphc/cms/viewmodels/"
    click Models "https://github.com/crux-bphc/cms-android/tree/development/app/src/main/java/crux/bphc/cms/models/"
    click APIClient "https://github.com/crux-bphc/cms-android/blob/development/app/src/main/java/crux/bphc/cms/network/APIClient.java"
    click MoodleServices "https://github.com/crux-bphc/cms-android/blob/development/app/src/main/java/crux/bphc/cms/network/MoodleServices.java"
    click DataMigration "https://github.com/crux-bphc/cms-android/blob/development/app/src/main/java/crux/bphc/cms/background/MigrateDataWorker.kt"
    click NotificationService "https://github.com/crux-bphc/cms-android/blob/development/app/src/main/java/crux/bphc/cms/background/MyFirebaseMessagingService.kt"
    click FileManager "https://github.com/crux-bphc/cms-android/blob/development/app/src/main/java/crux/bphc/cms/core/FileManager.kt"
    click HelperClasses "https://github.com/crux-bphc/cms-android/tree/development/app/src/main/java/crux/bphc/cms/helper/"
    click CoreComponents "https://github.com/crux-bphc/cms-android/blob/development/app/src/main/java/crux/bphc/cms/core/PushNotifRegManager.kt"

    %% Legend
    subgraph Legend
        UI_Legend["UI Components"]:::ui
        Business_Legend["Business Logic"]:::business
        Data_Legend["Data Components"]:::data
        Network_Legend["Network Components"]:::network
        External_Legend["External Services"]:::external
    end
```
