# charlespikachu/games architecture

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

- Interactive diagram: https://gitdiagram.com/charlespikachu/games
- Repository: https://github.com/charlespikachu/games

## Overview

##### Project type and purpose
- This is a pure-Python, command-line games framework/library (“cpgames”) that bundles ~29 standalone mini-games as plugins.
- It provides a single public API (CPGames) to enumerate, select, and launch any of the supported games.

##### File structure
- Top‐level:
- setup.py, requirements.txt → packaging & dependencies
- cpgames/ → main Python package
- docs/ → Sphinx documentation
- cpgames/ contains two primary subpackages:
- core/games/… → each game is its own subpackage (e.g., flappybird, tetris, tankwar…), with its own modules (interfaces, sprites, utilities) and resources (images, audio, levels).
- core/utils/… → shared helpers (initialize, I/O, misc).
- cpgames/cpgames.py → entry point (CPGames class) that discovers and dispatches to game plugins.

##### README for additional insights
- The Quick Start snippet shows a simple CLI usage:
import cpgames
client = CPGames()
game = random.choice(client.getallsupported())
client.execute(game)
- No web or network external services except optional online mode in gobang.

##### Main components & their interactions
a. **CLI / Entry Point** (cpgames-console script or cpgames/cpgames.py)
- Parses user request (e.g., random or explicit game name).
- Delegates to CPGames API.
b. **CPGames API / Game Manager**
- Scans core/games package for installed game subpackages.
- Builds a registry of available Game classes.
- Provides `getallsupported()` and `execute(game_id)` methods.
c. **Game Plugin** (one per mini-game)
- Implements a unified interface (e.g., a .py file exposing Game class with `run()` or similar).
- Contains submodules:
- modules/ → components (sprites, interfaces, utils, levels map parsers, AI, online client/server for gobang).
- resources/ → static assets (audio, images, fonts, levels data).
- May depend on Pygame or Python stdlib.
d. **Shared Utilities** (cpgames/core/utils)
- Helpers for initialization, resource loading (I/O), common math or CLI utilities.
e. **External Dependencies**
- Pygame (for rendering, audio)
- Python standard libraries

##### Architectural patterns/design principles
- **Plugin Architecture** – each game is a self-contained plugin that follows the same interface, enabling dynamic discovery.
- **Package modularity** – separation between core logic (CPGames API), game implementations, and utilities.
- **Resource isolation** – each plugin carries its own assets.
- **Single entry-point CLI** – simple runner pattern.
- **Extensibility** – to add a new game, drop a subpackage into core/games adhering to the interface.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and Entry
    User["User"]:::external
    CLI["CLI / Entry Point\n(cpgames/cpgames.py)"]:::core
    click CLI "https://github.com/charlespikachu/games/blob/master/cpgames/cpgames.py"

    %% Manager
    Manager["CPGames Manager\n(public API & dynamic discovery)"]:::core
    click Manager "https://github.com/charlespikachu/games/blob/master/cpgames/cpgames.py"

    %% Shared Utilities
    subgraph "Shared Utilities" 
        direction TB
        Init["initialize.py"]:::core
        IO["io.py"]:::core
        Misc["misc.py"]:::core
        click Init "https://github.com/charlespikachu/games/blob/master/cpgames/core/utils/initialize.py"
        click IO "https://github.com/charlespikachu/games/blob/master/cpgames/core/utils/io.py"
        click Misc "https://github.com/charlespikachu/games/blob/master/cpgames/core/utils/misc.py"
    end

    %% Game Plugins
    subgraph "Game Plugins\n(cpgames/core/games/)" 
        direction TB
        click GamePlugins "https://github.com/charlespikachu/games/tree/master/cpgames/core/games/"
        subgraph "Flappy Bird Plugin" 
            direction TB
            FBCode["flappybird.py"]:::plugin
            click FBCode "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/flappybird/flappybird.py"
            subgraph "Modules" 
                direction TB
                FBIntStart["startinterface.py"]:::plugin
                FBIntEnd["endinterface.py"]:::plugin
                FBSpBird["bird.py"]:::plugin
                FBSpPipe["pipe.py"]:::plugin
                click FBIntStart "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/flappybird/modules/interfaces/startinterface.py"
                click FBIntEnd "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/flappybird/modules/interfaces/endinterface.py"
                click FBSpBird "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/flappybird/modules/sprites/bird.py"
                click FBSpPipe "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/flappybird/modules/sprites/pipe.py"
            end
            ResourcesFB["Resources\n(images, audios)"]:::resources
            click ResourcesFB "https://github.com/charlespikachu/games/tree/master/cpgames/core/games/flappybird/resources/"
        end
        subgraph "Gobang Plugin" 
            direction TB
            GBCode["gobang.py"]:::plugin
            click GBCode "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/gobang/gobang.py"
            subgraph "Modules" 
                direction TB
                AIGB["aigobang.py"]:::plugin
                AIPlay["playwithai.py"]:::plugin
                OLClient["client.py"]:::plugin
                OLPlay["playonline.py"]:::plugin
                OLServer["server.py"]:::plugin
                MGBMisc["utils.py"]:::plugin
                click AIGB "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/gobang/modules/ai/aigobang.py"
                click AIPlay "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/gobang/modules/ai/playwithai.py"
                click OLClient "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/gobang/modules/online/client.py"
                click OLPlay "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/gobang/modules/online/playonline.py"
                click OLServer "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/gobang/modules/online/server.py"
                click MGBMisc "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/gobang/modules/misc/utils.py"
            end
            ResourcesGB["Resources\n(images, audios)"]:::resources
            click ResourcesGB "https://github.com/charlespikachu/games/tree/master/cpgames/core/games/gobang/resources/"
        end
        BaseInterface["Base Game Interface\n(basegame.py)"]:::core
        click BaseInterface "https://github.com/charlespikachu/games/blob/master/cpgames/core/games/base/basegame.py"
        Others["+28 Other Plugins"]:::plugin
    end

    %% External Dependencies
    External["Pygame\n(Rendering & Audio)"]:::external

    %% Packaging & Docs & GitHub
    subgraph "Project Metadata"
        direction TB
        Setup["setup.py"]:::packaging
        Req["requirements.txt"]:::packaging
        click Setup "https://github.com/charlespikachu/games/blob/master/setup.py"
        click Req "https://github.com/charlespikachu/games/blob/master/requirements.txt"
        subgraph "Documentation" 
            Quick["Quickstart.md"]:::docs
            Conf["conf.py"]:::docs
            click Quick "https://github.com/charlespikachu/games/blob/master/docs/Quickstart.md"
            click Conf "https://github.com/charlespikachu/games/blob/master/docs/conf.py"
        end
        subgraph "GitHub Metadata"
            Issue["bug-report.md"]:::docs
            Fund["FUNDING.yml"]:::docs
            click Issue "https://github.com/charlespikachu/games/blob/master/.github/ISSUE_TEMPLATE/bug-report.md"
            click Fund "https://github.com/charlespikachu/games/blob/master/.github/FUNDING.yml"
        end
    end

    %% Connections
    User -->|"runs script"| CLI
    CLI -->|"calls getallsupported()/execute()"| Manager
    Manager -->|"scans directory"| GamePlugins
    Manager -->|"uses"| Init
    Manager -->|"uses"| IO
    Manager -->|"uses"| Misc
    GamePlugins -->|"loads plugin"| FBCode
    GamePlugins -->|"loads plugin"| GBCode
    FBCode -->|"uses resources"| ResourcesFB
    FBCode -->|"calls utils"| Init
    FBCode -->|"calls utils"| IO
    FBCode -->|"renders via"| External
    GBCode -->|"uses resources"| ResourcesGB
    GBCode -->|"calls utils"| Init
    GBCode -->|"calls utils"| IO
    GBCode -->|"renders via"| External

    %% Styles
    classDef core fill:#AED6F1,stroke:#21618C,color:#1B2631;
    classDef plugin fill:#ABEBC6,stroke:#196F3D,color:#1B2631;
    classDef external fill:#FAD7A0,stroke:#B9770E,color:#1B2631;
    classDef resources fill:#D5D8DC,stroke:#566573,color:#1B2631;
    classDef packaging fill:#F5B7B1,stroke:#C0392B,color:#1B2631;
    classDef docs fill:#D7BDE2,stroke:#7D3C98,color:#1B2631;
```
