mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-20 22:24:28 +01:00
4.1 KiB
4.1 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
HabitTrove is a gamified habit tracking PWA built with Next.js 15, TypeScript, and Jotai state management. Users earn coins for completing habits and can redeem them for rewards. Features multi-user support with admin capabilities and shared ownership of habits/wishlist items.
Essential Commands
Development
npm run dev- Start development server with Turbopacknpm run setup:dev- Full setup: installs bun, dependencies, runs typecheck and lintnpm install --force- Install dependencies (force flag required)
Quality Assurance (Run these before committing)
npm run typecheck- TypeScript type checking (required)npm run lint- ESLint code linting (required)npm test- Run tests with Bunnpm run build- Build production version
Docker Deployment
npm run docker-build- Build Docker image locallydocker compose up -d- Run with docker-compose (recommended)- Requires
AUTH_SECRETenvironment variable:openssl rand -base64 32
Version Management
Creating a New Version
- Update version in
package.json - Update
CHANGELOG.mdwith new version and changes (follow existing patterns in the file, keep entries concise - ideally 1 line per change) - Run
npm run typecheck && npm run lintto ensure code quality - Commit changes:
git add . && git commit -m "feat: description"
- Follow Conventional Commits Standard:
<type>[scope]: <description>(e.g.,feat(auth): add OAuth integration,fix: resolve memory leak in task loader).
Architecture Overview
State Management (Jotai)
- Central atoms:
habitsAtom,coinsAtom,wishlistAtom,usersAtominlib/atoms.ts - Derived atoms: Computed values like
dailyHabitsAtom,coinsBalanceAtom - Business logic hooks:
useHabits,useCoins,useWishlistin/hooks
Data Models & Ownership
- Individual ownership:
CoinTransactionhas singleuserId - Shared ownership:
HabitandWishlistItemTypehaveuserIds: string[]array - Admin features: Admin users can view/manage any user's data via dropdown selectors
- Data persistence: JSON files in
/datadirectory with automatic/backups
Key Components Structure
- Feature components:
HabitList,CoinsManager,WishlistManager- main page components - Modal components:
AddEditHabitModal,AddEditWishlistItemModal,UserSelectModal - UI components:
/components/ui- shadcn/ui based components
Authentication & Users
- NextAuth.js v5 with multi-user support
- User permissions: regular users vs admin users
- Admin dropdown patterns: Similar implementation across Habits/Wishlist pages (reference CoinsManager for pattern)
Internationalization
next-intlwith messages in/messages/*.json- Supported languages: English, Spanish, German, French, Russian, Chinese, Japanese
Code Patterns
Component Structure
// Standard component pattern:
export default function ComponentName() {
const [data, setData] = useAtom(dataAtom)
const { businessLogicFunction } = useCustomHook()
// Component logic
}
Hook Patterns
- Custom hooks accept options:
useHabits({ selectedUser?: string }) - Return destructured functions and computed values
- Handle both individual and shared ownership models
Shared Ownership Pattern
// Filtering for shared ownership:
const userItems = allItems.filter(item =>
item.userIds && item.userIds.includes(targetUserId)
)
Admin Dropdown Pattern
Reference CoinsManager.tsx:107-119 for admin user selection implementation. Similar pattern should be applied to Habits and Wishlist pages.
Data Safety
- Always backup
/databefore major changes - Test with existing data files to prevent data loss
- Validate user permissions for all data operations
- Handle migration scripts carefully (see PLAN.md for shared ownership migration)
Performance Considerations
- State updates use immutable patterns
- Large dataset filtering happens at hook level
- Derived atoms prevent unnecessary re-renders