Skip to content

HussainAbdi/habit-tracker

Repository files navigation

Habit - A Google Sheets Powered Habit Tracker

A visual, mobile-first habit tracker PWA built with Next.js, Tailwind and the Google Sheets API. This is the real habit system I use every day - synced to the same Google Sheet I track my habits in.

The app renders a month-by-month calendar UI, hydrates from my Sheet on load, and updates the Sheet instantly when I mark habits complete.

Demo

habit-tracker-demo-edited

habit-tracker-software-preview habit-tracker-gym-preview habit-tracker-music-preview habit tracker - update habit

Google Sheets Backend

habit-tracker-sheets-backend

How It Works

Data Flow

Google Sheet ←→ Sheets API ←→ Next.js API Routes ←→ React Frontend

Loading Habits

The frontend calls GET /api/habit on mount, which:

  • Authenticates with Google via a service account
  • Reads the sheet and returns completed dates for all habits (Software, Music, Gym)
  • Groups entries by habit using a config-driven column mapping

Marking a Habit Complete

Tapping an uncompleted date:

  • Instantly updates the UI (optimistic update)
  • Triggers haptic feedback (Vibration API on Android, hidden <input switch> workaround on iOS 18+)
  • Fires an async POST /api/habit to write the value into the correct sheet cell

Editing a Completed Habit

Tapping a completed date opens a draggable bottom sheet where you can:

  • Log time spent (minutes or hours)
  • Add notes
  • Remove the entry

The bottom sheet uses velocity-based gesture detection for natural swipe-to-dismiss.

Multi-Habit Support

Habits are driven by a single HABIT_CONFIG object that maps each habit to its sheet columns. Switching between habits is done via arrow navigation, and adding a new habit requires only a config change.

Security

  • PIN-based authentication with rate limiting and secure HTTP-only cookies
  • All secrets (private key, sheet ID) stored in environment variables

Tech Stack

  • Frontend: Next.js 16, React 19, TypeScript, Tailwind CSS
  • Backend: Next.js API Routes, Google Sheets API
  • Deployment: Vercel with automatic CI/CD from GitHub

About

A visual, mobile-first habit tracker PWA built with Next.js, Tailwind and the Google Sheets API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors