# keykoder/tetris-android architecture

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

- Interactive diagram: https://gitdiagram.com/keykoder/tetris-android
- Repository: https://github.com/keykoder/tetris-android

## Overview

##### And Label Main Components
- Android Application Layer: Represent the overall application managed through Android’s framework.
- UI/Presentation Layer: Include all activity components (GameActivity, LevelSelect, LoginActivity, ProfileActivity, RegisterActivity) as they host the game interface and user interactions.
- Game Engine/Logic Component: Identify the game logic classes such as Board, Replay, SinglePiece, Tetromino, and Vector2D. This is where the core Tetris mechanics are implemented.
- Utility and Data Layer: Include supporting classes like NotifyingArrayList (and its listener), PlayerData, and Utils that help manage data and game state.
- Build and Project Configuration: Although not part of runtime, tools like Gradle (with build.gradle files, gradlew wrappers), AndroidManifest.xml, and configuration files (google-services.json, proguard-rules.pro) are essential for the build and deployment process.

##### Relationships and Interactions
- A directional connection from the UI/Presentation Layer to the Game Engine indicating that user actions in the activities trigger game logic operations.
- Demonstrate how the Game Engine uses Resource/Asset Layer elements (e.g., layouts, images, sound files) to render game visuals and audio.

##### Architectural Patterns
- Separation of concerns where Activities handle user interactions and delegate to separate classes (game logic) for the Tetris mechanics.
- The resource management follows the standard Android MVC/MVP style where XML layout files are decoupled from business logic.
- Use of custom utility classes such as NotifyingArrayList suggests an Observer-like pattern for managing state changes in collections.

- Notes on the usage of Gradle as the build tool and Android Manifest file as the entry point of the app configuration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Android Application Layer"
        A("AndroidManifest")
    end

    subgraph "UI/Presentation Layer"
        GA("GameActivity")
        LS("LevelSelect")
        LA("LoginActivity")
        PA("ProfileActivity")
        RA("RegisterActivity")
    end

    subgraph "Game Engine/Logic Component"
        B("Board")
        R("Replay")
        SP("SinglePiece")
        T("Tetromino")
        V("Vector2D")
    end

    subgraph "Utility & Data Layer"
        NA("NotifyingArrayList")
        NL("NotifyingArrayListListener")
        PD("PlayerData")
        U("Utils")
    end

    subgraph "Resources & Assets"
        Res("Resources/Assets")
    end

    subgraph "Build & Config"
        AG("app/build.gradle")
        RG("build.gradle")
        GW("gradlew & Wrapper")
        GS("app/google-services.json")
        PR("app/proguard-rules.pro")
    end

    %% Relationships
    GA -->|"triggers"| B
    LS -->|"selects"| B
    LA -->|"initiates"| GA
    B -->|"renders_with"| Res
    PD -->|"updatesState"| B
    B -->|"spawns"| SP
    AG -->|"configures"| A
    RG -->|"configures"| A
    GW -->|"builds"| A
    GS -->|"configures"| A
    PR -->|"configures"| A

    %% Click Events for Android Application Layer
    click A "https://github.com/keykoder/tetris-android/blob/main/app/src/main/AndroidManifest.xml"

    %% Click Events for UI/Presentation Layer
    click GA "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/activities/GameActivity.java"
    click LS "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/activities/LevelSelect.java"
    click LA "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/activities/LoginActivity.java"
    click PA "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/activities/ProfileActivity.java"
    click RA "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/activities/RegisterActivity.java"

    %% Click Events for Game Engine/Logic Component
    click B "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/game/Board.java"
    click R "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/game/Replay.java"
    click SP "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/game/SinglePiece.java"
    click T "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/game/Tetromino.java"
    click V "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/game/Vector2D.java"

    %% Click Events for Utility & Data Layer
    click NA "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/NotifyingArrayList.java"
    click NL "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/NotifyingArrayListListener.java"
    click PD "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/PlayerData.java"
    click U "https://github.com/keykoder/tetris-android/blob/main/app/src/main/java/com/giratron/tetris/Utils.java"

    %% Click Event for Resources & Assets
    click Res "https://github.com/keykoder/tetris-android/tree/main/app/src/main/res"

    %% Click Events for Build & Config
    click AG "https://github.com/keykoder/tetris-android/blob/main/app/build.gradle"
    click RG "https://github.com/keykoder/tetris-android/blob/main/build.gradle"
    click GW "https://github.com/keykoder/tetris-android/tree/main/gradle/wrapper"
    click GS "https://github.com/keykoder/tetris-android/blob/main/app/google-services.json"
    click PR "https://github.com/keykoder/tetris-android/blob/main/app/proguard-rules.pro"

    %% Styles
    class A androidLayer
    class GA,LS,LA,PA,RA ui
    class B,R,SP,T,V engine
    class NA,NL,PD,U util
    class Res resource
    class AG,RG,GW,GS,PR build

    %% Class Definitions with Colors
    classDef androidLayer fill:#f9d4d4,stroke:#d9534f,stroke-width:2px;
    classDef ui fill:#d4f9d4,stroke:#5cb85c,stroke-width:2px;
    classDef engine fill:#d4e2f9,stroke:#337ab7,stroke-width:2px;
    classDef util fill:#f9f1d4,stroke:#f0ad4e,stroke-width:2px;
    classDef resource fill:#f9d4f9,stroke:#9933ff,stroke-width:2px;
    classDef build fill:#d4d4f9,stroke:#5a5aff,stroke-width:2px;
```
