# sayzx/tamagotchi-py-poo architecture

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

- Interactive diagram: https://gitdiagram.com/sayzx/tamagotchi-py-poo
- Repository: https://github.com/sayzx/tamagotchi-py-poo

## Overview

##### Project Type and Purpose
- This is a game application (a virtual pet simulator, à la Tamagotchi) where users can create, care for, and interact with creatures.
- Its purpose is to simulate creature behaviors including feeding, playing, sleeping, and reacting to random events.
- The game uses pygame (as indicated in the README) for graphical and possibly audio outputs.

##### Main Components
- Entry Point: main.py
- Game Core/Logic: game.py, which likely manages the overall game loop and interactions.
- Creature Module: creature.py (defining creature attributes, behavior, evolution, etc.)
- Actions & Events:
- actions.py: Responsible for creature actions (feeding, playing, etc.)
- events.py: Handling random events (disease, party, encounters, etc.)
- Data Management & Persistence:
- storage.py: Likely handles saving/loading the game state (with data/savegame.json serving as the persistent storage).
- UI and Multimedia:
- ui/display.py: Manages on-screen rendering.
- ui/art: Contains ASCII or image art for various creatures.
- ui/sound: Contains audio files linked to creature sounds or game effects.
- Dependencies and Auxiliary:
- requirements.txt: Lists dependencies (e.g., pygame).
- README.MD: Provides overall game description and instructions.

##### Relationships and Interactions
- Main Flow: main.py initializes the game, sets up the game loop (possibly through game.py), and invokes UI rendering and event-handling.
- Game Core (game.py) coordinates between:
- Creature logic (creature.py)
- Action handling (actions.py) to update creature state.
- Event triggering (events.py) to inject unpredictability in the game.
- Data Persistence: storage.py reads/writes the state to data/savegame.json.
- UI Interaction: ui/display.py, together with assets found in ui/art and ui/sound, is invoked by the game loop to visually render the game state and play sounds.

##### Architectural Patterns or Principles
- Modular Structure: Each file (or module) encapsulates a specific aspect of the game (logic, UI, persistence, events).
- Separation of Concerns: Distinct modules for game logic, creature behavior, UI, events, and data management.
- Integration via a central game loop (likely in game.py) that orchestrates interactions between these modules.
- Use of external libraries (pygame) for UI and sound handling.

- Branch downward to game.py representing the game loop that orchestrates the entire simulation.
- From game.py, branch out to:
- Creature Management (creature.py)
- Actions (actions.py)
- Events (events.py)
- UI (ui/display.py) – attach assets such as those in ui/art and ui/sound.

##### Final Reminder
- The main objective is to capture all essential architectural elements: game init, core modules, UI, storage, and data flow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point
    A["Main Module (main.py)"]:::core
    
    %% Core Modules
    subgraph "Core Modules"
        B["Game Engine/Loop (game.py)"]:::core
        C["Creature Management (creature.py)"]:::core
        D["Actions Handler (actions.py)"]:::core
        E["Events Manager (events.py)"]:::core
    end
    
    %% Data Management
    subgraph "Data Management"
        F["Storage (storage.py)"]:::data
        G["Savegame Data (data/savegame.json)"]:::data
    end
    
    %% UI & Multimedia
    subgraph "UI & Multimedia"
        H["UI Manager (ui/display.py)"]:::ui
        I["Art Assets (ui/art)"]:::ui
        J["Sound Assets (ui/sound)"]:::ui
    end

    %% Connections
    A -->|"initializes"| B
    B -->|"manages"| C
    B -->|"updates"| D
    B -->|"triggers"| E
    B -->|"saves/loads"| F
    F -->|"reads/writes"| G
    B -->|"renders"| H
    H -->|"uses"| I
    H -->|"uses"| J

    %% Click Events
    click A "https://github.com/sayzx/tamagotchi-py-poo/blob/master/main.py"
    click B "https://github.com/sayzx/tamagotchi-py-poo/blob/master/game.py"
    click C "https://github.com/sayzx/tamagotchi-py-poo/blob/master/creature.py"
    click D "https://github.com/sayzx/tamagotchi-py-poo/blob/master/actions.py"
    click E "https://github.com/sayzx/tamagotchi-py-poo/blob/master/events.py"
    click F "https://github.com/sayzx/tamagotchi-py-poo/blob/master/storage.py"
    click G "https://github.com/sayzx/tamagotchi-py-poo/blob/master/data/savegame.json"
    click H "https://github.com/sayzx/tamagotchi-py-poo/blob/master/ui/display.py"
    click I "https://github.com/sayzx/tamagotchi-py-poo/tree/master/ui/art"
    click J "https://github.com/sayzx/tamagotchi-py-poo/tree/master/ui/sound"

    %% Styles
    classDef core fill:#f9c,stroke:#333,stroke-width:2px;
    classDef data fill:#ccf,stroke:#333,stroke-width:2px;
    classDef ui fill:#cfc,stroke:#333,stroke-width:2px;
```
