Skip to content

Commit f41b281

Browse files
ChanMeng666claude
andcommitted
refactor(core): implement multi-assessment type architecture
Transform single friendship assessment into extensible multi-type platform BREAKING CHANGE: Assessment data structure updated with assessmentType field Features: - Add assessment configuration system with registry pattern - Create generic scoring algorithm in lib/core/scoring.ts - Implement dynamic assessment loading in stores - Add type filtering and badges in history page - Support multiple assessment types (friendship, family) Architecture Changes: - New lib/assessments/ structure with plugin-based configs - Dynamic routing with app/assess/[type]/ for type-specific assessments - Type-safe assessment configurations with TypeScript - Backward compatible data migration for existing assessments Components: - Create assessment type selection page (app/assess/page.tsx) - Refactor assessment page to support dynamic types - Update results page to render based on assessment type - Enhance history page with type filtering dropdown Assessment Types: - Migrate friendship assessment to new structure (20 questions, 10 categories) - Add family relationship assessment (16 questions, 8 categories) Developer Experience: - Add new assessment type in 4 simple steps - No component changes needed for new types - Full TypeScript type safety - Comprehensive CLAUDE.md documentation 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fd2c173 commit f41b281

18 files changed

Lines changed: 2065 additions & 276 deletions

File tree

CLAUDE.md

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
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+
FriendScope is a Next.js 15 application that provides scientific friendship assessments through a client-side architecture. The application evaluates friendships across 10 psychological categories using a 20-question assessment, providing users with detailed analytics, historical tracking, and personalized recommendations - all while maintaining complete privacy through local storage.
8+
9+
**Tech Stack:**
10+
- **Framework**: Next.js 15 with App Router, React 19, TypeScript 5
11+
- **Styling**: Tailwind CSS + shadcn/ui components
12+
- **State Management**: Zustand with persist middleware
13+
- **Charts**: Recharts + ApexCharts
14+
- **Animations**: Framer Motion + Lottie React
15+
- **PDF Export**: jsPDF
16+
- **Deployment**: Vercel
17+
18+
## Development Commands
19+
20+
```bash
21+
# Development
22+
npm run dev # Start dev server at http://localhost:3000
23+
npm run build # Build for production
24+
npm run start # Start production server
25+
npm run lint # Run ESLint
26+
27+
# Package Manager
28+
npm install # Install dependencies (also: yarn, pnpm)
29+
```
30+
31+
## Architecture
32+
33+
### Core Assessment System
34+
35+
The assessment engine (`lib/assessment.ts`) is the heart of the application:
36+
37+
- **20 questions across 10 categories**: Each question has a weight (1.0-1.5) reflecting psychological importance
38+
- **10 assessment categories**:
39+
- Trust & Honesty (weight: 1.5) - Core foundation
40+
- Emotional Support (weight: 1.2)
41+
- Communication (weight: 1.0)
42+
- Boundaries (weight: 1.3)
43+
- Reciprocity (weight: 1.1)
44+
- Conflict Resolution (weight: 1.2)
45+
- Growth & Development (weight: 1.0)
46+
- Values Alignment (weight: 1.4)
47+
- Respect & Recognition (weight: 1.2)
48+
- Reliability (weight: 1.3)
49+
50+
- **Scoring algorithm**: Weighted calculation that converts 7-point Likert scale responses into category scores (0-100), then averages to overall score
51+
- **Health assessment thresholds**: Excellent (85+), Good (70-84), Concerning (50-69), Unhealthy (30-49), Toxic (<30)
52+
53+
### State Management Architecture
54+
55+
**Two separate Zustand stores with different purposes:**
56+
57+
1. **`lib/store.ts`** - Assessment State (non-persistent):
58+
- Manages current assessment session
59+
- Tracks question progression and answers
60+
- Resets on completion
61+
- No persistence - temporary state only
62+
63+
2. **`lib/history-store.ts`** - History State (persistent):
64+
- Persists completed assessments to localStorage
65+
- Manages assessment history (max 50 entries)
66+
- Provides CRUD operations for historical data
67+
- Key: `friendship-assessment-history`
68+
69+
**Critical distinction**: Assessment state is transient; only completed assessments are saved to history store.
70+
71+
### Data Flow
72+
73+
```
74+
User Input → Assessment Store (temp) → Calculate Scores → Save to History Store (persistent) → Visualization
75+
```
76+
77+
1. User takes assessment (`app/assess/page.tsx`)
78+
2. Answers stored in temporary assessment store (`lib/store.ts`)
79+
3. On completion, scores calculated (`lib/assessment.ts:calculateScores`)
80+
4. Result saved to history store with localStorage persistence (`lib/history-store.ts`)
81+
5. User redirected to results page (`app/results/[id]/page.tsx`)
82+
83+
### Component Structure
84+
85+
```
86+
app/
87+
├── page.tsx # Landing page
88+
├── assess/page.tsx # Assessment interface (stepper through 20 questions)
89+
├── results/[id]/page.tsx # Individual result detail page
90+
├── results/page.tsx # All results overview
91+
├── history/page.tsx # Assessment history with comparison
92+
├── about/page.tsx # Mission and scientific foundation
93+
├── resources/page.tsx # Professional support resources
94+
└── layout.tsx # Root layout with Header/Footer
95+
96+
components/
97+
├── ui/ # shadcn/ui base components
98+
├── layout/ # Header.tsx, Footer.tsx
99+
├── dialogs/ # ShareDialog.tsx
100+
├── ComparisonChart.tsx # Multi-assessment comparison visualization
101+
├── FriendInfoDialog.tsx # Assessment metadata entry
102+
├── GEOHead.tsx # SEO/meta tags
103+
├── GEODashboard.tsx # Analytics dashboard
104+
└── LottieAnimation.tsx # Animation wrapper
105+
106+
lib/
107+
├── assessment.ts # Questions, scoring, health assessment logic
108+
├── assessment-utils.ts # PDF generation, share functionality
109+
├── store.ts # Assessment state (non-persistent)
110+
├── history-store.ts # History state (persistent to localStorage)
111+
├── geo-analytics.ts # Analytics utilities
112+
├── svg-generator.ts # SVG export functionality
113+
├── fonts.ts # Font configurations
114+
└── utils.ts # General utilities (cn, etc.)
115+
116+
types/
117+
└── assessment.ts # AssessmentResult interface
118+
```
119+
120+
## Key Implementation Details
121+
122+
### Assessment Question Format
123+
124+
Each question in `lib/assessment.ts` follows this structure:
125+
```typescript
126+
{
127+
id: number, // 1-20
128+
text: string, // Question text
129+
options: string[], // 7-point Likert scale (standardOptions)
130+
category: string, // One of 10 categories
131+
weight: number // 1.0-1.5 (psychological importance)
132+
}
133+
```
134+
135+
### Score Calculation
136+
137+
The `calculateScores` function in `lib/assessment.ts:182`:
138+
1. Groups answers by category
139+
2. Converts each answer to weighted score: `((optionsLength - 1 - optionIndex) / (optionsLength - 1)) * 100 * weight`
140+
3. Calculates category averages
141+
4. Overall score = mean of all category averages
142+
143+
### localStorage Schema
144+
145+
```typescript
146+
// Key: friendship-assessment-history
147+
{
148+
state: {
149+
assessments: AssessmentResult[] // Max 50 entries
150+
},
151+
version: 0
152+
}
153+
```
154+
155+
### TypeScript Path Aliases
156+
157+
Uses `@/*` alias for imports (e.g., `@/lib/assessment`, `@/components/ui/button`)
158+
159+
## Privacy-First Architecture
160+
161+
**Critical**: All data processing happens client-side:
162+
- No backend API calls
163+
- No user authentication/tracking
164+
- All assessments stored in browser localStorage
165+
- No external analytics (except Next.js built-in)
166+
- PDF generation and sharing are client-side only
167+
168+
When adding features, maintain this privacy-first approach.
169+
170+
## Styling Conventions
171+
172+
- **Tailwind CSS** for utility-first styling
173+
- **shadcn/ui** for component primitives (never modify these directly)
174+
- **Framer Motion** for page transitions and animations
175+
- **Responsive design**: Mobile-first approach
176+
- **Dark mode**: Not currently implemented but Tailwind is configured for it
177+
178+
## Common Development Tasks
179+
180+
### Adding a New Assessment Question
181+
182+
1. Add question to `lib/assessment.ts:questions` array
183+
2. Ensure it uses `standardOptions`
184+
3. Assign to existing category or create new one
185+
4. Set appropriate weight (1.0-1.5)
186+
5. Update category descriptions if new category
187+
188+
### Modifying Scoring Algorithm
189+
190+
All scoring logic is in `lib/assessment.ts:calculateScores`. Consider:
191+
- Weighted vs unweighted scores
192+
- Category average calculations
193+
- Overall score aggregation
194+
- Impact on existing assessments
195+
196+
### Adding New Visualizations
197+
198+
Charts are built with Recharts/ApexCharts:
199+
- See `app/results/[id]/page.tsx` for radar chart implementation
200+
- See `components/ComparisonChart.tsx` for multi-assessment comparisons
201+
- Keep charts responsive and accessible
202+
203+
### Extending History Features
204+
205+
History store (`lib/history-store.ts`) supports:
206+
- Adding/removing assessments
207+
- Retrieving by ID
208+
- Clearing all history
209+
- Automatic 50-entry limit
210+
211+
## Scientific Accuracy
212+
213+
The assessment is based on psychological research. When modifying:
214+
- Maintain evidence-based question design
215+
- Preserve weighted scoring reflecting research importance
216+
- Keep 7-point Likert scale for statistical validity
217+
- Ensure health assessment thresholds are meaningful
218+
219+
## Performance Considerations
220+
221+
- Next.js automatic code splitting by route
222+
- Lazy load heavy components (charts, animations)
223+
- Optimize images with Next.js Image component
224+
- localStorage operations are synchronous - keep minimal
225+
- Zustand provides efficient re-renders
226+
227+
## Testing Assessment Flow
228+
229+
Manual testing checklist:
230+
1. Start assessment on `/assess`
231+
2. Answer all 20 questions
232+
3. Enter friend name and notes in dialog
233+
4. Verify score calculation
234+
5. Check localStorage persistence
235+
6. Test PDF export
236+
7. Verify history tracking
237+
8. Test comparison charts with multiple assessments
238+
239+
## Known Constraints
240+
241+
- Maximum 50 assessments in history (oldest auto-deleted)
242+
- localStorage size limits vary by browser (~5-10MB)
243+
- PDF generation is client-side only (limited styling)
244+
- No backend means no cross-device sync
245+
- Assessment questions are English-only
246+
247+
## Deployment
248+
249+
Project is configured for Vercel deployment:
250+
- No environment variables required
251+
- Automatic deployments on push to master
252+
- Edge runtime not used (client-side rendering)
253+
- No serverless functions needed

0 commit comments

Comments
 (0)