A minimalist command-line task tracker built with Java, using no external libraries and following MVC architecture.
This project was designed to deepen my understanding of core Java concepts while overcoming the challenges of working without external libraries. Key learnings include:
-
Manual JSON Handling:
- Parsing and writing JSON files without libraries like Gson or Jackson.
- Implementing robust string manipulation to avoid
ArrayIndexOutOfBoundsExceptionand malformed JSON. - Handling edge cases (e.g., empty files, missing fields) with custom logic.
-
MVC Architecture:
- Model:
TaskModelandTaskListModelmanage data and business logic. - View:
TaskClihandles user input/output. - Controller:
TaskControllerbridges Model and View. - Reinforced separation of concerns and modular design.
- Model:
-
File I/O Operations:
- Reading/writing to
tasks.jsonin the user’s home directory. - Ensuring atomicity and error handling for file operations.
- Reading/writing to
Challenge: Parsing and generating JSON manually is error-prone.
Solutions:
- Used
String.split()and regex to extract key-value pairs. - Added validation for missing/empty fields (e.g.,
finishedAt). - Wrote a custom
toJson()/fromJson()inTaskModel.
Challenge: Avoiding corruption when saving/loading tasks.
Solutions:
- Atomic writes with
FileWriterand backups (e.g.,tasks.json.bak). - Checks for file existence and empty content in
TaskListModel.
Challenge: Tight coupling between components.
Solutions:
- Strict separation:
- View (
TaskCli) only interacts with Controller. - Model has no dependency on View.
- View (
# Add a task
java View.TaskCli add "Buy groceries"
# Remove a task (by ID)
java View.TaskCli remove 1
# List all tasks
java View.TaskCli list allsrc/
├── Model/ # Business logic and data
│ ├── TaskModel.java
│ └── TaskListModel.java
├── View/ # CLI interface
│ └── TaskCli.java
└── Controller/ # Mediates Model-View
└── TaskController.java
// From TaskModel.java
public static TaskModel fromJson(String json) {
json = json.replace("{", "").replace("}", "").replace("\"", "").trim();
String[] pairs = json.split(",");
// Iterate over key-value pairs...
}// In TaskCli.java (View)
addTaskFromCli(args[1]); // Calls Controller
// In TaskController.java
list.addTask(description); // Delegates to Model
list.saveTasks(); // Saves to JSON-
Fundamentals Over Convenience:
By avoiding libraries, I gained hands-on experience with file I/O, data serialization, and error handling—skills transferable to low-level systems programming. -
MVC in Practice:
Learned how to decouple logic, making the codebase scalable and testable.
Built with ♥ and javac. Feedback welcome! 🚀