Skip to content

Frontend Package

@habit-tracker/frontend

React + Vite web application for the Habit Tracker. Provides the user interface for managing habits, viewing progress, and configuring settings.

Key Files

FilePurpose
src/App.tsxMain app component with routing
src/api/client.tsAPI client for backend communication
src/hooks/useHabits.tsHook for fetching and managing habits
src/hooks/useTodayLogs.tsHook for today's completion logs
src/components/DailyChecklist.tsxMain habit list with checkboxes
src/components/QuickAddHabit.tsxQuick habit creation form
src/components/HabitItem.tsxHabit card and modal component
src/pages/GlobalSettings.tsxBlocked websites configuration

Components

Core Components

ComponentDescription
DailyChecklistLists today's habits with completion status
HabitItemIndividual habit card that expands to modal
QuickAddHabitSingle-field habit creation
EmergencyResetButtonUnblock all websites immediately

Data Visualization

ComponentDescription
CalendarViewMonthly calendar showing completion history
GraphViewCharts for data-tracking habits

Pages

RouteComponentDescription
/HomePageMain daily checklist view
/settingsGlobalSettingsConfigure blocked websites

Development

bash
# Start development server (port 5174)
npm run dev -w @habit-tracker/frontend

# Build for production
npm run build -w @habit-tracker/frontend

# Run tests
npm test -w @habit-tracker/frontend

Architecture

The frontend uses a simple data-fetching pattern:

  1. Hooks manage data fetching and state (useHabits, useTodayLogs)
  2. API Client handles HTTP requests to the backend
  3. Components render UI and dispatch actions

State is primarily server-driven - after any mutation, hooks refetch data to ensure consistency.

Data Flow

User Action → Component → API Client → Backend

           Hook refresh → Component re-render

Key Dependencies

PackagePurpose
react-router-domClient-side routing
zodRuntime schema validation

Environment Variables

VariableDevelopmentProduction
VITE_API_URLhttp://localhost:3001http://localhost:3000

Built with VitePress