# lukechern/tetris architecture

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

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

## Overview

##### Project type and purpose
- This is a purely client-side, web-based Tetris game (“俄罗斯方块 AI高清重制摸鱼版”), published as an NPM package and optionally as a Discuz! plugin.
- It provides classic Tetris gameplay plus an AI “golden finger” that predicts landing positions. It’s delivered as static HTML/CSS/JS assets with no backend service.

##### File structure
- Top level
- index_7ree.html – single-page entry point
- package.json – NPM packaging metadata
- demo/ – screenshots for the README
- resource/
- config/ – default (config_system_7ree.js) and user-override (config_user_7ree.js) settings
- css/ – modular CSS files handling layout, themes, animations
- js/ – vanilla-JavaScript modules:
– base_7ree.js (common helpers)
– tetris_7ree.js (core game loop & engine)
– ghost_piece_7ree.js (AI assist / preview)
– celebration_7ree.js, difficulty_7ree.js, etc.
– lang_7ree.js / lang_utils_7ree.js (i18n)
– mo_7ree.js / pc_7ree.js (mobile vs. desktop input handling)
– sound_7ree.js (audio manager)
- sounds/ – background music and SFX assets

##### README for additional insights
- Core features: classic controls, multiple difficulty levels, AI drop-point prediction, lossless scaling & animations, customizable sound/music and speed, cross-platform via browser.
- Distribution: GitHub repo, NPM module (“aitetris”), optional Discuz! plugin.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Browser Environment"]:::external
    Entry["index_7ree.html"]:::external
    Browser --> Entry

    subgraph "Configuration Subsystem"
        SysConfig["config_system_7ree.js"]:::config
        UserConfig["config_user_7ree.js"]:::config
    end
    Entry --> SysConfig
    Entry --> UserConfig

    Loader["Asset Loader"]:::assets
    Entry --> Loader
    Loader --> CSS["CSS Modules"]:::assets
    Loader --> JSMods["JavaScript Modules"]:::assets
    Loader --> SoundsAsset["Sound Assets"]:::assets

    subgraph "Core Modules"
        Engine["Game Engine"]:::core
        AI["AI Assist / Ghost Preview"]:::core
    end
    Loader --> Engine
    Loader --> AI
    SysConfig --> Engine
    UserConfig --> Engine
    Engine <--> AI

    subgraph "UI & Input"
        UI["UI Renderer"]:::ui
        Mob["Mobile Input (mo_7ree.js)"]:::ui
        Desk["Desktop Input (pc_7ree.js)"]:::ui
    end
    Loader --> UI
    SysConfig --> UI
    UserConfig --> UI
    Mob --> UI
    Desk --> UI
    Mob -->|"user events"| Engine
    Desk -->|"user events"| Engine
    Engine -->|"render updates"| UI

    subgraph "Audio Manager"
        Audio["Audio Manager"]:::audio
    end
    Loader --> Audio
    Engine -->|"audio events"| Audio

    subgraph "Internationalization"
        i18n["i18n Module"]:::core
    end
    Loader --> i18n
    UI --> i18n

    subgraph "Supporting UI & Visual Flair"
        Celebration["Celebration Module"]:::ui
        Difficulty["Difficulty Module"]:::core
        CSSExtras["Additional CSS Modules"]:::assets
    end
    Loader --> Celebration
    Loader --> Difficulty
    Loader --> CSSExtras
    Engine --> Celebration

    subgraph "Distribution"
        Package["package.json, README.md, demo/"]:::config
        NPM["NPM Registry"]:::external
        GitHub["GitHub Pages"]:::external
        Discuz["Discuz! Plugin Store"]:::external
    end
    Entry --> Package
    Package --> NPM
    Package --> GitHub
    Entry --> Discuz

    click Entry "https://github.com/lukechern/tetris/blob/main/index_7ree.html"
    click SysConfig "https://github.com/lukechern/tetris/blob/main/resource/config/config_system_7ree.js"
    click UserConfig "https://github.com/lukechern/tetris/blob/main/resource/config/config_user_7ree.js"
    click CSS "https://github.com/lukechern/tetris/tree/main/resource/css/"
    click JSMods "https://github.com/lukechern/tetris/tree/main/resource/js/"
    click SoundsAsset "https://github.com/lukechern/tetris/tree/main/resource/sounds/"
    click Engine "https://github.com/lukechern/tetris/blob/main/resource/js/tetris_7ree.js"
    click AI "https://github.com/lukechern/tetris/blob/main/resource/js/ghost_piece_7ree.js"
    click CSSExtras "https://github.com/lukechern/tetris/tree/main/resource/css/"
    click Package "https://github.com/lukechern/tetris/blob/main/package.json"

    classDef config fill:#CFE2F3,stroke:#0366D6,color:#0366D6;
    classDef core fill:#D9EAD3,stroke:#6AA84F,color:#274E13;
    classDef ui fill:#FCE5CD,stroke:#E69138,color:#7F6000;
    classDef audio fill:#EAD1DC,stroke:#A64D79,color:#741B47;
    classDef assets fill:#EDEDED,stroke:#888888,color:#333333;
    classDef external fill:#F2F2F2,stroke:#AAAAAA,color:#666666;
```
