# lightrao/flutter_todo_list_app architecture

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

- Interactive diagram: https://gitdiagram.com/lightrao/flutter_todo_list_app
- Repository: https://github.com/lightrao/flutter_todo_list_app

## Overview

##### Main Components
- UI Layer: Represented by the “screens” (e.g., todo_list_page.dart) and “widgets” (e.g., add_task_dialog.dart) directories. This part covers the Material Design-based user interface where users interact with the app.
- Provider/State Management Layer: Represented by the “providers/todo_model.dart” file. This component handles the state of tasks and acts as the intermediary between UI events and backend operations.
- Models Layer: Represented by “models/task.dart”. This contains the data representation of a task, including methods for mapping to and from the database.
- Services Layer: Includes:
- Database Service: Located in “services/database/database_helper.dart”, which utilizes the Singleton pattern for handling SQLite database operations.
- File Service: Found in “services/file_service.dart”, managing task export/import functionality.
- External Dependencies: Show that the app leverages third-party Flutter packages such as Provider for state management, sqflite for SQLite operations, File Picker for file I/O, and Permission Handler for managing access rights.

##### Relationships and Interactions
- The UI Layer communicates user actions (e.g., add, update, or delete tasks) to the Provider layer.
- The Provider layer updates the Models (task.dart) and triggers the Database Service to persist changes.
- The Database Service is responsible for performing optimized queries using SQLite.
- The File Service handles exporting to and importing from JSON files, interacting with the file system.

##### Important Architectural Patterns and Design Principles
- Separation of Concerns: Clearly distinguish between UI, state management, models, and services.
- Singleton Pattern: Highlight the use of the singleton for database management (ensuring a single point of access to the database connection).
- Resource Management: Note the emphasis on resource disposal and efficient memory handling for task management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface (Screens & Widgets)"
        UI1["Todo List Page (Screen)"]:::ui
        UI2["Add Task Dialog (Widget)"]:::ui
    end

    subgraph "State Management"
        Provider["State Management (Provider)"]:::provider
    end

    subgraph "Data Models"
        Model["Task Model"]:::model
    end

    subgraph "Services"
        DBService["Database Service (SQLite)"]:::service
        FileService["File Service (Import/Export)"]:::service
    end

    subgraph "External Persistence & Integration"
        SQLiteDB["SQLite Database"]:::database
        FileSystem["File System"]:::filesystem
    end

    subgraph "External Libraries"
        Flutter["Flutter"]:::external
        ProviderLib["Provider"]:::external
        Sqflite["sqflite"]:::external
        FilePicker["File Picker"]:::external
        PermissionHandler["Permission Handler"]:::external
    end

    %% Data Flow from UI to Provider
    UI1 -->|"userAction"| Provider
    UI2 -->|"userAction"| Provider

    %% Provider communicates with Models and Services
    Provider -->|"update"| Model
    Provider -->|"persist"| DBService
    Provider -->|"export/import"| FileService

    %% Services interactions with external resources
    DBService -->|"query"| SQLiteDB
    SQLiteDB -->|"results"| DBService

    FileService -->|"fileI/O"| FileSystem

    %% Click events for component mapping
    click UI1 "https://github.com/lightrao/flutter_todo_list_app/blob/master/lib/screens/todo_list_page.dart"
    click UI2 "https://github.com/lightrao/flutter_todo_list_app/blob/master/lib/widgets/add_task_dialog.dart"
    click Provider "https://github.com/lightrao/flutter_todo_list_app/blob/master/lib/providers/todo_model.dart"
    click Model "https://github.com/lightrao/flutter_todo_list_app/blob/master/lib/models/task.dart"
    click DBService "https://github.com/lightrao/flutter_todo_list_app/blob/master/lib/services/database/database_helper.dart"
    click FileService "https://github.com/lightrao/flutter_todo_list_app/blob/master/lib/services/file_service.dart"

    %% Styling definitions
    classDef ui fill:#f9e79f,stroke:#e67e22,stroke-width:2px;
    classDef provider fill:#d2b4de,stroke:#8e44ad,stroke-width:2px;
    classDef model fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef service fill:#a9dfbf,stroke:#27ae60,stroke-width:2px;
    classDef database fill:#ffe599,stroke:#bf9000,stroke-width:2px;
    classDef filesystem fill:#fad7a0,stroke:#d35400,stroke-width:2px;
    classDef external fill:#e8daef,stroke:#8e44ad,stroke-width:2px;
```
