Skip to content

Commit 8fb7cd1

Browse files
authored
Add project documentation and translation guide (#174)
1 parent a6f5bf1 commit 8fb7cd1

File tree

10 files changed

+640
-4
lines changed

10 files changed

+640
-4
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ Dockerfile
77
node_modules
88
npm-debug.log
99
data
10+
CLAUDE.md
11+
docs/

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## Version 0.2.25
4+
5+
### Added
6+
7+
* 🌍 Added Catalan language support (Català)
8+
9+
### Fixed
10+
11+
* Translation files consistency: Added missing UserForm keys to English and Korean translations
12+
313
## Version 0.2.24
414

515
### Added

CLAUDE.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
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.
8+
9+
## Essential Commands
10+
11+
### Development
12+
- `npm run dev` - Start development server with Turbopack
13+
- `npm run setup:dev` - Full setup: installs bun, dependencies, runs typecheck and lint
14+
- `npm install --force` - Install dependencies (force flag required)
15+
16+
### Quality Assurance (Run these before committing)
17+
- `npm run typecheck` - TypeScript type checking (required)
18+
- `npm run lint` - ESLint code linting (required)
19+
- `npm test` - Run tests with Bun
20+
- `npm run build` - Build production version
21+
22+
### Docker Deployment
23+
- `npm run docker-build` - Build Docker image locally
24+
- `docker compose up -d` - Run with docker-compose (recommended)
25+
- Requires `AUTH_SECRET` environment variable: `openssl rand -base64 32`
26+
27+
## Architecture Overview
28+
29+
### State Management (Jotai)
30+
- **Central atoms**: `habitsAtom`, `coinsAtom`, `wishlistAtom`, `usersAtom` in `lib/atoms.ts`
31+
- **Derived atoms**: Computed values like `dailyHabitsAtom`, `coinsBalanceAtom`
32+
- **Business logic hooks**: `useHabits`, `useCoins`, `useWishlist` in `/hooks`
33+
34+
### Data Models & Ownership
35+
- **Individual ownership**: `CoinTransaction` has single `userId`
36+
- **Shared ownership**: `Habit` and `WishlistItemType` have `userIds: string[]` array
37+
- **Admin features**: Admin users can view/manage any user's data via dropdown selectors
38+
- **Data persistence**: JSON files in `/data` directory with automatic `/backups`
39+
40+
### Key Components Structure
41+
- **Feature components**: `HabitList`, `CoinsManager`, `WishlistManager` - main page components
42+
- **Modal components**: `AddEditHabitModal`, `AddEditWishlistItemModal`, `UserSelectModal`
43+
- **UI components**: `/components/ui` - shadcn/ui based components
44+
45+
### Authentication & Users
46+
- NextAuth.js v5 with multi-user support
47+
- User permissions: regular users vs admin users
48+
- Admin dropdown patterns: Similar implementation across Habits/Wishlist pages (reference CoinsManager for pattern)
49+
50+
### Internationalization
51+
- `next-intl` with messages in `/messages/*.json`
52+
- Supported languages: English, Spanish, German, French, Russian, Chinese, Japanese
53+
54+
## Code Patterns
55+
56+
### Component Structure
57+
```typescript
58+
// Standard component pattern:
59+
export default function ComponentName() {
60+
const [data, setData] = useAtom(dataAtom)
61+
const { businessLogicFunction } = useCustomHook()
62+
// Component logic
63+
}
64+
```
65+
66+
### Hook Patterns
67+
- Custom hooks accept options: `useHabits({ selectedUser?: string })`
68+
- Return destructured functions and computed values
69+
- Handle both individual and shared ownership models
70+
71+
### Shared Ownership Pattern
72+
```typescript
73+
// Filtering for shared ownership:
74+
const userItems = allItems.filter(item =>
75+
item.userIds && item.userIds.includes(targetUserId)
76+
)
77+
```
78+
79+
### Admin Dropdown Pattern
80+
Reference `CoinsManager.tsx:107-119` for admin user selection implementation. Similar pattern should be applied to Habits and Wishlist pages.
81+
82+
## Data Safety
83+
- Always backup `/data` before major changes
84+
- Test with existing data files to prevent data loss
85+
- Validate user permissions for all data operations
86+
- Handle migration scripts carefully (see PLAN.md for shared ownership migration)
87+
88+
## Performance Considerations
89+
- State updates use immutable patterns
90+
- Large dataset filtering happens at hook level
91+
- Derived atoms prevent unnecessary re-renders

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Want to try HabitTrove before installing? Visit the public [demo instance](https
2020
- 💰 Create a wishlist of rewards to redeem with earned coins
2121
- 📊 View your habit completion streaks and statistics
2222
- 📅 Calendar heatmap to visualize your progress (WIP)
23-
- 🌍 Multi-language support (English, Español, Deutsch, Français, Русский, 简体中文, 한국어, 日本語)
23+
- 🌍 Multi-language support (English, Español, Català, Deutsch, Français, Русский, 简体中文, 한국어, 日本語)
2424
- 🌙 Dark mode support
2525
- 📲 Progressive Web App (PWA) support
2626
- 💾 Automatic daily backups with rotation

app/settings/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ export default function SettingsPage() {
229229
{/* Add more languages as needed */}
230230
<option value="en">English</option>
231231
<option value="es">Español</option>
232+
<option value="ca">Català</option>
232233
<option value="de">Deutsch</option>
233234
<option value="fr">Français</option>
234235
<option value="ru">Русский</option>

docs/translation-guide.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Language Guide
2+
3+
## Adding/Updating Translations
4+
5+
### Adding a New Language
6+
7+
To add a new language translation to HabitTrove:
8+
9+
1. **Create translation file**:
10+
- Copy `messages/en.json` as a template
11+
- Save as `messages/{language-code}.json` (e.g., `ko.json` for Korean)
12+
- Translate all values while preserving keys and placeholder variables like `{username}`, `{count}`, etc.
13+
14+
2. **Validate translation structure**:
15+
```bash
16+
# Ensure JSON is valid
17+
jq empty messages/{language-code}.json
18+
19+
# Compare structure with English (should show no differences)
20+
diff <(jq -S . messages/en.json | jq -r 'keys | sort | .[]') <(jq -S . messages/{language-code}.json | jq -r 'keys | sort | .[]')
21+
```
22+
23+
3. **Add language option to UI**:
24+
- Edit `app/settings/page.tsx`
25+
- Add new `<option value="{language-code}">{Language Name}</option>` in alphabetical order
26+
27+
4. **Update documentation**:
28+
- Add language to README.md supported languages list
29+
- Create new changelog entry with version bump
30+
- Update package.json version
31+
32+
### Example: Adding Korean (한국어)
33+
34+
```bash
35+
# 1. Copy translation file
36+
cp /path/to/ko.json messages/ko.json
37+
38+
# 2. Add to settings page
39+
# Add: <option value="ko">한국어</option>
40+
41+
# 3. Update README.md
42+
# Change: 简体中文, 日본語
43+
# To: 简체中文, 한국어, 日본語
44+
45+
# 4. Add changelog entry
46+
# Create new version section with language addition
47+
48+
# 5. Bump package version
49+
# Update version in package.json
50+
```
51+
52+
### Translation Quality Guidelines
53+
54+
- Use natural, contextually appropriate expressions
55+
- Maintain consistent terminology throughout
56+
- Preserve all placeholder variables exactly: `{username}`, `{count}`, `{target}`, etc.
57+
- Use appropriate formality level for the target language
58+
- Ensure JSON structure matches English file exactly (385 total keys)
59+
60+
### Validation Commands
61+
62+
```bash
63+
# Check JSON validity
64+
jq empty messages/{lang}.json
65+
66+
# Compare key structure
67+
node -e "
68+
const en = require('./messages/en.json');
69+
const target = require('./messages/{lang}.json');
70+
// ... deep key comparison script
71+
"
72+
73+
# Verify placeholder consistency
74+
grep -o '{[^}]*}' messages/en.json | sort | uniq > en_vars.txt
75+
grep -o '{[^}]*}' messages/{lang}.json | sort | uniq > {lang}_vars.txt
76+
diff en_vars.txt {lang}_vars.txt
77+
```

0 commit comments

Comments
 (0)