# swarabhalerao/bmi-calculator architecture

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

- Interactive diagram: https://gitdiagram.com/swarabhalerao/bmi-calculator
- Repository: https://github.com/swarabhalerao/bmi-calculator

## Overview

##### Main Components
- Flutter Application: Represented by the lib directory, this is where the core Flutter code lives. It includes:
- Main Entry Point: lib/main.dart
- UI Screens: lib/screens (e.g., input_page.dart and results_page.dart)
- Custom Widgets/Components: lib/components (e.g., bottom_button.dart, gender_widget.dart, reusable_card.dart, round_icon_button.dart)
- Business Logic: lib/calculator_brain.dart for calculating the BMI.

- Platform Integration Layer:
- Android Native Code: The android directory (including gradle files and AndroidManifest.xml) sets up the Android project, integrating the Flutter layer.
- iOS Native Code: The ios directory has the Xcode project files, Info.plist, and necessary configuration to run the app on iOS.

- Dependency and Build Management:
- Pubspec Files: pubspec.yaml and pubspec.lock for Flutter dependencies.
- Build Scripts: Gradle and Xcode related configuration files in their respective directories.

- Testing:
- Test Directory: Contains widget_test.dart to validate the UI elements and possibly some logic tests.

##### Relationships and Data Flow
- User Interaction: Users input their weight and height via the Input Screen (input_page.dart).
- Data Flow: From the UI, the input is passed to the Calculator Brain (business logic) which then calculates the BMI.
- Flow: The result is sent back and rendered on the Results Screen (results_page.dart).
- Component Interaction: Custom widgets (reusable_card, gender_widget, etc.) encapsulate common functionality used across the UI.
- Platform Bootstrapping: The Android and iOS directories launch the Flutter app on mobile devices through their respective native integration layers.

##### Architectural Patterns
- Separation of Concerns: UI elements, business logic, and platform integrations are clearly separated.
- Modular Design: Custom widgets packaged in the components folder help in reusing functionality.
- Cross-Platform Layer: Flutter abstracts the underlying native platform code allowing common code (lib/) to run on both Android and iOS.

##### Relevant Technologies and Frameworks
- Flutter Framework: Drives the UI and state management.
- Dart: The programming language for both UI and business logic.
- Platform-specific Tools: Android (Gradle/Android Studio) and iOS (Xcode) for native integrations.
- Testing Framework: Flutter’s built-in testing tools for widget testing.

- Use clear labels for each segment/component.
- Dependency on the pubspec configuration for external libraries and assets.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Flutter Application Layer
    subgraph "Flutter Application (lib)"
        MainEntry["main.dart"]:::flutterEntry
        subgraph "UI Layer"
            InputPage["input_page.dart"]:::uiScreen
            ResultsPage["results_page.dart"]:::uiScreen
            subgraph "Custom Components"
                BottomButton["bottom_button.dart"]:::uiComponent
                GenderWidget["gender_widget.dart"]:::uiComponent
                ReusableCard["reusable_card.dart"]:::uiComponent
                RoundIconButton["round_icon_button.dart"]:::uiComponent
            end
        end
        CalcBrain["calculator_brain.dart"]:::businessLogic
    end

    %% Platform Integration Layer
    subgraph "Platform Integration"
        AndroidNative["Android Native"]:::platform
        iOSNative["iOS Native"]:::platform
    end

    %% Dependency and Build Management Layer
    subgraph "Dependency & Build Management"
        Pubspec["pubspec.yaml"]:::dependency
        BuildScripts["Build Scripts"]:::dependency
    end

    %% Testing
    subgraph "Testing"
        WidgetTest["widget_test.dart"]:::testing
    end

    %% Relationships for User Flow and Bootstrapping
    %% User starts interaction on InputPage
    User["User Interaction"]:::external
    User -->|"input"| InputPage
    InputPage -->|"sendDataTo"| CalcBrain
    CalcBrain -->|"resultData"| ResultsPage

    %% Main entry triggers UI and Business Logic startup
    MainEntry --> InputPage
    MainEntry --> CalcBrain

    %% Flutter App is integrated with Native Platforms
    MainEntry -->|"integrates"| AndroidNative
    MainEntry -->|"integrates"| iOSNative

    %% Dependency Management relationship with Flutter App
    MainEntry -->|"configBased"| Pubspec
    MainEntry -->|"using"| BuildScripts

    %% Testing validates UI and logic
    WidgetTest --> InputPage
    WidgetTest --> CalcBrain

    %% Click Events
    click MainEntry "https://github.com/swarabhalerao/bmi-calculator/blob/main/lib/main.dart"
    click InputPage "https://github.com/swarabhalerao/bmi-calculator/blob/main/lib/screens/input_page.dart"
    click ResultsPage "https://github.com/swarabhalerao/bmi-calculator/blob/main/lib/screens/results_page.dart"
    click BottomButton "https://github.com/swarabhalerao/bmi-calculator/blob/main/lib/components/bottom_button.dart"
    click GenderWidget "https://github.com/swarabhalerao/bmi-calculator/blob/main/lib/components/gender_widget.dart"
    click ReusableCard "https://github.com/swarabhalerao/bmi-calculator/blob/main/lib/components/reusable_card.dart"
    click RoundIconButton "https://github.com/swarabhalerao/bmi-calculator/blob/main/lib/components/round_icon_button.dart"
    click CalcBrain "https://github.com/swarabhalerao/bmi-calculator/blob/main/lib/calculator_brain.dart"
    click AndroidNative "https://github.com/swarabhalerao/bmi-calculator/tree/main/android"
    click iOSNative "https://github.com/swarabhalerao/bmi-calculator/tree/main/ios"
    click Pubspec "https://github.com/swarabhalerao/bmi-calculator/blob/main/pubspec.yaml"
    click BuildScripts "https://github.com/swarabhalerao/bmi-calculator/blob/main/android/build.gradle"
    click WidgetTest "https://github.com/swarabhalerao/bmi-calculator/blob/main/test/widget_test.dart"

    %% Styles
    classDef flutterEntry fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef uiScreen fill:#ADD8E6,stroke:#4682B4,stroke-width:2px;
    classDef uiComponent fill:#B0E0E6,stroke:#5F9EA0,stroke-width:2px;
    classDef businessLogic fill:#90EE90,stroke:#32CD32,stroke-width:2px;
    classDef platform fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
    classDef dependency fill:#FFFACD,stroke:#F0E68C,stroke-width:2px;
    classDef testing fill:#D3D3D3,stroke:#A9A9A9,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#FF4500,stroke-width:2px;
```
