# wesleyel/war3parser architecture

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

- Interactive diagram: https://gitdiagram.com/wesleyel/war3parser
- Repository: https://github.com/wesleyel/war3parser

## Overview

##### Main Components
- Core Library: Represented by the crates/lib folder. This is the heart of the project containing various parser modules (e.g., parser/w3i, parser/w3x, parser/wts) and utility functions (e.g., binary reading, error handling). It also has functionalities to extract metadata and operate on map files.
- Command-Line Interface (CLI): In the crates/cli folder, this component consumes the core library to offer commands for dumping metadata, extracting files, and converting images.
- WASM Module: Located in the crates/wasm folder, this part packages the library’s functionalities into a WebAssembly binary to be used from JavaScript, providing an interface that wraps the core functionality.
- External Data/Resources: Represent the test_data folder that contains sample .w3x map files used for testing and as input examples.
- Build/CI Infrastructure: Indicate the GitHub workflows under .github/workflows and the Justfile for build tasks, which show the support for continuous integration and deployment.

##### Relationships and Interactions
- The Core Library is the central component. Both the CLI and WASM components depend on it.
- Interactions where data flows from input map files (such as those from test_data) into the Core Library, which then processes and returns parsed data, and then those results flow to the CLI or are exposed via the WASM interface.

##### Architectural Patterns and Principles
- Modularity: The separation into different crates (CLI, lib, wasm) reflects a modular design that isolates core functionality, user-facing CLI interactivity, and web integration.
- Reusability: The core library is built to be reused in multiple interfaces (CLI and WASM), emphasizing a separation of concerns.
- Layered Architecture: The system can be visualized as layers – the lower layer being the core parsing logic, and the upper layers being different interfaces/wrappers.

##### Relevant Technologies
- Rust: The primary language and toolchain (Cargo) used for development.
- Cargo and Justfile: For building, dependency management, and automation.
- WASM: For web integration, highlighting that the library is compiled to WebAssembly.
- GitHub Actions: For CI/CD integration depicted via the workflows in .github/workflows.

- The central parsing engine (the war3parser Core Library), broken down into submodules for various file formats.
- The two main interfaces that consume the core library: the CLI tool (for direct command-line use) and the WASM interface (for integration within web environments).
- Interaction dynamics with external map data and integration with build/CI pipelines.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "War3Parser Core Library"
        coreLib["\"War3Parser Core Library\""]:::core
        subgraph "Parser Modules"
            parserGeneral["\"General Parser\""]:::core
            parserW3I["\"W3I Parser\""]:::core
            parserW3X["\"W3X Parser\""]:::core
            parserWTS["\"WTS Parser\""]:::core
        end
        subgraph "Utility Functions"
            binaryReader["\"Binary Reader\""]:::core
            errorHandling["\"Error Handling\""]:::core
        end
    end

    cliInterface["\"CLI Interface\""]:::cli
    wasmInterface["\"WASM Interface\""]:::wasm
    externalData["\"External Data/Map Files\""]:::data

    subgraph "Build/CI Infrastructure"
        githubActions["\"GitHub Workflows\""]:::ci
        justfileNode["\"Justfile\""]:::ci
    end

    externalData -->|"supplies"| coreLib
    cliInterface -->|"uses"| coreLib
    wasmInterface -->|"uses"| coreLib
    githubActions -->|"triggers_build"| coreLib
    justfileNode -->|"executes_tasks"| coreLib

    click coreLib "https://github.com/wesleyel/war3parser/tree/main/crates/lib"
    click parserW3I "https://github.com/wesleyel/war3parser/tree/main/crates/lib/src/parser/w3i"
    click parserW3X "https://github.com/wesleyel/war3parser/tree/main/crates/lib/src/parser/w3x"
    click parserWTS "https://github.com/wesleyel/war3parser/tree/main/crates/lib/src/parser/wts"
    click binaryReader "https://github.com/wesleyel/war3parser/blob/main/crates/lib/src/parser/binary_reader.rs"
    click errorHandling "https://github.com/wesleyel/war3parser/blob/main/crates/lib/src/parser/error.rs"
    click cliInterface "https://github.com/wesleyel/war3parser/tree/main/crates/cli"
    click wasmInterface "https://github.com/wesleyel/war3parser/tree/main/crates/wasm"
    click externalData "https://github.com/wesleyel/war3parser/tree/main/test_data"
    click githubActions "https://github.com/wesleyel/war3parser/tree/main/.github/workflows"
    click justfileNode "https://github.com/wesleyel/war3parser/tree/main/Justfile"

    classDef core fill:#f9e79f,stroke:#6e2c00,stroke-width:2px;
    classDef cli fill:#aed6f1,stroke:#1b4f72,stroke-width:2px;
    classDef wasm fill:#abebc6,stroke:#0b5345,stroke-width:2px;
    classDef data fill:#f5b7b1,stroke:#641e16,stroke-width:2px;
    classDef ci fill:#fadbd8,stroke:#78281f,stroke-width:2px;
```
