# balatro-paperback/paperback architecture

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

- Interactive diagram: https://gitdiagram.com/balatro-paperback/paperback
- Repository: https://github.com/balatro-paperback/paperback

## Overview

##### Main Components
- Mod Loader & Main Entry: At the top level, “paperback.lua” serves as the entry point for the mod. It is responsible for bootstrapping the mod and integrating it with the base game.
- Configuration: “config.lua” is the configuration file that defines global settings and mod initialization parameters.
- Assets: The “assets” folder holds supporting files (images, shaders, sounds). This forms the asset management component that the rendering and audio layers will use.
- Localization: The “localization” folder contains language files (en-us, fr, pt_BR, ru) for translating mod text and dialogues.
- Metadata & Contribution: Files like “metadata.json”, CODE_OF_CONDUCT.md, CONTRIBUTING.md, etc., mark the project’s governance and versioning but are peripheral to the runtime design. They provide context on collaboration rather than the architecture itself.

##### Relationships and Component Interactions
- The Mod Loader (“paperback.lua”) first initiates by reading the “config.lua” file to set up global parameters.
- It then loads the various content modules from the “content” folder. Each of these modules (cards, jokers, enhancements) registers its definitions into the mod’s runtime.
- The Assets component supplies visuals and sounds to the mod. When a particular piece of content (say, a joker card or booster) is instantiated, it will reference assets defined under the “assets” folder.
- Localization files are loaded by the mod early in the initialization phase so that all textual content is translated for the appropriate locale.
- Utilities and hooks provide a mechanism to integrate with the base game’s event loop, override UI elements, or respond to in-game events. They connect the mod’s custom logic with the streaming of real-time events.

##### Architectural Patterns and Design Principles
- Modular Design: Each distinct type of content (jokers, decks, cards, etc.) is isolated in its own folder, encouraging separation of concerns.
- Data-Driven Design: Much in-game behavior appears to be driven by Lua scripts and data definitions (in the “content” subfolders). This allows for easy extension and tweaks without changing core logic.
- Plug-and-Play Architecture: The utilities and hooks are likely designed to integrate with existing game loops, allowing you to insert or override functionality provided by the base game.
- Clear Dependency Separation: Assets, localization, and utilities are clearly separated, which means each component can be updated or maintained independently.

- A central “Mod Loader” node representing “paperback.lua”.
- A “Configuration” node (config.lua) feeding into the Mod Loader.
- A complex “Content Management” section depicting individual modules (joker, booster, deck, minor_arcana, paperclip, etc.).
- “Assets” node that links to content modules.
- “Localization” node showing language support files.
- “Utilities & Hooks” node linking back to the mod loader and content modules for custom game interactions.
- Optional side notes indicating external documentation and community support (GitHub contributions, Discord, Wiki).

This detailed approach will give you the clarity required to both develop and communicate the mod's architecture effectively. Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Runtime Initialization"
        modLoader("Mod Loader (paperback.lua)"):::mod
        config("Configuration (config.lua)"):::config
        modLoader -->|"reads"| config
    end

    subgraph "Content Management"
        Joker("Joker Module"):::content
        Booster("Booster Module"):::content
        Deck("Deck Module"):::content
        MinorArcana("Minor Arcana Module"):::content
        Paperclip("Paperclip Module"):::content
        Planet("Planet Module"):::content
        Pokerhand("Pokerhand Module"):::content
        Suit("Suit Module"):::content
        Tag("Tag Module"):::content
        Voucher("Voucher Module"):::content
    end

    subgraph "Auxiliary Services"
        assets("Assets Management"):::assets
        localization("Localization"):::localization
        utilities("Utilities & Hooks"):::utilities
        theme("Theme/Color Configuration"):::theme
    end

    %% Mod Loader loads Content Modules
    modLoader -->|"loads"| Joker
    modLoader -->|"loads"| Booster
    modLoader -->|"loads"| Deck
    modLoader -->|"loads"| MinorArcana
    modLoader -->|"loads"| Paperclip
    modLoader -->|"loads"| Planet
    modLoader -->|"loads"| Pokerhand
    modLoader -->|"loads"| Suit
    modLoader -->|"loads"| Tag
    modLoader -->|"loads"| Voucher

    %% Assets supplies content assets
    assets -->|"supplies"| Joker
    assets -->|"supplies"| Booster
    assets -->|"supplies"| Deck
    assets -->|"supplies"| MinorArcana
    assets -->|"supplies"| Paperclip
    assets -->|"supplies"| Planet
    assets -->|"supplies"| Pokerhand
    assets -->|"supplies"| Suit
    assets -->|"supplies"| Tag
    assets -->|"supplies"| Voucher

    %% Localization provides language support
    localization -->|"provides"| Joker
    localization -->|"provides"| Booster
    localization -->|"provides"| Deck
    localization -->|"provides"| MinorArcana
    localization -->|"provides"| Paperclip
    localization -->|"provides"| Planet
    localization -->|"provides"| Pokerhand
    localization -->|"provides"| Suit
    localization -->|"provides"| Tag
    localization -->|"provides"| Voucher

    %% Utilities enhance content functionality and mod integration
    utilities -->|"enhances"| Joker
    utilities -->|"enhances"| Booster
    utilities -->|"enhances"| Deck
    utilities -->|"enhances"| MinorArcana
    utilities -->|"enhances"| Paperclip
    utilities -->|"enhances"| Planet
    utilities -->|"enhances"| Pokerhand
    utilities -->|"enhances"| Suit
    utilities -->|"enhances"| Tag
    utilities -->|"enhances"| Voucher
    utilities -->|"integrates with"| modLoader

    %% Theme configuration customizes Utilities & Hooks
    theme -->|"configures"| utilities

    %% Click Events
    click modLoader "https://github.com/balatro-paperback/paperback/blob/main//paperback.lua"
    click config "https://github.com/balatro-paperback/paperback/blob/main//config.lua"
    click Joker "https://github.com/balatro-paperback/paperback/tree/main//content/joker"
    click Booster "https://github.com/balatro-paperback/paperback/tree/main//content/booster"
    click Deck "https://github.com/balatro-paperback/paperback/tree/main//content/deck"
    click MinorArcana "https://github.com/balatro-paperback/paperback/tree/main//content/minor_arcana"
    click Paperclip "https://github.com/balatro-paperback/paperback/tree/main//content/paperclip"
    click Planet "https://github.com/balatro-paperback/paperback/tree/main//content/planet"
    click Pokerhand "https://github.com/balatro-paperback/paperback/tree/main//content/pokerhand"
    click Suit "https://github.com/balatro-paperback/paperback/tree/main//content/suit"
    click Tag "https://github.com/balatro-paperback/paperback/tree/main//content/tag"
    click Voucher "https://github.com/balatro-paperback/paperback/tree/main//content/voucher"
    click assets "https://github.com/balatro-paperback/paperback/tree/main//assets"
    click localization "https://github.com/balatro-paperback/paperback/tree/main//localization"
    click utilities "https://github.com/balatro-paperback/paperback/tree/main//utilities"
    click theme "https://github.com/balatro-paperback/paperback/tree/main//lovely"

    %% Styles
    classDef mod fill:#ffdddd,stroke:#ff0000,stroke-width:2px;
    classDef config fill:#ddffdd,stroke:#00aa00,stroke-width:2px;
    classDef content fill:#ddeeff,stroke:#0000ff,stroke-width:2px;
    classDef assets fill:#ffddff,stroke:#ff00ff,stroke-width:2px;
    classDef localization fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
    classDef utilities fill:#ddffff,stroke:#00cccc,stroke-width:2px;
    classDef theme fill:#ffeedd,stroke:#cc6600,stroke-width:2px;
```
