# crisronda/reactnative-moodle architecture

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

- Interactive diagram: https://gitdiagram.com/crisronda/reactnative-moodle
- Repository: https://github.com/crisronda/reactnative-moodle

## Overview

##### Primary Layers/Components
- Client (Presentation) Layer:
- This includes the UI components (found in the “src/screens” folder, with separate sub-folders for authentication/signin and the main/home screens).
- The navigation layer is managed in “src/navigation” with separate flows for Signin and Main.
- The hooks (in “src/hooks”) support state management for authentication, course retrieval, and user data.

- Business Logic & State Management:
- The Redux components are under “src/redux” with actions, reducers, and types clearly defining the application state and update flows.
- In addition, custom hooks (like useAuth, useCourses, useUser) further encapsulate business logic.

- Service/Integration Layer:
- Service integrations for Moodle are in “src/services/moodle”, while integration with Firebase and Firestore are in “src/services/fcm” and “src/services/firestore” respectively.
- This layer is responsible for handling network calls to external services (Moodle and Firebase) and any data transformation.

- Notification & Wrappers:
- The “src/wrappers/Notifications” directory contains logic for formatting and handling notifications, bridging the native Firebase/FCM notifications.

- Native Code & Platform-Specific Layers:
- The “android” and “ios” directories contain platform-specific configurations and native code (e.g., MainActivity.java, AppDelegate, Xcode project files, and the Gradle configuration).
- These ensure the React Native layer properly integrates with the native runtime and third-party services like Firebase.

##### Relationships & Data Flows
- A user initiates actions via the UI screens (e.g., login or course selection).
- These UI interactions trigger events that are managed by navigation flows and custom hooks.
- Hooks then dispatch actions to the Redux store, which coordinates state updates in the application.
- When actions require external data (like authentication or course information), the Redux actions call corresponding service functions:
- Moodle service calls (authentication and course fetching) located under “src/services/moodle.”
- Firebase/FCM integration for notifications, handled via “src/services/fcm” and “src/wrappers/Notifications.”
- Responses then update the Redux store, which in turn propagates changes back to the UI.
- Native modules in the “android” and “ios” directories ensure proper configuration and integration for platform-specific requirements (e.g., handling push notifications on the device).

##### Architectural Patterns & Design Principles
- The separation of concerns is well-practiced by dividing the project into UI, state management, and service/integration layers.
- Use of Redux and hooks suggests a unidirectional data flow pattern, ensuring predictable state interactions.
- The clear division between service wrappers and presentation components helps with maintainability and testability.
- There's an emphasis on modularity (each service and feature has its own directory) which aligns with modern React Native best practices.

##### Technology and Frameworks
- React Native for building cross-platform mobile apps.
- Redux for state management.
- Firebase (with FCM and Firestore) for backend services like notifications and data persistence.
- Moodle web services for external course data integration.
- Navigation components for handling different flows (Signin and Main).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global Entities
    User("User")
    
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI1("Signin Screen"):::presentation
        UI2("Main Screen"):::presentation
        Nav("Navigation Flow"):::presentation
        Hook1("useAuth.js"):::presentation
        Hook2("useCourses.js"):::presentation
        Hook3("useUser.js"):::presentation
        Hook4("useFetch.js"):::presentation
    end

    %% Business Logic & State Management
    subgraph "Business Logic"
        Redux("Redux Store"):::business
    end

    %% Service / Integration Layer
    subgraph "Service Layer"
        Moodle("Moodle Integration"):::service
        FCM("FCM Service"):::service
        Firestore("Firestore Integration"):::service
    end

    %% Notification & Wrappers
    subgraph "Notification & Wrappers"
        Notif("Notification Handler"):::service
    end

    %% Native Code & Platform-Specific Integration
    subgraph "Native Integration"
        Android("Android Native"):::native
        iOS("iOS Native"):::native
    end

    %% Relationships & Data Flows
    User -->|"initiates"| UI1
    User -->|"initiates"| UI2

    UI1 -->|"navigates"| Nav
    UI2 -->|"navigates"| Nav

    UI1 -->|"triggers"| Hook1
    UI1 -->|"triggers"| Hook2
    UI2 -->|"triggers"| Hook3
    UI2 -->|"triggers"| Hook4

    Hook1 -->|"dispatchAction"| Redux
    Hook2 -->|"dispatchAction"| Redux
    Hook3 -->|"dispatchAction"| Redux
    Hook4 -->|"dispatchAction"| Redux

    Redux -->|"apiRequest"| Moodle
    Moodle -->|"apiResponse"| Redux

    Redux -->|"apiRequest"| Firestore
    Firestore -->|"apiResponse"| Redux

    Redux -->|"registerFCM"| FCM
    FCM -->|"pushNotification"| Notif
    Notif -->|"updateState"| Redux

    Redux -->|"updateUI"| UI1
    Redux -->|"updateUI"| UI2

    Android -->|"nativeBridge"| FCM
    iOS -->|"nativeBridge"| FCM

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef business fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef service fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef native fill:#FFFF99,stroke:#333,stroke-width:2px;

    %% Click Events
    click UI1 "https://github.com/crisronda/reactnative-moodle/tree/main/src/screens/Signin"
    click UI2 "https://github.com/crisronda/reactnative-moodle/tree/main/src/screens/Main"
    click Nav "https://github.com/crisronda/reactnative-moodle/tree/main/src/navigation"
    click Hook1 "https://github.com/crisronda/reactnative-moodle/blob/main/src/hooks/useAuth.js"
    click Hook2 "https://github.com/crisronda/reactnative-moodle/blob/main/src/hooks/useCourses.js"
    click Hook3 "https://github.com/crisronda/reactnative-moodle/blob/main/src/hooks/useUser.js"
    click Hook4 "https://github.com/crisronda/reactnative-moodle/blob/main/src/hooks/useFetch.js"
    click Redux "https://github.com/crisronda/reactnative-moodle/tree/main/src/redux"
    click Moodle "https://github.com/crisronda/reactnative-moodle/tree/main/src/services/moodle"
    click FCM "https://github.com/crisronda/reactnative-moodle/tree/main/src/services/fcm"
    click Firestore "https://github.com/crisronda/reactnative-moodle/tree/main/src/services/firestore"
    click Notif "https://github.com/crisronda/reactnative-moodle/tree/main/src/wrappers/Notifications"
    click Android "https://github.com/crisronda/reactnative-moodle/tree/main/android"
    click iOS "https://github.com/crisronda/reactnative-moodle/tree/main/ios"
```
