# mohamedmajdi/rust-dem-viewer architecture

> Architecture diagram of the GitHub repository mohamedmajdi/rust-dem-viewer, 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/mohamedmajdi/rust-dem-viewer
- Repository: https://github.com/mohamedmajdi/rust-dem-viewer

## Overview

##### Main Components
- CLI Parser Component – Responsible for reading command-line arguments. This uses the clap crate and the Args struct.
- File I/O & DEM Parsing Component – Reads and parses the provided `.asc` DEM file into a suitable data structure.
- Visualization Engine – Processes the DEM data and applies the chosen visualization mode. This can include:
▪ Grayscale rendering logic.
▪ Hillshade simulation (applying simulated sunlight and shading).
- Output Renderer – Outputs the visualization as terminal-based images or textual representation.

##### Relationships and Interactions
- The system starts at the main entry point (main.rs) where the CLI Parser is invoked.
- Once command-line parameters (file path and mode) are captured, the File I/O & DEM Parsing Component is called to load the file.
- The parsed DEM data is then passed to the Visualization Engine which, based on the selected mode, processes and enhances the DEM data.
- Finally, the Output Renderer takes the processed data and displays the result in the terminal.

##### Architectural Patterns and Design Principles
- Simple, modular separation between input handling, data processing, and output rendering.
- The use of the clap crate for robust CLI parsing shows adherence to a clean command-line interface pattern.
- The program follows a “pipeline” flow: Input → Processing → Output.
- Although the project is compact, drawing separation between concerns will help in any future extension (e.g., adding new visualization modes).

##### Relevant Technologies and Libraries
- Rust Programming Language for system implementation.
- Cargo for dependency and build management.
- clap crate for command-line parsing.
- Standard Rust libraries for file I/O and data processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    mainEntry["main() [Entry Point]"]:::main

    subgraph "Input Layer"
        cliParser["CLI Parser (using clap)"]:::input
    end

    subgraph "Processing Layer"
        demParser["DEM File Loader & Parser (.asc file reader)"]:::processing
        visEngine["Visualization Engine (grayscale, color, hillshade, combined)"]:::processing
    end

    subgraph "Output Layer"
        renderer["Terminal Renderer"]:::output
    end

    mainEntry -->|"invokes"| cliParser
    cliParser -->|"loads file"| demParser
    demParser -->|"passes DEM data"| visEngine
    visEngine -->|"outputs visualization"| renderer

    click cliParser "https://github.com/mohamedmajdi/rust-dem-viewer/blob/main/src/main.rs"
    click demParser "https://github.com/mohamedmajdi/rust-dem-viewer/blob/main/src/main.rs"
    click visEngine "https://github.com/mohamedmajdi/rust-dem-viewer/blob/main/src/main.rs"
    click renderer "https://github.com/mohamedmajdi/rust-dem-viewer/blob/main/src/main.rs"

    classDef main fill:#f8c291,stroke:#333,stroke-width:2px;
    classDef input fill:#82ccdd,stroke:#333,stroke-width:2px;
    classDef processing fill:#f6e58d,stroke:#333,stroke-width:2px;
    classDef output fill:#6ab04c,stroke:#333,stroke-width:2px;
```
