# lab-smile/grace-cli architecture

> Architecture diagram of the GitHub repository lab-smile/grace-cli, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lab-smile/grace-cli
- Repository: https://github.com/lab-smile/grace-cli

## Overview

##### Project type and purpose
- This is a command-line tool (CLI) written in Python that wraps the GRACE model for batch processing of NIfTI medical images.
- It’s not a web or microservice system but a local‐execution pipeline: take .nii/.nii.gz files, run inference with a pre-trained GRACE model, and write output files.

##### File structure
Top-level files:
- run.sh       – Shell entry point; orchestrates virtual‐environment setup, dependency installation, and invokes the Python script.
- grace.py     – Core Python program: parses arguments, loads the GRACE model, runs inference via nibabel or similar, writes output.
- requirements.txt – Python dependencies.
- GRACE.pth    – (Not committed; downloaded at install) pre-trained model weights.
- inputs       – User-provided .nii/.nii.gz files or directory (not in repo but part of runtime).
- outputs      – Generated by the CLI; holds *_pred_GRACE.nii(.gz) files.

##### README for additional insights
- Steps: clone → chmod +x run.sh → download GRACE.pth → ./run.sh <input>
- run.sh:
1. create fresh venv
2. pip install -r requirements.txt
3. python grace.py <input>
4. outputs go into ./outputs
- Error handling for missing/invalid inputs, GPU optional if CUDA is available.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User-facing components
    User["User CLI"]:::user
    Doc["Project Documentation (README.md)"]:::user
    Run["Shell Wrapper (run.sh)"]:::user

    %% Environment layer
    subgraph "Environment Setup"
        direction TB
        Venv["Virtual Environment (venv)"]:::env
        Install["pip install (requirements.txt)"]:::env
        Python["Python Interpreter"]:::env
    end

    %% Processing layer
    subgraph "Processing Logic"
        direction TB
        Grace["Processing Module (grace.py)"]:::proc
        Model["GRACE Model File (GRACE.pth)"]:::proc
    end

    %% File system
    subgraph "File System"
        direction TB
        Input["Input Folder (inputs/)"]:::fs
        Output["Output Folder (outputs/)"]:::fs
    end

    %% Control and data flow
    User --> Doc
    Doc -.-> Run
    User --> Run
    Run --> Venv
    Run --> Install
    Install --> Python
    Run --> Python
    Python --> Grace
    Grace --> Model
    Grace --> Input
    Grace --> Output

    %% Click Events
    click Run "https://github.com/lab-smile/grace-cli/blob/main/run.sh"
    click Grace "https://github.com/lab-smile/grace-cli/blob/main/grace.py"
    click Install "https://github.com/lab-smile/grace-cli/blob/main/requirements.txt"
    click Doc "https://github.com/lab-smile/grace-cli/blob/main/README.md"

    %% Styles
    classDef user fill:#a8f0c6,stroke:#333,stroke-width:1px
    classDef env fill:#a0c4ff,stroke:#333,stroke-width:1px
    classDef proc fill:#f9f19f,stroke:#333,stroke-width:1px
    classDef fs fill:#d3d3d3,stroke:#333,stroke-width:1px
```
