# eyeshuang/vfs architecture

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

- Interactive diagram: https://gitdiagram.com/eyeshuang/vfs
- Repository: https://github.com/eyeshuang/vfs

## Overview

- Application Entry Point: Represented by the “cmd” package (cmd/main.go) which initializes and bootstraps the application.
- REPL Interface: Captured in the “repl” package (repl/repl.go) which handles interactive command input and output.
- Command Handlers: The “handler” package (files: file.go, folder.go, user.go, validator.go) processes and validates incoming CLI commands.
- Service Layer: The “service” package (files: file.go, folder.go, user.go) implements the business logic for the file system operations.
- Repository Layer: The “repo” package (files: file.go, folder.go, user.go) provides in-memory data management and persistence for users, folders, and files.
- Domain Model: Encapsulated in the “vfs.go” file that defines the core domain objects (user, folder, file).
- Testing & Mocks: Include “test” for integration tests and “mock” for mocking certain components, which are useful for verifying interactions.

##### Interactions and relationships
- The entry point (cmd/main.go) kickstarts the application, setting up the REPL (repl package).
- The REPL listens for user commands, passing them to the appropriate handlers.
- Handlers parse commands (ensuring validation in validator.go) and route requests to the relevant service components.
- The service layer executes the business logic (like registering users or managing file/folder operations) and relies on the repository layer for state management.
- The repositories manage the persistence (in this case, in-memory) of file system objects.
- Domain objects (defined in vfs.go) are used throughout to represent the system's key entities.
- Integration tests (under the “test” folder) verify the interactions between these components, ensuring data flows and dependencies work as expected.

##### Architectural patterns/design principles
- Layered (or multi-tier) architecture: The separation between the CLI interface, command handling, business logic (service layer), and data management (repository) is evident.
- Separation of concerns: Each package has a clear responsibility—from input (REPL) to processing (handlers and services) to persistence (repos).
- Testing and mocking: The presence of dedicated “test” and “mock” directories reinforces the design principle of testability and dependency isolation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        A["Entry Point (cmd/main.go)"]
        B["REPL Interface (repl/repl.go)"]
    end

    subgraph "Command Handlers"
        C1["File Handler (handler/file.go)"]
        C2["Folder Handler (handler/folder.go)"]
        C3["User Handler (handler/user.go)"]
        C4["Validator (handler/validator.go)"]
    end

    subgraph "Service Layer"
        D1["File Service (service/file.go)"]
        D2["Folder Service (service/folder.go)"]
        D3["User Service (service/user.go)"]
    end

    subgraph "Repository Layer"
        E1["File Repository (repo/file.go)"]
        E2["Folder Repository (repo/folder.go)"]
        E3["User Repository (repo/user.go)"]
    end

    subgraph "Data Layer"
        F["Domain Model (vfs.go)"]
    end

    subgraph "Support & Documentation"
        G["Testing (test)"]
        H["Mocks (mock/mock.go)"]
        I["Documentation (docs)"]
    end

    %% Main Flow Connections
    A -->|"start"| B
    B -->|"sendCommand"| C1
    C1 -->|"delegate"| D1
    D1 -->|"persist"| E1
    D1 -->|"useDomain"| F
    E1 -->|"manageDomain"| F

    %% Tie additional components within layers (assumed parallel components)
    C2 --- C1
    C3 --- C1
    C4 --- C1

    D2 --- D1
    D3 --- D1

    E2 --- E1
    E3 --- E1

    %% Click Events
    click A "https://github.com/eyeshuang/vfs/blob/main/cmd/main.go"
    click B "https://github.com/eyeshuang/vfs/blob/main/repl/repl.go"
    click C1 "https://github.com/eyeshuang/vfs/blob/main/handler/file.go"
    click C2 "https://github.com/eyeshuang/vfs/blob/main/handler/folder.go"
    click C3 "https://github.com/eyeshuang/vfs/blob/main/handler/user.go"
    click C4 "https://github.com/eyeshuang/vfs/blob/main/handler/validator.go"
    click D1 "https://github.com/eyeshuang/vfs/blob/main/service/file.go"
    click D2 "https://github.com/eyeshuang/vfs/blob/main/service/folder.go"
    click D3 "https://github.com/eyeshuang/vfs/blob/main/service/user.go"
    click E1 "https://github.com/eyeshuang/vfs/blob/main/repo/file.go"
    click E2 "https://github.com/eyeshuang/vfs/blob/main/repo/folder.go"
    click E3 "https://github.com/eyeshuang/vfs/blob/main/repo/user.go"
    click F "https://github.com/eyeshuang/vfs/blob/main/vfs.go"
    click G "https://github.com/eyeshuang/vfs/tree/main/test"
    click H "https://github.com/eyeshuang/vfs/blob/main/mock/mock.go"
    click I "https://github.com/eyeshuang/vfs/tree/main/docs"

    %% Styling
    class A,B fill:#ADD8E6,stroke:#333,stroke-width:2px
    class C1,C2,C3,C4 fill:#90EE90,stroke:#333,stroke-width:2px
    class D1,D2,D3 fill:#90EE90,stroke:#333,stroke-width:2px
    class E1,E2,E3 fill:#FFFF99,stroke:#333,stroke-width:2px
    class F fill:#FFDAB9,stroke:#333,stroke-width:2px
    class G,H,I fill:#D3D3D3,stroke:#333,stroke-width:2px
```
