# fragglet/lhasa architecture

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

- Interactive diagram: https://gitdiagram.com/fragglet/lhasa
- Repository: https://github.com/fragglet/lhasa

## Overview

##### Main Components
The system should be divided into these key components:

a) Library Core (lib/)
- File Header Processing
- Decompression Algorithms
- Stream Handling
- Platform-specific Code

b) Command Line Interface (src/)
- User Input Processing
- Archive Operations
- Output Formatting

c) Testing Framework (test/)
- Test Suite
- Archive Samples
- Validation Tools

##### Component Relationships

**[Command Line Interface]**
- ↓
- [Library Core]
- ↓
**[Platform Abstraction Layer]**
- ↓
**[Operating System / File System]**

##### Detailed Component Breakdown

a) Library Core Components:
**[File Header Parser] → [Decompression Engine]**
- ↓                      ↓
**[Stream Handler] ←→ [Archive Reader]**
- ↓
**[Platform-specific I/O]**

- Blue: Public API components
- Green: Core processing components
- Yellow: Platform-specific components
- Gray: Support/utility components

##### Key Interfaces to Highlight

**Public API (lib/public/):**
- lha_decoder.h
- lha_file_header.h
- lha_input_stream.h
- lha_reader.h
- lhasa.h

##### Data Flow
**[Input Archive] → [Header Parser] → [Decompression] → [Output Files]**
- ↓
- [Metadata/CRC]

##### Implementation Details

- Multiple compression algorithm support (LH0-LH7, etc.)
- Cross-platform compatibility layer
- Error handling paths
- CRC verification flow

**→ Data flow**
**↔ Bidirectional interaction**
**□ Core component**
**○ Support component**
**◇ External interface**

##### Testing infrastructure integration

Remember to include version information and supported archive format types (LHA, LArc, PMarc) in supplementary documentation.

This design reflects the project's focus on archive reading/decompression functionality while leaving room for future compression support.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CLI["Command Line Interface"]
        direction TB
        UserInput["User Input Processing"]:::cli
        ArchiveOps["Archive Operations"]:::cli
        OutputFormat["Output Formatting"]:::cli
        UserInput --> ArchiveOps
        ArchiveOps --> OutputFormat
    end

    subgraph Core["Library Core"]
        direction TB
        FileHeader["File Header Processing"]:::core
        DecompEngine["Decompression Engine"]:::core
        StreamHandler["Stream Handler"]:::core
        ArchiveReader["Archive Reader"]:::core
        CRCVerif["CRC Verification"]:::core
        
        FileHeader --> DecompEngine
        StreamHandler <--> ArchiveReader
        DecompEngine --> StreamHandler
        ArchiveReader --> CRCVerif
    end

    subgraph Platform["Platform Abstraction Layer"]
        direction TB
        PlatformIO["Platform-specific I/O"]:::platform
        UnixArch["Unix Architecture"]:::platform
        WinArch["Windows Architecture"]:::platform
        
        PlatformIO --> UnixArch
        PlatformIO --> WinArch
    end

    subgraph API["Public API"]
        direction TB
        Decoder["lha_decoder"]:::api
        FileHeaderAPI["lha_file_header"]:::api
        InputStream["lha_input_stream"]:::api
        Reader["lha_reader"]:::api
        LhasaAPI["lhasa"]:::api
    end

    subgraph Test["Testing Framework"]
        direction TB
        TestSuite["Test Suite"]:::test
        ArchiveSamples["Archive Samples"]:::test
        ValidationTools["Validation Tools"]:::test
    end

    CLI --> API
    API --> Core
    Core --> Platform
    Test --> API

    classDef cli fill:#f9f,stroke:#333,stroke-width:2px
    classDef core fill:#9cf,stroke:#333,stroke-width:2px
    classDef platform fill:#ff9,stroke:#333,stroke-width:2px
    classDef api fill:#9f9,stroke:#333,stroke-width:2px
    classDef test fill:#ddd,stroke:#333,stroke-width:2px

    click FileHeader "https://github.com/fragglet/lhasa/blob/master/lib/lha_file_header.c"
    click DecompEngine "https://github.com/fragglet/lhasa/blob/master/lib/lh1_decoder.c"
    click StreamHandler "https://github.com/fragglet/lhasa/blob/master/lib/lha_input_stream.c"
    click PlatformIO "https://github.com/fragglet/lhasa/blob/master/lib/lha_arch.h"
    click UnixArch "https://github.com/fragglet/lhasa/blob/master/lib/lha_arch_unix.c"
    click WinArch "https://github.com/fragglet/lhasa/blob/master/lib/lha_arch_win32.c"
    click Decoder "https://github.com/fragglet/lhasa/blob/master/lib/public/lha_decoder.h"
    click FileHeaderAPI "https://github.com/fragglet/lhasa/blob/master/lib/public/lha_file_header.h"
    click InputStream "https://github.com/fragglet/lhasa/blob/master/lib/public/lha_input_stream.h"
    click Reader "https://github.com/fragglet/lhasa/blob/master/lib/public/lha_reader.h"
    click LhasaAPI "https://github.com/fragglet/lhasa/blob/master/lib/public/lhasa.h"
    click UserInput "https://github.com/fragglet/lhasa/blob/master/src/main.c"
    click ArchiveOps "https://github.com/fragglet/lhasa/blob/master/src/extract.c"
    click TestSuite "https://github.com/fragglet/lhasa/blob/master/test/test-decoder.c"
    click ArchiveSamples "https://github.com/fragglet/lhasa/tree/master/test/archives"
    click CRCVerif "https://github.com/fragglet/lhasa/blob/master/lib/crc16.c"
```
