# anssi-fr/bmc-tools architecture

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

- Interactive diagram: https://gitdiagram.com/anssi-fr/bmc-tools
- Repository: https://github.com/anssi-fr/bmc-tools

## Overview

##### Main Components
- Command Line Interface (CLI) & Argument Parsing – This is where the tool receives user input (e.g., -s, -d, -c, -v, -o, -b, -w, -k options) from the terminal.
- Input Data Handler – A module or component that locates and reads the provided BMCache files (e.g. “bcache*.bmc” and “cache????.bin”) from the specified source directory.
- Bitmap Extraction & Parsing Engine – The core logic that parses the BMCache files, handles tile decompression, manages old bitmap data extraction, and produces output bitmaps.
- Collage Generator (Optional) – If the bitmap flag (-b) is used, an additional processing step aggregates individual tiles into a single collage.
- Output Handler – This component writes the extracted bitmaps (and optionally the collage image) to the destination directory. This might also handle the KAPE output option (splitting files into separate folders) if that option is specified.
- Logging/Verbose Output – The system may display additional information based on the verbose option (-v), useful for tracing execution flow and processing details.

##### Relationships and Interactions
- The parsed parameters determine the subsequent execution flow:
- The Input Data Handler locates and reads the correct BMCache file(s) from the source.
- The Bitmap Extraction & Parsing Engine processes these files. This engine can be seen as the central component where the parsing and any tile decompression occur.
- If the collage output option is selected, the Collage Generator combines individual images based on the specified width parameter.
- The Output Handler then saves the processed images to the destination directory, ensuring any directory checks (as mentioned in the changelog) are performed beforehand.
- Throughout these steps, any logging or verbose reporting is managed to update the user.

##### Technical and Architectural Patterns
- Lightweight, single-script design – The entire logic is contained within a single Python file, meaning that the modular separation is conceptual rather than physically distributed across multiple files.
- Emphasis on extensibility – Even though it’s a small tool, clearly separating the functions (argument parsing, input reading, processing, output writing) will help future developers understand potential extension points.

##### Relevant Technologies/Frameworks
- Python – Indicate that the system is implemented in Python, compatible with both Python2 and Python3.
- Standard Libraries for file I/O, argument parsing, and possibly image processing (if there are dependencies for bitmap manipulation).

## Diagram (Mermaid)

```mermaid
graph TD
    A("CLI/Argument Parser"):::blue
    B("Input File Reader"):::blue
    C("Bitmap Extraction & Parsing Engine"):::green
    CollageDecision{"Collage Flag Active?"}:::green
    E("Optional: Collage Generator"):::orange
    F("Output Handler"):::blue
    G("Logging/Verbose Output"):::purple

    A --> B
    B --> C
    C --> CollageDecision
    CollageDecision -- "yes" --> E
    CollageDecision -- "no" --> F
    E --> F

    A -. "logs" .-> G
    B -. "logs" .-> G
    C -. "logs" .-> G
    F -. "logs" .-> G

    click A "https://github.com/anssi-fr/bmc-tools/blob/master/bmc-tools.py"
    click B "https://github.com/anssi-fr/bmc-tools/blob/master/bmc-tools.py"
    click C "https://github.com/anssi-fr/bmc-tools/blob/master/bmc-tools.py"
    click E "https://github.com/anssi-fr/bmc-tools/blob/master/bmc-tools.py"
    click F "https://github.com/anssi-fr/bmc-tools/blob/master/bmc-tools.py"
    click G "https://github.com/anssi-fr/bmc-tools/blob/master/bmc-tools.py"

    classDef blue fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef green fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef orange fill:#FFD580,stroke:#000,stroke-width:1px;
    classDef purple fill:#DDA0DD,stroke:#000,stroke-width:1px;
```
