Console Habit Tracker
Build a habit tracker for the terminal in Kotlin: add habits you want to build (such as reading or exercise), mark them done each day, and see your current and longest streaks, plus a small calendar of the last weeks. Habits and their history are saved in a JSON file with kotlinx.serialization, so they're still there next time. It's a good first Kotlin project: you'll learn data classes, lists and maps, working with dates using java.time (or kotlinx-datetime), reading user input in a menu loop, saving and loading JSON, handling errors, and testing with kotlin.test.
- Estimate
- ~7h
- Steps
- 5
- Completed by
- 0
- Proposed by
- codeseed.app
kotlinx-serialization · Gradle
Project roadmap
- 01
Design the data model
~1hCreate a Gradle Kotlin project with the kotlinx.serialization plugin. Define a @Serializable data class Habit (id, name, created date, and a set of dates it was completed, stored as ISO strings or with a serializer for LocalDate) and a HabitStore holding the list. Done when: the project builds, and a Habit can be created in code.
- 02
Save and load JSON
~1.5hSave the habits as JSON with Json.encodeToString to a file in the user's home folder, and load them at startup. When the file doesn't exist, start empty; when it's broken, keep a backup copy and start empty with a warning instead of crashing. Write to a temporary file and rename it. Done when: habits saved in one run are loaded in the next.
- 03
Build the menu
~1.5hWrite a loop showing a numbered menu (list habits, add a habit, mark done today, mark done on another date, delete a habit and quit) and reading choices with readLine, handling invalid choices and a null input (end of input). Names can't be empty or duplicated, and dates can't be in the future. Save after every change. Done when: every menu option works.
- 04
Calculate streaks
~1.5hWrite pure functions for the current streak (consecutive days ending today, or yesterday if today isn't done yet) and the longest streak ever, using java.time.LocalDate. Show them in the habit list, with a small grid of the last 4 weeks using # for done days and . for missed ones. Done when: the streaks and grid match the recorded days.
- 05
Test it
~1.5hWrite tests with kotlin.test: streak calculations with fixed dates (gaps, today not done, a single day and across months), JSON round trips, loading a broken file, and input validation. Done when: ./gradlew test passes.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack