# chieri-jn/zenmode architecture

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

- Interactive diagram: https://gitdiagram.com/chieri-jn/zenmode
- Repository: https://github.com/chieri-jn/zenmode

## Overview

##### Project type and purpose
- ZenMode is a standalone, client-side desktop game written in Python.
- It uses the CMU 15-112 graphics framework (cmu_112_graphics.py) to render screens and handle user events.
- The game logic revolves around a “zen” quiz, word-collection gameplay (synonyms/antonyms), and multiple screens (start, quiz, game, pause, help, win/loss).

##### File structure
Top-level files and folders:
- Main.py           – entry point; defines screens, event handlers, game loop
- cmu_112_graphics.py – graphics & UI engine (event loop, drawing callbacks)
- classes.py        – game-domain classes (e.g., Word objects, Player state, maybe fractal tree generator)
- dictionaries.py   – word lists (synonyms, antonyms) and data structures to look them up
- drawings.py       – drawing routines for custom graphics (fractal tree, UI widgets)
- slimeSprites/     – image assets for word “slimes” and UI elements
- README.md & demo-video.txt – documentation

##### Key insights from the README
- Libraries: only PIL (for image handling) and cmu_112_graphics.
- No network, no database—everything is file-based and in-memory.
- Users navigate between screens via keyboard; game state is advanced in response to key events.

##### Main components
1. Frontend / UI Engine
– CMU_112_Graphics Framework (cmu_112_graphics.py)
- Event Loop & Event Dispatcher
- Canvas Manager & Drawing API
2. Application Controller
– Main.py
- Screen Manager (Start, Quiz, Game, Pause, Help, Win/Loss)
- Keyboard & Mouse Event Handlers
- State Machine Transitions
3. Game Logic Layer
– classes.py
- Data Models: PlayerState, WordItem, ZenQuiz, FractalTree
- Game Rules Engine: collision detection, point updates
4. Domain Data / Resources
– dictionaries.py
- Synonym & Antonym Data Structures
– slimeSprites/
- Image assets loaded via PIL
– texts_colours.py
– drawings.py
- Helper functions for drawing fractal trees, backgrounds, UI elements
5. External Library
– PIL (Python Imaging Library)

##### Relationships and data flows
- User Input (keyboard) → CMU Graphics Event Loop → Main.py handler
- Main.py → updates Game State via classes.py → queries dictionaries.py → returns word buckets
- CMU Graphics → renders frames → user sees updated UI on screen
- Asset loading: slimeSprites images are loaded once (at startup or on-demand) via PIL into memory

##### Architectural patterns & design principles
- Model-View-Controller (MVC) style separation:
– Model: classes.py + dictionaries.py
– View: cmu_112_graphics + drawings.py + texts_colours.py + slimeSprites
– Controller: Main.py orchestrating screens and events
- Event-driven architecture: all user interactions route through the CMU event loop.
- Modular design: each concern (data, drawing, control) lives in its own module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entities
    User(("User")):::externalEntity
    Screen[/Screen Display/]:::externalEntity

    %% External Framework
    CMU["CMU_112_Graphics\n(UI Engine)"]:::framework

    %% Application Modules
    Main["Main Controller\n(Main.py)\nScreen Manager & Event Handlers"]:::module
    GameLogic["Game Logic\n(classes.py)"]:::module
    Dicts["Dictionaries\n(dictionaries.py)"]:::module
    TextCol["Texts & Colours\n(texts_colours.py)"]:::asset
    DrawHelpers["Drawing Helpers\n(drawings.py)"]:::module
    Assets["SlimeSprites\n(slimeSprites/)"]:::asset
    PIL["PIL Library"]:::external

    %% Screen Manager Subgraph
    subgraph "Screen Manager"
        direction TB
        Start["Start"]
        Quiz["Quiz"]
        Game["Game"]
        Pause["Pause"]
        Help["Help"]
        WinLoss["Win/Loss"]
    end
    Main --> Start
    Start --> Quiz
    Quiz --> Game
    Game --> Pause
    Pause --> Help
    Help --> WinLoss

    %% Data Flows
    User -->|"onKeyPress → dispatchEvent()"| CMU
    CMU -->|"dispatchEvent()"| Main
    Main -->|"updateState()"| GameLogic
    GameLogic -->|"lookup(word)"| Dicts
    Main -->|"getText()/getColour()"| TextCol
    Main -->|"call drawFractalTree()"| DrawHelpers
    DrawHelpers -->|"draw() calls"| CMU
    CMU -->|"render()"| Screen

    %% Asset Loading
    Main -->|"loadSprites()"| PIL
    PIL -.->|"load images"| Assets

    %% Click Events
    click CMU "https://github.com/chieri-jn/zenmode/blob/main/cmu_112_graphics.py"
    click Main "https://github.com/chieri-jn/zenmode/blob/main/Main.py"
    click GameLogic "https://github.com/chieri-jn/zenmode/blob/main/classes.py"
    click Dicts "https://github.com/chieri-jn/zenmode/blob/main/dictionaries.py"
    click TextCol "https://github.com/chieri-jn/zenmode/blob/main/texts_colours.py"
    click DrawHelpers "https://github.com/chieri-jn/zenmode/blob/main/drawings.py"
    click Assets "https://github.com/chieri-jn/zenmode/tree/main/slimeSprites/"

    %% Styles
    classDef module fill:#add8e6,stroke:#333,stroke-width:1px
    classDef framework fill:#90ee90,stroke:#333,stroke-width:1px
    classDef asset fill:#ffffe0,stroke:#333,stroke-width:1px
    classDef external fill:none,stroke:#333,stroke-dasharray:5 5
    classDef externalEntity fill:#f0f0f0,stroke:#999,stroke-width:1px
```
