# team-hmh/hmh-android architecture

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

- Interactive diagram: https://gitdiagram.com/team-hmh/hmh-android
- Repository: https://github.com/team-hmh/hmh-android

## Overview

##### Project Type & Purpose
- This is a multi-module Android mobile application (“하면함 Android”) that helps users break smartphone addiction.
- It follows a clean, layered, MVVM-style architecture with Dagger-Hilt for DI, Kotlin Coroutines/Flow, Material3, and custom Gradle convention plugins.

##### High-Level Layers & Modules
- UI / Feature layer (“feature/*” modules)
- Presentation / ViewModel layer (“core/viewmodel” module)
- Domain layer (“domain/*” modules)
- Data layer (“data/*” modules)
- Core libraries (“core/common”, “core/designsystem”, “core/network”, “core/database”, “core/service”)
- App container (“app” module)
- External services: REST APIs, Firebase, Room DB, Android UsageStats & Foreground Service

##### Main Components & Interactions
a. Feature Modules (UI)
- e.g. feature/login, feature/main, feature/challenge, feature/lock, feature/mypage, feature/onboarding, feature/store
- Provide Activities/Fragments → bind to corresponding ViewModels
b. ViewModel Layer
- core/viewmodel: exposes state/effects to UI, invokes domain use-cases
c. Domain Layer
- Use-case classes and Repository interfaces (e.g. LoginRepository, ChallengeRepository)
- Contains pure business logic, independent of data source
d. Data Layer
- data/* modules: implement Repository interfaces
- Each has localDataSource (Room, UsageStats), remoteDataSource (Retrofit APIs)
- Network/DB models ↔ domain models
e. Core Libraries
- core/network: Retrofit, OkHttp, Auth interceptor, Hilt modules for network
- core/database: RoomDatabase, DAOs, Hilt modules for DB
- core/common & designsystem: shared UI components, helpers, themes
- core/service: ForegroundService for app lock/notifications
f. App Module
- “app”: AndroidManifest, Application subclass, Hilt entry point, glues all modules
g. External Systems
- Backend REST API (Auth, Challenge, Point, MyPage, UsageGoal, etc.)
- Firebase utils
- Android OS: UsageStatsManager, NotificationManager, Foreground Service
- Local Room database

##### Data Flow & Dependency Directions
- UI → ViewModel → Domain use-cases → Repository interface → Data layer → (Network API or Room DB) → back to UI
- All dependencies point inward: feature → core/viewmodel → domain → data → core libraries → external

##### Architectural Patterns & Design Principles
- Clean Architecture / Layered + MVVM
- Single-direction dependency flow
- Separation of concerns: UI vs. state vs. business logic vs. data sources
- DI with Dagger-Hilt: denote Hilt Component at center or top, pointing to modules across layers

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "App Module"
        style AppModule fill:#ffffff,stroke:#000000,stroke-dasharray: 5 5

        subgraph "Feature (UI Layer)"
            direction TB
            Login["feature/login"] 
            MainFeature["feature/main"] 
            Challenge["feature/challenge"] 
            Lock["feature/lock"] 
            MyPage["feature/mypage"] 
            Onboarding["feature/onboarding"] 
            Store["feature/store"] 
        end

        subgraph "ViewModel Layer"
            VM["core/viewmodel"] 
        end

        subgraph "Domain Layer"
            direction TB
            DomChallenge["domain/challenge"] 
            DomLock["domain/lock"] 
            DomLogin["domain/login"] 
            DomMain["domain/main"] 
            DomPoint["domain/point"] 
            DomUsage["domain/usagestats"] 
            DomUserInfo["domain/userinfo"] 
        end

        subgraph "Data Layer"
            direction TB
            DataChallenge["data/challenge"] 
            DataDevice["data/device"] 
            DataLock["data/lock"] 
            DataLogin["data/login"] 
            DataMain["data/main"] 
            DataPoint["data/point"] 
            DataUsage["data/usagestats"] 
            DataUserInfo["data/userinfo"] 
        end

        subgraph "Core Libraries"
            CoreCommon["core/common"] 
            CoreDS["core/designsystem"] 
            CoreNet["core/network"] 
            CoreDB["core/database"] 
            CoreSvc["core/service"] 
        end

        subgraph "External Systems"
            RESTAPI[(REST API)] 
            Firebase[(Firebase)] 
            RoomDB[(Room Database)] 
            UsageStatsMgr[(UsageStatsManager)] 
            NotificationMgr[(NotificationManager)] 
        end

        %% Layer arrows
        Login -->|invokes| VM
        MainFeature -->|invokes| VM
        Challenge -->|invokes| VM
        Lock -->|invokes| VM
        MyPage -->|invokes| VM
        Onboarding -->|invokes| VM
        Store -->|invokes| VM

        VM -->|calls UseCases| DomChallenge
        VM -->|calls UseCases| DomLock
        VM -->|calls UseCases| DomLogin
        VM -->|calls UseCases| DomMain
        VM -->|calls UseCases| DomPoint
        VM -->|calls UseCases| DomUsage
        VM -->|calls UseCases| DomUserInfo

        DomChallenge -->|implements| DataChallenge
        DomLock -->|implements| DataLock
        DomLogin -->|implements| DataLogin
        DomMain -->|implements| DataMain
        DomPoint -->|implements| DataPoint
        DomUsage -->|implements| DataUsage
        DomUserInfo -->|implements| DataUserInfo

        DataChallenge -->|uses| CoreDB
        DataChallenge -->|uses| CoreNet
        DataLogin -->|uses| CoreNet
        DataLock -->|uses| CoreSvc
        DataUsage -->|uses| CoreSvc
        DataUserInfo -->|uses| CoreNet
        DataMain -->|uses| CoreNet
        DataPoint -->|uses| CoreNet
        DataDevice -->|uses| CoreSvc

        CoreNet -->|Retrofit| RESTAPI
        CoreDB -->|Room| RoomDB
        CoreSvc -->|ForegroundService| UsageStatsMgr
        CoreSvc -->|Notifications| NotificationMgr
        app_ext -->|auth utils| Firebase

        %% Example Challenge Flow
        Challenge -->|shows UI| VM
        VM -->|ChallengeViewModel| DomChallenge
        DomChallenge -->|NewChallengeUseCase| DataChallenge
        DataChallenge -->|LocalDS| CoreDB
        DataChallenge -->|RemoteDS| CoreNet

    end

    %% Click events
    click Login "https://github.com/team-hmh/hmh-android/tree/develop/feature/login"
    click MainFeature "https://github.com/team-hmh/hmh-android/tree/develop/feature/main"
    click Challenge "https://github.com/team-hmh/hmh-android/tree/develop/feature/challenge"
    click Lock "https://github.com/team-hmh/hmh-android/tree/develop/feature/lock"
    click MyPage "https://github.com/team-hmh/hmh-android/tree/develop/feature/mypage"
    click Onboarding "https://github.com/team-hmh/hmh-android/tree/develop/feature/onboarding"
    click Store "https://github.com/team-hmh/hmh-android/tree/develop/feature/store"
    click VM "https://github.com/team-hmh/hmh-android/tree/develop/core/viewmodel/main"
    click DomChallenge "https://github.com/team-hmh/hmh-android/tree/develop/domain/challenge"
    click DomLock "https://github.com/team-hmh/hmh-android/tree/develop/domain/lock"
    click DomLogin "https://github.com/team-hmh/hmh-android/tree/develop/domain/login"
    click DomMain "https://github.com/team-hmh/hmh-android/tree/develop/domain/main"
    click DomPoint "https://github.com/team-hmh/hmh-android/tree/develop/domain/point"
    click DomUsage "https://github.com/team-hmh/hmh-android/tree/develop/domain/usagestats"
    click DomUserInfo "https://github.com/team-hmh/hmh-android/tree/develop/domain/userinfo"
    click DataChallenge "https://github.com/team-hmh/hmh-android/tree/develop/data/challenge"
    click DataDevice "https://github.com/team-hmh/hmh-android/tree/develop/data/device"
    click DataLock "https://github.com/team-hmh/hmh-android/tree/develop/data/lock"
    click DataLogin "https://github.com/team-hmh/hmh-android/tree/develop/data/login"
    click DataMain "https://github.com/team-hmh/hmh-android/tree/develop/data/main"
    click DataPoint "https://github.com/team-hmh/hmh-android/tree/develop/data/point"
    click DataUsage "https://github.com/team-hmh/hmh-android/tree/develop/data/usagestats"
    click DataUserInfo "https://github.com/team-hmh/hmh-android/tree/develop/data/userinfo"
    click CoreCommon "https://github.com/team-hmh/hmh-android/tree/develop/core/common"
    click CoreDS "https://github.com/team-hmh/hmh-android/tree/develop/core/designsystem"
    click CoreNet "https://github.com/team-hmh/hmh-android/tree/develop/core/network"
    click CoreDB "https://github.com/team-hmh/hmh-android/tree/develop/core/database"
    click CoreSvc "https://github.com/team-hmh/hmh-android/tree/develop/core/service"
    click AppModule "https://github.com/team-hmh/hmh-android/blob/develop/app/src/main/java/com/hmh/hamyeonham/HMHApplication.kt"

    %% Styles
    classDef feature fill:#e0f2f1,stroke:#004d40
    class Login,MainFeature,Challenge,Lock,MyPage,Onboarding,Store feature
    classDef vm fill:#e3f2f d,stroke:#0d47a1
    class VM vm
    classDef domain fill:#fff8e1,stroke:#f9a825
    class DomChallenge,DomLock,DomLogin,DomMain,DomPoint,DomUsage,DomUserInfo domain
    classDef data fill:#f3e5f5,stroke:#6a1b9a
    class DataChallenge,DataDevice,DataLock,DataLogin,DataMain,DataPoint,DataUsage,DataUserInfo data
    classDef core fill:#eceff1,stroke:#455a64
    class CoreCommon,CoreDS,CoreNet,CoreDB,CoreSvc core
    classDef external fill:#ffebee,stroke:#b71c1c
    class RESTAPI,Firebase,RoomDB,UsageStatsMgr,NotificationMgr external
    class AppModule external
```
