# hiepphatle1104/todo-cli architecture

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

- Interactive diagram: https://gitdiagram.com/hiepphatle1104/todo-cli
- Repository: https://github.com/hiepphatle1104/todo-cli

## Overview

##### Main Components
- CLI Entry Point (main.go & cmd/root.go): This is where the application starts and where command parsing is managed. The “cmd” folder encapsulates the CLI command definitions and routing.
- Core Business Logic (tasks/tasks.go): This module hosts the logic for task commands (e.g., adding, deleting, updating tasks) and acts as the primary coordinator for user requests.
- Data Model (models/model_task.go): This defines the task structure – the properties that make up a task.
- Persistence Layer (storage/storage.go and tasks.json): This module handles file I/O operations for reading from and saving tasks to a JSON file.
- Supporting Files: go.mod, go.sum, and the LICENSE file represent project configuration and licensing, while .idea is a development environment configuration folder.

##### Relationships and Data Flow
- When a user enters a command (like “todo add [task-name]”), the input is first processed by the CLI entry point (main.go and cmd/root.go).
- The parsed command then delegates processing to the business logic in the tasks package.
- The tasks module uses the task model to properly structure the data and calls the storage module to either read from or write to the tasks.json file.
- Data flows directionally: User Input → CLI Parsing → Business Logic → Data Model & Persistence.
- Return values or error messages can be sent back via the CLI for user feedback.

##### Architectural Patterns & Technologies
- Separation of Concerns: The system is divided into clear layers (CLI, business logic, data model, persistence) ensuring that each module has its dedicated responsibility.
- Modularity: Components are grouped into different directories which makes the application extendable and maintainable.
- Use of Golang Standard Packages and Techniques: Built-in file I/O, command-line handling, and modular design principles.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Terminal("User Commands"):::external

    subgraph "CLI Interface"
        main["main.go"]:::core
        root["cmd/root.go"]:::core
    end

    Manager["Task Manager/Controller"]:::core
    Model["Task Model"]:::data

    subgraph "Persistence Layer"
        StorageModule["Storage Module"]:::data
        TasksData(("Tasks Data")):::data
    end

    Terminal -->|"command"| main
    main -->|"routes"| root
    root -->|"delegates"| Manager
    Manager <-->|"task_ops"| Model
    Manager <-->|"persist_ops"| StorageModule
    Manager <-->|"persist_ops"| TasksData
    Manager -->|"feedback"| root
    root -->|"output"| Terminal

    click main "https://github.com/hiepphatle1104/todo-cli/blob/main/main.go"
    click root "https://github.com/hiepphatle1104/todo-cli/blob/main/cmd/root.go"
    click Manager "https://github.com/hiepphatle1104/todo-cli/blob/main/tasks/tasks.go"
    click Model "https://github.com/hiepphatle1104/todo-cli/blob/main/models/model_task.go"
    click StorageModule "https://github.com/hiepphatle1104/todo-cli/blob/main/storage/storage.go"
    click TasksData "https://github.com/hiepphatle1104/todo-cli/blob/main/tasks.json"

    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef data fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
```
