# izaanshahid/bmi-calculator architecture

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

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

## Overview

##### Project Type and Purpose
- Type: Native iOS mobile application
- Purpose: A simple multi-screen Body Mass Index calculator built to teach MVC, Optionals, and Classes vs. Structs

##### File Structure
- Top-level folders:
– BMI Calculator: contains all Swift code, assets, storyboards
– Documentation: static images
– Project config (.xcodeproj, Info.plist, SceneDelegate.swift, AppDelegate.swift)
- MVC pattern:
– Models: CalculateBrain.swift (contains BMI calculation logic, BMI struct)
– Views: Main.storyboard, LaunchScreen.storyboard, Assets.xcassets
– Controllers: CalculateViewController.swift, ResultViewController.swift
- No external services, network calls, or databases

##### Key Insights from README
- Optionals, MVC, Classes vs. Structs
- Two screens: “Calculate” and “Result”
- No persistent storage or remote APIs

##### Main Components
A. iOS App Shell
– AppDelegate & SceneDelegate (app lifecycle, window setup)
B. View Layer
– Storyboard Scenes:
- Calculate Screen (UITextField for weight & height, UIButton “Calculate”)
- Result Screen (UILabel for BMI value & advice)
– Assets (AppIcon, background images)
C. Controller Layer
– CalculateViewController
- Handles user input, triggers model calculation, performs segue to ResultViewController
– ResultViewController
- Receives BMI data, updates UI
D. Model Layer
– CalculateBrain class
- Contains computeBMI(height, weight) → BMI struct
– BMI struct

##### Relationships & Data Flows
1. App launches → SceneDelegate sets root UINavigationController from Main.storyboard
2. UINavigationController shows CalculateViewController
3. User enters inputs → CalculateViewController reads UITextFields
4. CalculateViewController calls CalculateBrain.calculateBMI(…)
6. CalculateViewController performs segue → passes BMI to ResultViewController

##### Architectural Patterns & Principles
- MVC:
– Model (CalculateBrain + BMI struct) is completely decoupled from ViewControllers
– ViewControllers mediate between Views (storyboards) and Model
- Single Responsibility: each ViewController manages only its own screen
- Dependency Injection: BMI data is injected into the ResultViewController via segue

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "App Shell"
        AppDelegate["AppDelegate"]:::shell
        SceneDelegate["SceneDelegate"]:::shell
        UINavigation["UINavigationController"]:::shell
    end

    subgraph "Project Configuration"
        XcodeProj["Xcode Project File"]:::config
        Info["Info.plist"]:::config
    end

    subgraph "View Layer"
        MainSB["Main.storyboard\n(Calculate & Result Screens)"]:::view
        LaunchSB["LaunchScreen.storyboard"]:::view
        Assets["Assets.xcassets"]:::view
    end

    subgraph "Controller Layer"
        CalcVC["CalculateViewController"]:::controller
        ResultVC["ResultViewController"]:::controller
    end

    subgraph "Model Layer"
        CalcBrain["CalculateBrain\n(class)"]:::model
        BMI["BMI struct"]:::model
    end

    AppDelegate -->|"application:didFinishLaunching"| SceneDelegate
    SceneDelegate -->|"set root UINavigationController\nfrom Main.storyboard"| UINavigation
    UINavigation -->|"initial view controller"| MainSB
    MainSB -->|"embeds CalculateViewController"| CalcVC
    CalcVC -->|"calculateBMI(height:weight:)"| CalcBrain
    CalcBrain -->|"returns BMI instance"| BMI
    CalcVC -->|"performSegue(pass BMI)"| ResultVC
    ResultVC -->|"update UI (value, advice, color)"| MainSB

    click AppDelegate "https://github.com/izaanshahid/bmi-calculator/blob/main/BMI Calculator/AppDelegate.swift"
    click SceneDelegate "https://github.com/izaanshahid/bmi-calculator/blob/main/BMI Calculator/SceneDelegate.swift"
    click MainSB "https://github.com/izaanshahid/bmi-calculator/blob/main/BMI Calculator/Views/Base.lproj/Main.storyboard"
    click LaunchSB "https://github.com/izaanshahid/bmi-calculator/blob/main/BMI Calculator/Base.lproj/LaunchScreen.storyboard"
    click Assets "https://github.com/izaanshahid/bmi-calculator/blob/main/BMI Calculator/Assets.xcassets"
    click CalcVC "https://github.com/izaanshahid/bmi-calculator/blob/main/BMI Calculator/Controllers/CalculateViewController.swift"
    click ResultVC "https://github.com/izaanshahid/bmi-calculator/blob/main/BMI Calculator/Controllers/ResultViewController.swift"
    click CalcBrain "https://github.com/izaanshahid/bmi-calculator/blob/main/BMI Calculator/Controllers/CalculateBrain.swift"
    click Info "https://github.com/izaanshahid/bmi-calculator/blob/main/BMI Calculator/Info.plist"
    click XcodeProj "https://github.com/izaanshahid/bmi-calculator/blob/main/BMI Calculator.xcodeproj/project.pbxproj"

    classDef shell fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef config fill:#eeeeee,stroke:#666,stroke-width:1px,stroke-dasharray: 5 5
    classDef view fill:#add8e6,stroke:#333,stroke-width:1px
    classDef controller fill:#90ee90,stroke:#333,stroke-width:1px
    classDef model fill:#ffa500,stroke:#333,stroke-width:1px
```
