# movila/cleanrn architecture

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

- Interactive diagram: https://gitdiagram.com/movila/cleanrn
- Repository: https://github.com/movila/cleanrn

## Overview

##### Project type and purpose
- This is a small, single-binary CLI tool named `@movila/cleanrn` whose sole purpose is to scan a React Native project folder, detect build artifacts/caches/logs, and delete them safely.
- It ships as an npm package with a shell wrapper (`bin/cleanrn.sh`) and a Node.js entrypoint (`index.js`), exposes command-line flags (dry-run, force, verbose), and integrates with the host OS (Bash, file system, Watchman if present).

##### File structure
- Top level:
- LICENSE, README.md — docs and licensing
- package.json — package metadata, CLI “bin” mapping, dependencies
- index.js — the core Node.js program
- bin/cleanrn.sh — shell‐wrapper stub to launch `index.js` in Bash
- No frontend, no services; purely a script that interacts with the local file system.

##### README for additional insights
- The tool has modular “cleaners” for:
- Dependencies & caches
- iOS artifacts
- Android artifacts
- General cleanup (logs, coverage, Expo cache)
- Safety features (project detection, dry-run, confirmation prompt) wrap around those cleaners.
- Outputs structured feedback to STDOUT.

a. Main components
1. User/Developer (CLI invoker)
2. Shell wrapper (`bin/cleanrn.sh`)
3. Node.js runtime & `index.js` (CLI core)
4. Command-line parser (flags → configuration)
5. Safety & detection module
6. Cleaner modules (DependencyCleaner, CacheCleaner, iOSCleaner, AndroidCleaner, GeneralCleaner)
7. File system & OS environment (Bash, Watchman, npm, Yarn)
8. Console/Logger (feedback to user)
b. Relationships & data flow
- Developer runs `cleanrn` → shell wrapper → Node.js process
- CLI parser reads flags → config object
- Safety module performs project detection & confirmation → passes permit to cleaning engine
- Cleaning engine iterates through cleaner modules → each module reads/deletes target paths in file system
- Logger prints progress & summary to console
c. Architectural patterns & principles
- Modular design: each cleaner is a separate unit
- Pipeline pattern: safety → configuration → execution
- Single responsibility: shell wrapper only boots Node.js, index.js orchestrates everything
d. Key technologies
- Bash script (POSIX shell)
- Node.js (CommonJS modules)
- File system APIs (`fs`), child-process (optional for Watchman)
- npm CLI for installation/distribution

##### Detail
- Confirmation prompt as a decision diamond between safety check and cleaning engine
- Callouts for optional paths (e.g., Watchman detection, dry-run skip deletion)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Developer["Developer/CLI Invoker"]:::userFacing
    Developer -->|"runs cleanrn"| ShellWrapper
    subgraph "Shell Shim"
        ShellWrapper["Shell Wrapper\n(bin/cleanrn.sh)"]:::userFacing
    end
    ShellWrapper -->|"executes"| NodeProcess
    NodeProcess["Node.js Process\n(index.js)"]:::userFacing

    subgraph "Core Logic"
        CLIParser["CLI Parser"]:::userFacing
        Safety["Safety & Detection Module"]:::coreLogic
        Decision{"Confirmation Prompt\n(dry-run, force)"}:::coreLogic
        subgraph "Cleaner Modules"
            DepCleaner["DependencyCleaner"]:::coreLogic
            CacheCleaner["CacheCleaner"]:::coreLogic
            iOSCleaner["iOSCleaner"]:::coreLogic
            AndroidCleaner["AndroidCleaner"]:::coreLogic
            GeneralCleaner["GeneralCleaner"]:::coreLogic
        end
        Logger["Logger/Console Output"]:::coreLogic
    end

    NodeProcess --> CLIParser
    CLIParser --> Safety
    Safety --> Decision
    Decision -->|"confirm"| DepCleaner
    Decision -->|"confirm"| CacheCleaner
    Decision -->|"confirm"| iOSCleaner
    Decision -->|"confirm"| AndroidCleaner
    Decision -->|"confirm"| GeneralCleaner

    DepCleaner --> FileSystem
    CacheCleaner --> FileSystem
    iOSCleaner --> FileSystem
    AndroidCleaner --> FileSystem
    GeneralCleaner --> FileSystem

    DepCleaner --> Logger
    CacheCleaner --> Logger
    iOSCleaner --> Logger
    AndroidCleaner --> Logger
    GeneralCleaner --> Logger

    Logger --> Console["Console Output\n(STDOUT)"]:::external

    FileSystem["File System & OS\n(Bash, Watchman)"]:::external

    Developer -.-> README["README.md"]:::docs
    Developer -.-> LICENSE["LICENSE"]:::docs
    NodeProcess -.-> PackageMeta["package.json"]:::meta

    click ShellWrapper "https://github.com/movila/cleanrn/blob/main/bin/cleanrn.sh"
    click NodeProcess "https://github.com/movila/cleanrn/blob/main/index.js"
    click CLIParser "https://github.com/movila/cleanrn/blob/main/index.js"
    click Safety "https://github.com/movila/cleanrn/blob/main/index.js"
    click DepCleaner "https://github.com/movila/cleanrn/blob/main/index.js"
    click CacheCleaner "https://github.com/movila/cleanrn/blob/main/index.js"
    click iOSCleaner "https://github.com/movila/cleanrn/blob/main/index.js"
    click AndroidCleaner "https://github.com/movila/cleanrn/blob/main/index.js"
    click GeneralCleaner "https://github.com/movila/cleanrn/blob/main/index.js"
    click Logger "https://github.com/movila/cleanrn/blob/main/index.js"
    click PackageMeta "https://github.com/movila/cleanrn/blob/main/package.json"
    click README "https://github.com/movila/cleanrn/blob/main/README.md"
    click LICENSE "https://github.com/movila/cleanrn/tree/main/LICENSE"

    classDef userFacing fill:#add8e6,stroke:#333,stroke-width:1px
    classDef coreLogic fill:#98fb98,stroke:#333,stroke-width:1px
    classDef external fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef docs fill:#fdfd96,stroke:#333,stroke-width:1px
    classDef meta fill:#dda0dd,stroke:#333,stroke-width:1px
```
