# wu4ngg/wellmate architecture

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

- Interactive diagram: https://gitdiagram.com/wu4ngg/wellmate
- Repository: https://github.com/wu4ngg/wellmate

## Overview

- Frontend (Flutter UI) – This is the primary presentation layer of the application. It covers all the various screens and components defined under the “lib/screen” and “lib/components” directories. Also, note the cross-platform support: Android, iOS, web, desktop (windows, macos, linux).
- State Management / Providers – Components contained in “lib/providers” handle business logic and state changes across the app’s UI.
- API Integration Layer – Organized under “lib/api”, this layer is responsible for interacting with backend services (e.g., for authentication, drug data, payment processing, hospital, and notification-related functions). Each API subdirectory (auth, address, cart, etc.) acts as a repository that abstracts external data communication.
- Data Models – Found under “lib/model”, these define the data structures used throughout the application. They serve as the intermediate form between the UI and data from external services.
- Local Storage and Utilities – Directories such as “lib/storage” (for secure storage) and “lib/utils” provide support for persisting user sessions, caching data, and handling common functions.

##### Relationships and interactions
- The UI components (screens, dialogs, widgets) interact with the state management providers, which in turn call the API layer to fetch or send data.
- The API layer communicates with external services (third-party servers for push notifications, payment gateways, etc.), which then deliver data back through defined repositories.
- Data models act as the shared contract throughout the layers—data received via API calls is converted to models which populate the UI.
- Local secure storage is used by both the API layer (e.g., token management) and state management to persist data across sessions.

##### Important architectural patterns and design principles
- Separation of Concerns – Each directory in “lib” is well-segregated: screens for UI, providers for state, API classes for data fetching, and models for data handling.
- Repository Pattern – Noticed in the “lib/api” folder, where each domain (auth, drug, hospital, etc.) has its own repository to manage external communication.
- Cross-Platform Development – The distinct directories under android, ios, web, etc. indicate platform-specific layers or configurations; however, the core logic resides within the “lib” folder.
- Modular and Scalable Design – The componentized structure allows for independent development and maintenance of features like medication scheduling or payment functionalities.

##### Relevant technologies and frameworks
- Flutter and Dart – The backbone of the application.
- Platform-Specific Configurations – Supported by native folders (android, ios, linux, macos, windows) which encapsulate build configurations and platform-specific integrations.
- External APIs – Although not detailed in the repository, the WellMate system integrates with services for push notifications, payment processing, and possibly barcode scanning.

- Individual components if needed, such as marking specific API repositories (auth, drug, schedule, etc.) and their relationship with corresponding UI screens.
- Don’t hesitate to detail subcomponents like push notifications, payment gateways, and barcode-based imports as standalone entities connected to the API layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer (Flutter UI)"
        UI_Screens["UI Screens"]:::ui
        UI_Components["UI Components"]:::ui
    end

    %% State Management Layer
    subgraph "State Management / Providers"
        Providers["Providers"]:::provider
    end

    %% API Integration Layer
    subgraph "API Integration Layer"
        Main_API["Main API"]:::integration
        Auth_API["Auth API Repository"]:::integration
        Drug_API["Drug API Repository"]:::integration
        Schedule_API["Schedule API Repository"]:::integration
        Notification_API["Notification API Repository"]:::integration
        Payment_API["Payment API Repository"]:::integration
        Address_API["Address API Repository"]:::integration
        Cart_API["Cart API Repository"]:::integration
        Hospital_API["Hospital API Repository"]:::integration
        User_API["User API Repository"]:::integration
    end

    %% External Services Layer
    subgraph "External Services"
        Push_Notifications["Push Notifications"]:::external
        Payment_Gateway["Payment Gateway"]:::external
        Barcode_Scanner["Barcode Scanning/Other APIs"]:::external
    end

    %% Data Models
    Data_Models["Data Models"]:::common

    %% Local Storage and Utilities
    subgraph "Local Storage and Utilities"
        Secure_Storage["Secure Storage"]:::storage
        Utilities["Utilities"]:::storage
    end

    %% Connections between Layers
    UI_Screens -->|"updates"| Providers
    UI_Components -->|"updates"| Providers

    Providers -->|"API calls"| Main_API
    Providers -->|"persists state"| Secure_Storage
    Providers -->|"uses"| Utilities

    Main_API -->|"delegates"| Auth_API
    Main_API -->|"delegates"| Drug_API
    Main_API -->|"delegates"| Schedule_API
    Main_API -->|"delegates"| Notification_API
    Main_API -->|"delegates"| Payment_API
    Main_API -->|"delegates"| Address_API
    Main_API -->|"delegates"| Cart_API
    Main_API -->|"delegates"| Hospital_API
    Main_API -->|"delegates"| User_API

    Notification_API -->|"calls"| Push_Notifications
    Payment_API -->|"calls"| Payment_Gateway
    Drug_API -->|"supports"| Barcode_Scanner

    Main_API -->|"maps data"| Data_Models
    Data_Models -->|"feeds"| Providers
    Data_Models -->|"feeds"| UI_Screens

    Secure_Storage -->|"assists"| Main_API
    Utilities -->|"assists"| Main_API

    %% Click Events
    click UI_Screens "https://github.com/wu4ngg/wellmate/tree/main/lib/screen"
    click UI_Components "https://github.com/wu4ngg/wellmate/tree/main/lib/components"
    click Providers "https://github.com/wu4ngg/wellmate/tree/main/lib/providers"
    click Main_API "https://github.com/wu4ngg/wellmate/blob/main/lib/api/api.dart"
    click Auth_API "https://github.com/wu4ngg/wellmate/blob/main/lib/api/auth/api_repo.dart"
    click Drug_API "https://github.com/wu4ngg/wellmate/blob/main/lib/api/drug/drug_repo.dart"
    click Schedule_API "https://github.com/wu4ngg/wellmate/blob/main/lib/api/schedule/schedule_repo.dart"
    click Notification_API "https://github.com/wu4ngg/wellmate/blob/main/lib/api/notification/notification_repo.dart"
    click Payment_API "https://github.com/wu4ngg/wellmate/blob/main/lib/api/payment/payment_repo.dart"
    click Address_API "https://github.com/wu4ngg/wellmate/tree/main/lib/api/address"
    click Cart_API "https://github.com/wu4ngg/wellmate/tree/main/lib/api/cart"
    click Hospital_API "https://github.com/wu4ngg/wellmate/tree/main/lib/api/hopital"
    click User_API "https://github.com/wu4ngg/wellmate/tree/main/lib/api/user"
    click Data_Models "https://github.com/wu4ngg/wellmate/tree/main/lib/model"
    click Secure_Storage "https://github.com/wu4ngg/wellmate/blob/main/lib/storage/secure_storage.dart"
    click Utilities "https://github.com/wu4ngg/wellmate/tree/main/lib/utils"

    %% Styles
    classDef ui fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef provider fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef integration fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef common fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef storage fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
```
