# amazingcoderpro/harmonyos_2048 architecture

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

- Interactive diagram: https://gitdiagram.com/amazingcoderpro/harmonyos_2048
- Repository: https://github.com/amazingcoderpro/harmonyos_2048

## Overview

##### Project type and purpose
- This is a HarmonyOS native mobile app implementing the classic 2048 puzzle game (4×4 grid) using eTS/ArkUI.
- It’s a pure client-side, standalone game—no external backend. It uses local storage for high-score persistence.

##### File structure
- Top-level modules:
- AppScope/              – global app configuration (app.json5) and shared resources
- entry/                 – the main application module containing:
– src/main/ets/        – ArkUI abilities (EntryAbility, EntryBackupAbility) and pages (Index.ets, SoundManager.ets)
– src/main/resources/  – multi-language strings, media assets (audio, layered images), themes, and profile configs
– src/mock/            – mocking utilities/config for development
– src/ohosTest/        – HarmonyOS integration tests (Ability.test.ets, List.test.ets)
– src/test/            – local unit tests (List.test.ets, LocalUnit.test.ets)
– module.json5         – module metadata for the app module
– hvigorfile.ts        – build tasks (packaging, obfuscation rules)
– obfuscation-rules.txt
- hvigor/                – shared hvigor build configuration
- build-profile.json5    – project-wide build settings
- code-linter.json5      – lint rules
- oh-package.json5 & lock – package dependencies and versioning
- Release/ contains the published .app and screenshot assets.

##### README
- Confirms game features: swipe gestures, merge logic, multiple game modes, theme switching, audio effects, local high-score storage.
- No remote services or login implemented yet—pure single-player.

##### Main components and relationships
a. Components:
1) Application Shell (EntryAbility & EntryBackupAbility)
2) UI Layer (ArkUI pages: Index, SoundManager, Mode/Theme selectors)
3) Game Logic Module (4×4 grid data structure, merge/score algorithms)
4) Resource Manager (multilingual strings, media assets, themes)
5) Local Storage (high-score persistence)
6) Audio Engine (plays .mp3 files for merge, game over etc.)
7) Build Pipeline (Hvizor tasks, obfuscation, packaging)
8) Test Suite (unit tests, integration tests)

b. Relationships & Interactions:
– The Application Shell launches the UI Layer.
– UI Layer captures swipe gestures → invokes Game Logic → updates grid model.
– Game Logic emits events to UI for re-render and to Audio Engine to play sounds.
– When score changes, Game Logic writes to Local Storage via Resource Manager API.
– Resource Manager supplies strings/media to UI.
– Build Pipeline ingests source, applies obfuscation rules, bundles resources, outputs .app.
– Test Suite runs against Game Logic and Abilities in CI.

c. Architectural patterns & principles
– Separation of concerns: UI (presentational) vs. Game Logic (business rules) vs. Resource access.
– ArkUI’s ability/page lifecycle (similar to Activity/Fragment).
– Modular structure: entry module encapsulates all app code, AppScope holds shareable config/resources.
– CI stages: lint → build → obfuscate → package → test.

d. Key technologies/frameworks
– eTS (ArkUI) for declarative UI in .ets files
– HarmonyOS Ability framework (EntryAbility)
– hvigor build tool for custom build steps
– JSON5 for config, theme, and resource descriptors
– Local Storage API for persistence
– Test runner for .ets tests

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Runtime Components
    subgraph "Runtime Components"
        direction TB
        EntryAbility["EntryAbility"]:::runtime
        EntryBackupAbility["EntryBackupAbility"]:::runtime
        IndexPage["Index.ets"]:::runtime
        SoundManager["SoundManager.ets"]:::runtime
        GameEngine["Game Engine"]:::runtime
        AudioEngine["Audio Engine"]:::runtime
        ResourceManager["Resource Manager"]:::resources
        LocalStorage["Local Storage"]:::persistence
    end

    EntryAbility --> IndexPage
    EntryBackupAbility --> IndexPage
    IndexPage --> GameEngine
    SoundManager --> GameEngine
    GameEngine --> IndexPage
    GameEngine --> AudioEngine
    IndexPage --> ResourceManager
    GameEngine --> ResourceManager
    GameEngine --> LocalStorage

    %% Resource Files
    subgraph "Resource Files"
        direction TB
        AppScopeString["AppScope string.json"]:::resources
        EntryString["Entry string.json"]:::resources
        ColorConfig["color.json"]:::resources
        LayeredImage["layered_image.json"]:::resources
        MediaAssets[".mp3 files"]:::resources
    end

    ResourceManager --> AppScopeString
    ResourceManager --> EntryString
    ResourceManager --> ColorConfig
    ResourceManager --> LayeredImage
    ResourceManager --> MediaAssets

    %% Build & Package
    subgraph "Build & Package"
        direction TB
        EntryHvizor["entry/hvigorfile.ts"]:::tool
        EntryObfuscation["entry/obfuscation-rules.txt"]:::tool
        GlobalHvizor["hvigor/hvigor-config.json5"]:::tool
        RootHvizor["hvigorfile.ts"]:::tool
        BuildProfile["build-profile.json5"]:::tool
        CodeLinter["code-linter.json5"]:::tool
        OhPackage["oh-package.json5 & lock"]:::tool
        HvizorPipeline["Hvizor Build Pipeline"]:::tool
        AppPackage[".app Package"]:::tool
    end

    EntryHvizor --> HvizorPipeline
    EntryObfuscation --> HvizorPipeline
    GlobalHvizor --> HvizorPipeline
    RootHvizor --> HvizorPipeline
    BuildProfile --> HvizorPipeline
    CodeLinter --> HvizorPipeline
    OhPackage --> HvizorPipeline
    HvizorPipeline --> AppPackage

    %% Module Configuration
    subgraph "Module Configuration"
        direction TB
        AppScopeAppJson["AppScope/app.json5"]:::config
        EntryModuleJson["entry/src/main/module.json5"]:::config
    end

    AppScopeAppJson --> EntryHvizor
    EntryModuleJson --> EntryHvizor

    %% Test Suite
    subgraph "Test Suite"
        direction TB
        IntegrationAbility["Ability.test.ets"]:::tool
        IntegrationList["List.test.ets (ohosTest)"]:::tool
        UnitList["List.test.ets (test)"]:::tool
        UnitLocal["LocalUnit.test.ets"]:::tool
    end

    IntegrationAbility --> EntryAbility
    IntegrationList --> EntryAbility
    UnitList --> GameEngine
    UnitLocal --> LocalStorage

    %% Click Events
    click EntryAbility "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/src/main/ets/entryability/EntryAbility.ets"
    click EntryBackupAbility "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets"
    click IndexPage "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/src/main/ets/pages/Index.ets"
    click SoundManager "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/src/main/ets/pages/SoundManger.ets"
    click AppScopeString "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/AppScope/resources/base/element/string.json"
    click EntryString "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/src/main/resources/base/element/string.json"
    click ColorConfig "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/src/main/resources/base/element/color.json"
    click LayeredImage "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/src/main/resources/base/media/layered_image.json"
    click MediaAssets "https://github.com/amazingcoderpro/harmonyos_2048/tree/main/entry/src/main/resources/rawfile"
    click EntryHvizor "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/hvigorfile.ts"
    click EntryObfuscation "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/obfuscation-rules.txt"
    click GlobalHvizor "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/hvigor/hvigor-config.json5"
    click RootHvizor "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/hvigorfile.ts"
    click AppScopeAppJson "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/AppScope/app.json5"
    click EntryModuleJson "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/src/main/module.json5"
    click IntegrationAbility "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/src/ohosTest/ets/test/Ability.test.ets"
    click IntegrationList "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/src/ohosTest/ets/test/List.test.ets"
    click UnitList "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/src/test/List.test.ets"
    click UnitLocal "https://github.com/amazingcoderpro/harmonyos_2048/blob/main/entry/src/test/LocalUnit.test.ets"

    %% Styles
    classDef runtime fill:#e0f7fa,stroke:#006064,color:#004d40
    classDef resources fill:#fff9c4,stroke:#f57f17,color:#33691e
    classDef persistence fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20
    classDef tool fill:#ffe0b2,stroke:#ef6c00,color:#e65100
    classDef config fill:#d1c4e9,stroke:#5e35b1,color:#311b92
```
