# mohit-s96/fs-utils architecture

> Architecture diagram of the GitHub repository mohit-s96/fs-utils, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohit-s96/fs-utils
- Repository: https://github.com/mohit-s96/fs-utils

## Overview

##### Main Components
- Entry Point & CLI Parser: The main.c file and cli.c/h implement the CLI parser responsible for reading user input and dispatching commands.
- Command Handlers: Individual commands are split across separate source files:
- ls (ls.c)
- find (find.c)
- cp (copy.c)
- new (new.c)
- size (size.c)
- Testing: The tests directory containing tests/test.c houses unit or integration tests for the CLI utilities.
- Build & Deployment: Makefile provides the build commands, installation, and test running instructions.

##### Relationships and Interactions
- The main entry (from main.c) initializes the CLI parser (from cli.c) which then routes to the correct command handler based on the user’s input.
- Each command handler (ls, find, cp, new, size) encapsulates the logic for that particular command, using shared utilities (such as multi-threading support from threads.c/h and pattern matching from pattern.c/h) when needed.
- The Makefile serves as the build orchestrator, compiling sources, running tests, and managing the installation process.
- The test suite invokes various parts of the code base to ensure correctness of functionalities.

##### Architectural Patterns and Design Principles
- Modular Design: The system is neatly divided by commands and common utility modules.
- Separation of Concerns: The CLI parser is separated from the individual command implementations, providing a clean boundary between input handling and file operations.
- Multi-threading: Some commands (find, cp, and du-like operations in size) have multi-threaded support, which implies components related to thread management (threads.c, threads.h) and possibly resource pooling (arena.c, arena.h).
- Extensibility: By separating commands into individual modules, it’s easier to add or modify functionalities without affecting the overall system.

##### Relevant Technologies, Frameworks, or Libraries
- C as the programming language.
- POSIX system calls for file operations.
- Likely use of pthreads for multi-threading (implied by threads.c/h).
- Standard C libraries for string, file, and I/O operations.
- The Make build system for building, testing, and installing the utility.

## Diagram (Mermaid)

```mermaid
flowchart TD
    M["Build & Deployment (Makefile)"]:::build
    A["Entry Point / Main Module (main.c)"]:::main
    B["CLI Parser (cli.c/h)"]:::cli

    M --> A
    A --> B

    subgraph "Command Handlers"
        C["LS Command (ls.c)"]:::command
        D["Find Command (find.c)"]:::command
        E["Copy Command (copy.c)"]:::command
        F["New Command (new.c)"]:::command
        G["Size Command (size.c)"]:::command
    end

    B --> C
    B --> D
    B --> E
    B --> F
    B --> G

    subgraph "Shared Utilities"
        U["General Helpers (utils.c/h)"]:::util
        V["Output Formatting (colors.c/h)"]:::util
        W["Pattern Matching (pattern.c/h)"]:::util
    end

    %% Connect each Command to Shared Utilities
    C -.-> U
    C -.-> V
    C -.-> W

    D -.-> U
    D -.-> V
    D -.-> W

    E -.-> U
    E -.-> V
    E -.-> W

    F -.-> U
    F -.-> V
    F -.-> W

    G -.-> U
    G -.-> V
    G -.-> W

    %% Multi-threading support used by Find and Copy commands
    X["Multi-threading Module (threads.c/h)"]:::multi
    D -.-> X
    E -.-> X

    %% Memory/Resource Management linked to Multi-threading
    Y["Memory/Resource Management (arena.c/h)"]:::mem
    X -.-> Y

    %% Testing Suite integration
    T["Testing Suite (tests/test.c)"]:::test
    T -.-> B

    %% Click Events
    click A "https://github.com/mohit-s96/fs-utils/blob/master/main.c"
    click B "https://github.com/mohit-s96/fs-utils/blob/master/cli.c"
    click C "https://github.com/mohit-s96/fs-utils/blob/master/ls.c"
    click D "https://github.com/mohit-s96/fs-utils/blob/master/find.c"
    click E "https://github.com/mohit-s96/fs-utils/blob/master/copy.c"
    click F "https://github.com/mohit-s96/fs-utils/blob/master/new.c"
    click G "https://github.com/mohit-s96/fs-utils/blob/master/size.c"
    click U "https://github.com/mohit-s96/fs-utils/blob/master/utils.c"
    click V "https://github.com/mohit-s96/fs-utils/blob/master/colors.c"
    click W "https://github.com/mohit-s96/fs-utils/blob/master/pattern.c"
    click X "https://github.com/mohit-s96/fs-utils/blob/master/threads.c"
    click Y "https://github.com/mohit-s96/fs-utils/blob/master/arena.c"
    click T "https://github.com/mohit-s96/fs-utils/blob/master/tests/test.c"
    click M "https://github.com/mohit-s96/fs-utils/tree/master/Makefile"

    %% Styles
    classDef main fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef cli fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef command fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef util fill:#FFFF99,stroke:#333,stroke-width:2px;
    classDef multi fill:#FFDEAD,stroke:#333,stroke-width:2px;
    classDef mem fill:#FFC0CB,stroke:#333,stroke-width:2px;
    classDef test fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef build fill:#E6E6FA,stroke:#333,stroke-width:2px;
```
