Skip to content

Latest commit

 

History

46 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Todo CLI

A command-line todo application written in modern C++ using CMake.

This project was built as a practical exercise in C++ software design, focusing on object-oriented programming, separation of concerns, STL containers, file I/O, persistence, JSON serialization, and CMake-based project organization.

Features

  • Add tasks
  • List tasks
  • Mark tasks as completed
  • Remove tasks
  • Automatic task ID generation
  • Persistent task storage
  • JSON-based data storage
  • Interactive command-line menu
  • Input validation

Project Structure

todo-cli/
├── CMakeLists.txt
├── include/
│   ├── nlohmann/
│   │   └── ...                 # nlohmann/json headers
│   └── todo/
│       ├── FileStorage.h
│       ├── Task.h
│       └── TodoManager.h
├── src/
│   ├── FileStorage.cpp
│   ├── Task.cpp
│   ├── TodoManager.cpp
│   └── main.cpp
└── build/

Architecture

The project separates responsibilities between the main components:

Task

Represents an individual todo item.

A task contains:

  • ID
  • Title
  • Completion status

TodoManager

Responsible for todo-related business logic, including:

  • Adding tasks
  • Removing tasks
  • Completing tasks
  • Managing the collection of tasks

FileStorage

Responsible for persistence.

It handles:

  • Saving tasks to disk
  • Loading tasks from disk
  • JSON serialization and deserialization
  • File I/O

The application uses std::fstream for file operations and nlohmann/json for JSON serialization.

Data Persistence

Tasks are stored in:

tasks.json

Example:

[
    {
        "id": 1,
        "title": "Learn C++",
        "completed": false
    },
    {
        "id": 2,
        "title": "Build Todo CLI",
        "completed": true
    }
]

The persistence flow is:

Save:

std::vector<Task>
       ↓
JSON objects
       ↓
JSON array
       ↓
tasks.json


Load:

tasks.json
       ↓
JSON
       ↓
Task objects
       ↓
std::vector<Task>

Technologies

  • C++20
  • CMake
  • Ninja
  • nlohmann/json
  • STL
  • std::ifstream
  • std::ofstream

Building

Configure

From the project root:

cmake -S . -B build -G Ninja

Build

cmake --build build

Run

On Windows:

.\build\todo-cli.exe

Example

===== Todo CLI =====
1. Add task
2. List tasks
3. Complete task
4. Remove task
5. Exit

Choose an option:

Tasks are automatically saved to tasks.json, allowing them to persist between program executions.

Learning Goals

This project was built to practice:

  • Modern C++ fundamentals
  • Classes and object-oriented design
  • Header/source separation
  • Encapsulation
  • References and const correctness
  • STL containers
  • C++ file I/O
  • JSON serialization and deserialization
  • Error handling
  • CMake project configuration
  • Separation of responsibilities
  • Basic persistence architecture

Future Improvements

Possible future improvements include:

  • Automated unit tests
  • More robust JSON validation
  • Better error handling and recovery
  • Command-line arguments
  • Task priorities and due dates
  • Filtering and searching
  • Improved project architecture

License

This project is for educational and portfolio purposes.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages