# leoeek/habit-ios architecture

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

- Interactive diagram: https://gitdiagram.com/leoeek/habit-ios
- Repository: https://github.com/leoeek/habit-ios

## Overview

##### Project Type and Purpose
- Project Type: Native iOS client application built with SwiftUI and MVVM
- Purpose: Allow users to sign up, log in, and manage “habits” by interacting with a remote backend web service.

##### File Structure
- HabitApp.swift: Application entry point.
- Top-level feature directories:
– Splash
– SignIn
– SignUp
– Home
- Common: Cross-cutting code
– Lang: String extensions
– Model: Shared data types (ErrorResponse, Gender, etc.)
– Network: WebService.swift (HTTP client)
– View / Style: Reusable SwiftUI views & styles
- Tests: Unit and UI tests

##### README for Additional Insights
- Screenshots confirm a simple sign-up/login flow and a home/dashboard screen.

##### Main Components & Their Relationships
a. UI Layer (SwiftUI Views)
- SplashView, SignInView, SignUpView, HomeView
- Reusable Common/View components (EditTextView, LoadingButtonView)
b. ViewModels (MVVM)
- SplashViewModel, SignInViewModel, SignUpViewModel, HomeViewModel
- Responsible for UI state, validation, paging through flows
c. Network Layer
- WebService.swift: one central HTTP client for REST calls
- Models: SignInRequest/Response, SignUpRequest/Response, ErrorResponse
d. Models & State
- UI state models (e.g. SignInUIState)
- Domain models (e.g. Gender enum)
e. External Services
- Remote Backend API (authentication, habit CRUD)

##### Architectural Patterns & Design Principles
- MVVM: clear separation of Views (display), ViewModels (logic + state), and Models (data).
- Single WebService client for all network calls—promotes reuse and testability.
- SwiftUI + Combine (or async/await) for reactive UI updates.
- Common folder for cross-cutting concerns (string extensions, styles, reusable views).

##### Detailed Elements
- App Entry: HabitApp.swift → initializes root view (SplashView)
- Splash Flow:
– SplashView → SplashViewModel → (maybe) WebService to check auth token → Home or SignIn
- SignIn / SignUp Flow:
– SignInView/SignUpView → corresponding ViewModel → WebService.authenticate or register → handle SignInResponse/SignUpResponse
– On success: navigate to HomeView
- Home Flow:
– HomeView → HomeViewModel → WebService.fetchHabits → display list
- Tests: optionally show a “Tests” boundary that invokes ViewModels and WebService mocks.

3. In the Network column, place WebService.
4. In the External API column, place “Habit Backend Service”.
5. In the Models column, list request/response models.

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "UI Layer"
    HabitApp["HabitApp"]:::ui
    SplashView["SplashView"]:::ui
    SignInView["SignInView"]:::ui
    SignUpView["SignUpView"]:::ui
    HomeView["HomeView"]:::ui
    EditTextView["EditTextView"]:::ui
    LoadingButtonView["LoadingButtonView"]:::ui
    CustomTextFieldStyle["CustomTextFieldStyle"]:::ui
  end

  subgraph "ViewModel Layer"
    SplashViewModel["SplashViewModel"]:::vm
    SplashViewRouter["SplashViewRouter"]:::vm
    SignInViewModel["SignInViewModel"]:::vm
    SignInViewRouter["SignInViewRouter"]:::vm
    SignUpViewModel["SignUpViewModel"]:::vm
    SignUpViewRouter["SignUpViewRouter"]:::vm
    HomeViewModel["HomeViewModel"]:::vm
  end

  subgraph "Network Layer"
    WebService["WebService"]:::network
  end

  subgraph "External API"
    HabitBackendService["Habit Backend Service"]:::external
  end

  subgraph "Models"
    ErrorResponse["ErrorResponse"]:::model
    Gender["Gender"]:::model
    SplashUIState["SplashUIState"]:::model
    SignInRequest["SignInRequest"]:::model
    SignInResponse["SignInResponse"]:::model
    SignInErrorResponse["SignInErrorResponse"]:::model
    SignInUIState["SignInUIState"]:::model
    SignUpRequest["SignUpRequest"]:::model
    SignUpResponse["SignUpResponse"]:::model
    SignUpUIState["SignUpUIState"]:::model
  end

  HabitApp --> SplashView
  SplashView --> SplashViewModel
  SplashViewModel -->|"checkAuth()"| WebService
  WebService -->|"checkAuth(request/response)"| HabitBackendService
  HabitBackendService -->|"auth result"| WebService
  WebService --> ErrorResponse
  WebService --> Gender
  SplashViewModel -->|"onAuthenticated"| HomeView
  SplashViewModel -->|"onUnauthenticated"| SignInView

  SignInView --> SignInViewModel
  SignInViewModel -->|"login(request)"| WebService
  WebService -->|"authenticate"| HabitBackendService
  HabitBackendService -->|"login response"| WebService
  SignInViewModel --> SignInUIState
  SignInViewModel -->|"onSuccess"| HomeView

  SignUpView --> SignUpViewModel
  SignUpViewModel -->|"signup(request)"| WebService
  WebService -->|"register"| HabitBackendService
  HabitBackendService -->|"signup response"| WebService
  SignUpViewModel --> SignUpUIState
  SignUpViewModel -->|"onSuccess"| HomeView

  HomeView --> HomeViewModel
  HomeViewModel -->|"fetchHabits()"| WebService
  WebService -->|"fetchHabits"| HabitBackendService
  HabitBackendService -->|"habits data"| WebService
  HomeViewModel --> HomeView

  SignInView --> EditTextView
  SignInView --> LoadingButtonView
  SignUpView --> EditTextView
  SignUpView --> LoadingButtonView
  SplashView --> CustomTextFieldStyle
  SignInView --> CustomTextFieldStyle
  SignUpView --> CustomTextFieldStyle
  HomeView --> CustomTextFieldStyle

  classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6
  classDef vm fill:#DFFFE0,stroke:#28A745,color:#28A745
  classDef network fill:#FFE8D0,stroke:#DE6823,color:#DE6823
  classDef external fill:#F0D0FF,stroke:#6F42C1,color:#6F42C1
  classDef model fill:#F0F0F0,stroke:#6A737D,color:#6A737D

  click HabitApp "https://github.com/leoeek/habit-ios/blob/main/Habit/HabitApp.swift"
  click SplashView "https://github.com/leoeek/habit-ios/blob/main/Habit/Splash/View/SplashView.swift"
  click SignInView "https://github.com/leoeek/habit-ios/blob/main/Habit/SignIn/View/SignInView.swift"
  click SignUpView "https://github.com/leoeek/habit-ios/blob/main/Habit/SignUp/View/SignUpView.swift"
  click HomeView "https://github.com/leoeek/habit-ios/blob/main/Habit/Home/View/HomeView.swift"
  click EditTextView "https://github.com/leoeek/habit-ios/blob/main/Habit/Common/View/EditTextView.swift"
  click LoadingButtonView "https://github.com/leoeek/habit-ios/blob/main/Habit/Common/View/LoadingButtonView.swift"
  click CustomTextFieldStyle "https://github.com/leoeek/habit-ios/blob/main/Habit/Common/View/Style/CustomTextFieldStyle.swift"
  click SplashViewModel "https://github.com/leoeek/habit-ios/blob/main/Habit/Splash/ViewModel/SplashViewModel.swift"
  click SplashViewRouter "https://github.com/leoeek/habit-ios/blob/main/Habit/Splash/ViewModel/SplashViewRouter.swift"
  click SignInViewModel "https://github.com/leoeek/habit-ios/blob/main/Habit/SignIn/ViewModel/SignInViewModel.swift"
  click SignInViewRouter "https://github.com/leoeek/habit-ios/blob/main/Habit/SignIn/ViewModel/SignInViewRouter.swift"
  click SignUpViewModel "https://github.com/leoeek/habit-ios/blob/main/Habit/SignUp/ViewModel/SignUpViewModel.swift"
  click SignUpViewRouter "https://github.com/leoeek/habit-ios/blob/main/Habit/SignUp/ViewModel/SignUpViewRouter.swift"
  click HomeViewModel "https://github.com/leoeek/habit-ios/blob/main/Habit/Home/ViewModel/HomeViewModel.swift"
  click WebService "https://github.com/leoeek/habit-ios/blob/main/Habit/Common/Network/WebService.swift"
  click ErrorResponse "https://github.com/leoeek/habit-ios/blob/main/Habit/Common/Model/ErrorResponse.swift"
  click Gender "https://github.com/leoeek/habit-ios/blob/main/Habit/Common/Model/Gender.swift"
  click SplashUIState "https://github.com/leoeek/habit-ios/blob/main/Habit/Splash/Model/SplashUIState.swift"
  click SignInRequest "https://github.com/leoeek/habit-ios/blob/main/Habit/SignIn/Model/SignInRequest.swift"
  click SignInResponse "https://github.com/leoeek/habit-ios/blob/main/Habit/SignIn/Model/SignInResponse.swift"
  click SignInErrorResponse "https://github.com/leoeek/habit-ios/blob/main/Habit/SignIn/Model/SignInErrorResponse.swift"
  click SignInUIState "https://github.com/leoeek/habit-ios/blob/main/Habit/SignIn/Model/SignInUIState.swift"
  click SignUpRequest "https://github.com/leoeek/habit-ios/blob/main/Habit/SignUp/Model/SignUpRequest.swift"
  click SignUpResponse "https://github.com/leoeek/habit-ios/blob/main/Habit/SignUp/Model/SignUpResponse.swift"
  click SignUpUIState "https://github.com/leoeek/habit-ios/blob/main/Habit/SignUp/Model/SignUpUIState.swift"
```
