# z-dux/crused-autocatcher architecture

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

- Interactive diagram: https://gitdiagram.com/z-dux/crused-autocatcher
- Repository: https://github.com/z-dux/crused-autocatcher

## Overview

##### Main Components
- Bot Core (Entry Point): Represented by index.ts. This is the central application that ties together all modules and contains the core logic for interacting with Discord.
- Data Resources: The “data” directory holds several data “assets”:
- Images (data/images): JSON files for events, forms, and image setups.
- Languages (data/langs): Language-specific JSONs (e.g., english.json, french.json, etc.) for localization support.
- Names (data/names): Multiple JSON configurations for various Pokémon categories (event, legendary, mythical, etc.).
- Pokémon Data (data/pokemon.json): Likely contains in-depth details used by the bot to determine how to “autocatch” or process Pokémon events.
- Structural/Utility Modules: The “structs” folder defines types and helper functions (e.g., pokemon.ts, utils.ts) that model your domain objects and encapsulate reusable logic.
- Setup and Configuration:
- Configuration Files: “example.config.json” (which should be renamed to config.json) and tokens.txt for sensitive data.
- Setup Scripts: setup.bat and setup.ts that handle dependency setup and configuration initialization.
- Package Configuration & Build: package.json and tsconfig.json guide dependency management and TypeScript compilation, respectively.
- Executable Scripts: run.bat (and the alternative tsc + node commands) is used to launch the bot.

##### Relationships and Interactions
- The Bot Core (index.ts) initializes the bot by reading the configuration (config.json) and authentication tokens (tokens.txt).
- It loads data from the “data” directory to determine runtime behavior (such as which Pokémon events to monitor or how to respond based on language/localization).
- The utilities and type definitions in “structs” are leveraged by the core to parse and process the data consistently.
- There is an initialization/setup phase, handled via setup.bat/setup.ts, which prepares the environment and may preprocess configuration files.
- The project, although seemingly self-contained, likely interacts with the Discord API, using these modules to handle events (though explicit API wrappers are not visible in the file structure, the README indicates Discord integration).

##### Architectural Patterns and Design Principles
- Separation of Concerns: The clear split between data, configuration, core logic, and utilities suggests a modular design.
- Data-Driven Configuration: External JSON files are used to drive behavior (data/images, data/langs, data/names), making it easier to update without changing code.
- Setup/Bootstrap Phase: Having dedicated setup scripts underlines the emphasis on a smooth initialization/configuration process.
- Type Safety: Usage of TypeScript (supported by tsconfig.json and files in structs) emphasizes a type-safe and maintainable code base.
- Command-line Driven Execution: Batch files (setup.bat, run.bat) simplify invocation and deployment on Windows environments.

##### Final Reminders
- Be detailed: Each component should be explicit even if the project is relatively simple. Don't shy away from separating it into as many nodes as possible—this helps in understanding dependencies and interaction flows.
- Development/deployment flow: Include build steps (from tsconfig.json and package.json) and execution scripts, which could be side nodes to give a complete picture of the operational environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Setup & Configuration
    subgraph "Setup & Configuration"
        config["example.config.json"]:::config
        setupBat["setup.bat"]:::config
        setupTS["setup.ts"]:::config
    end

    %% Data Resources
    subgraph "Data Resources"
        images["data/images"]:::data
        langs["data/langs"]:::data
        names["data/names"]:::data
        pokemon["data/pokemon.json"]:::data
    end

    %% Utility Modules
    subgraph "Utility Modules"
        structs["structs"]:::util
    end

    %% Build & Execution
    subgraph "Build & Execution"
        package["package.json"]:::build
        tsconfig["tsconfig.json"]:::build
        run["run.bat"]:::build
    end

    %% Bot Core and External Integration
    core["index.ts"]:::core
    external["Discord API"]:::external

    %% Relationships
    config -->|"init"| core
    setupBat -->|"configure"| config
    setupTS -->|"configure"| config

    images -->|"loadData"| core
    langs -->|"loadData"| core
    names -->|"loadData"| core
    pokemon -->|"loadData"| core

    structs -->|"utilities"| core

    package -->|"build"| run
    tsconfig -->|"build"| run
    run -->|"start"| core

    core -->|"handleEvents"| external

    %% Click Events
    click core "https://github.com/z-dux/crused-autocatcher/blob/main/index.ts"
    click images "https://github.com/z-dux/crused-autocatcher/tree/main/data/images"
    click langs "https://github.com/z-dux/crused-autocatcher/tree/main/data/langs"
    click names "https://github.com/z-dux/crused-autocatcher/tree/main/data/names"
    click pokemon "https://github.com/z-dux/crused-autocatcher/blob/main/data/pokemon.json"
    click structs "https://github.com/z-dux/crused-autocatcher/tree/main/structs"
    click config "https://github.com/z-dux/crused-autocatcher/blob/main/example.config.json"
    click setupBat "https://github.com/z-dux/crused-autocatcher/blob/main/setup.bat"
    click setupTS "https://github.com/z-dux/crused-autocatcher/blob/main/setup.ts"
    click package "https://github.com/z-dux/crused-autocatcher/blob/main/package.json"
    click tsconfig "https://github.com/z-dux/crused-autocatcher/blob/main/tsconfig.json"
    click run "https://github.com/z-dux/crused-autocatcher/blob/main/run.bat"

    %% Styles
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef config fill:#f9c,stroke:#333,stroke-width:2px;
    classDef data fill:#cfc,stroke:#333,stroke-width:2px;
    classDef util fill:#fcf,stroke:#333,stroke-width:2px;
    classDef build fill:#cff,stroke:#333,stroke-width:2px;
    classDef external fill:#ddd,stroke:#333,stroke-width:2px;
```
