Skip to content

Commit 23c928d

Browse files
committed
docs: update CLAUDE.md with streamlined architecture docs
- Consolidate development commands section - Add package dependency diagram - Document complete auth API endpoints - Add auth flow file references - Streamline database models section - Remove redundant sections
1 parent e7b12a1 commit 23c928d

1 file changed

Lines changed: 90 additions & 171 deletions

File tree

CLAUDE.md

Lines changed: 90 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -4,189 +4,108 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
StudySync is an AI-powered educational platform built as a monorepo using Turborepo. It transforms passive note-taking into active learning through AI-generated flashcards, quizzes, and study guides.
8-
9-
## Repository Structure
10-
11-
This is a Turborepo monorepo with the following workspace structure:
12-
- `apps/web` - Next.js 14 frontend application (@studysync/web)
13-
- `apps/api` - Express.js backend API server (@studysync/api)
14-
- `packages/database` - Prisma ORM and database schema (@studysync/database)
15-
- `packages/auth` - Shared authentication logic with JWT (@studysync/auth)
16-
- `packages/ui` - Shared UI components (planned)
17-
- `packages/shared` - Shared utilities (planned)
7+
StudySync is an AI-powered educational platform that transforms passive note-taking into active learning through AI-generated flashcards, quizzes, and study guides. Built as a Turborepo monorepo.
188

199
## Development Commands
2010

21-
### Initial Setup
22-
```bash
23-
# Install dependencies
24-
npm install
25-
26-
# Setup environment
27-
cp .env.example .env
28-
# Edit .env with actual values
29-
30-
# Start Docker services
31-
docker-compose up -d
32-
33-
# Setup database
34-
npm run db:push # Push schema to database
35-
npm run db:generate # Generate Prisma client
36-
```
37-
38-
### Daily Development
3911
```bash
40-
# Start all development servers concurrently
12+
# Start all services (frontend + backend)
4113
npm run dev
4214

43-
# Individual app development
44-
npm run dev --workspace=@studysync/web # Frontend only
45-
npm run dev --workspace=@studysync/api # Backend only
46-
47-
# Database operations
48-
npm run db:studio # Open Prisma Studio GUI
49-
npm run db:migrate # Run migrations in dev
50-
npm run db:push # Push schema changes without migration
15+
# Run single workspace
16+
npm run dev --workspace=@studysync/web # Frontend on :3000
17+
npm run dev --workspace=@studysync/api # Backend on :3001
18+
19+
# Database (requires Docker services running first)
20+
docker-compose up -d # Start PostgreSQL, Redis, MinIO
21+
npm run db:push # Push schema changes
22+
npm run db:generate # Generate Prisma client
23+
npm run db:studio # Open Prisma GUI
24+
npm run db:migrate # Run migrations
25+
26+
# Testing and linting
27+
npm run lint # Lint all packages
28+
npm run test # Run all tests
29+
npm run test --workspace=@studysync/api # Test single package
30+
31+
# Build
32+
npm run build # Build all packages
33+
npm run clean # Remove build artifacts and node_modules
5134
```
5235

53-
### Building and Testing
54-
```bash
55-
# Build all packages
56-
npm run build
57-
58-
# Run all tests
59-
npm run test
60-
61-
# Lint all packages
62-
npm run lint
63-
64-
# Format code
65-
npm run format
36+
## Repository Structure
6637

67-
# Clean build artifacts
68-
npm run clean
38+
```
39+
apps/
40+
web/ # Next.js 14 frontend (@studysync/web) - src/app/ uses App Router
41+
api/ # Express.js backend (@studysync/api)
42+
packages/
43+
database/ # Prisma schema and client (@studysync/database)
44+
auth/ # JWT authentication logic (@studysync/auth)
45+
shared/ # Shared utilities (planned)
46+
ui/ # Shared UI components (planned)
6947
```
7048

71-
### Running Specific Commands
72-
```bash
73-
# Run command in specific workspace
74-
npm run <command> --workspace=@studysync/<package>
49+
## Architecture
7550

76-
# Example: Run tests only for API
77-
npm run test --workspace=@studysync/api
51+
### Package Dependencies
52+
```
53+
@studysync/web → (calls API endpoints)
54+
@studysync/api → @studysync/auth → @studysync/database
7855
```
79-
80-
## Architecture Overview
8156

8257
### Authentication Flow
83-
1. User credentials are validated using schemas in `packages/auth/src/index.ts`
84-
2. Passwords are hashed using bcrypt with salt rounds of 10
85-
3. JWT tokens are generated with 7-day expiration for access tokens
86-
4. Refresh tokens have 30-day expiration
87-
5. Session management includes user data and token expiry tracking
88-
89-
### Database Architecture
90-
- PostgreSQL as primary database with Prisma ORM
91-
- Redis for caching and rate limiting
92-
- MinIO (optional) for S3-compatible file storage in development
93-
94-
Key models and relationships:
95-
- `User` - Central user model with subscription tiers (FREE, PREMIUM, STUDENT_PLUS, UNIVERSITY)
96-
- `Upload` - File uploads with processing status (PENDING, PROCESSING, COMPLETED, FAILED)
97-
- `FlashcardSet` and `Flashcard` - Spaced repetition system with difficulty levels
98-
- `Quiz`, `Question`, `Answer` - Quiz system supporting multiple question types
99-
- `Note` and `NoteConnection` - Knowledge graph for concept relationships
100-
101-
### API Structure
102-
The Express API (`apps/api/src/index.ts`) implements:
103-
- Helmet for security headers
104-
- CORS with credential support
105-
- Rate limiting (100 requests per 15 minutes per IP)
106-
- Structured routes: `/api/auth`, `/api/content`, `/api/flashcards`, `/api/quizzes`
107-
108-
### Frontend Architecture
109-
Next.js 14 with App Router structure:
110-
- TypeScript for type safety
111-
- Tailwind CSS for styling
112-
- Server components by default
113-
- API calls to backend at `NEXT_PUBLIC_API_URL`
114-
115-
## Environment Configuration
116-
117-
Critical environment variables:
118-
- `DATABASE_URL` - PostgreSQL connection string
119-
- `JWT_SECRET` and `JWT_REFRESH_SECRET` - Authentication tokens
120-
- `OPENAI_API_KEY` - For AI features
121-
- `REDIS_URL` - Redis connection
122-
- `NEXT_PUBLIC_API_URL` - Backend API URL for frontend
123-
124-
Development defaults:
125-
- Frontend: http://localhost:3000
126-
- API: http://localhost:3001
127-
- PostgreSQL: localhost:5432
128-
- Redis: localhost:6379
129-
- MinIO Console: http://localhost:9001
130-
131-
## Turborepo Pipeline
132-
133-
The build pipeline (`turbo.json`) defines task dependencies:
134-
- `build` depends on upstream builds (`^build`)
135-
- `dev` runs persistently without caching
136-
- `test` and `lint` depend on upstream tasks
137-
- Environment variables are properly passed to build tasks
138-
139-
## Key Technical Decisions
140-
141-
1. **Monorepo with Turborepo**: Enables code sharing and coordinated deployments
142-
2. **Prisma ORM**: Type-safe database access with migrations
143-
3. **JWT Authentication**: Stateless auth with refresh token rotation
144-
4. **Express + TypeScript**: Type-safe backend with familiar Node.js patterns
145-
5. **Next.js 14 App Router**: Latest React patterns with server components
146-
6. **PostgreSQL + Redis**: Relational data with caching layer
147-
148-
## AI Integration Points
149-
150-
The codebase is prepared for AI features:
151-
- OpenAI SDK configured in API dependencies
152-
- LangChain for AI orchestration
153-
- Content processing pipeline in `Upload` model
154-
- Vector database support planned for semantic search
155-
156-
## Common Development Patterns
157-
158-
### Adding New API Routes
159-
1. Create route handler in `apps/api/src/routes/`
160-
2. Add validation schemas using Zod
161-
3. Implement business logic with Prisma client
162-
4. Add rate limiting if needed
163-
5. Update CORS settings if required
164-
165-
### Database Schema Changes
166-
1. Modify `packages/database/prisma/schema.prisma`
167-
2. Run `npm run db:migrate` to create migration
168-
3. Run `npm run db:generate` to update client
169-
4. Update dependent packages as needed
170-
171-
### Adding Shared Packages
172-
1. Create new directory in `packages/`
173-
2. Add package.json with `@studysync/` namespace
174-
3. Update root `package.json` workspaces if needed
175-
4. Configure TypeScript with proper build output
176-
177-
## Current Implementation Status
178-
179-
Completed (SSC-5):
180-
- Project architecture and setup
181-
- Database schema design
182-
- Authentication package structure
183-
- Basic API structure
184-
- Frontend scaffolding
185-
- CI/CD pipeline configuration
186-
187-
Pending (from Linear roadmap):
188-
- SSC-10: User Authentication implementation
189-
- SSC-6: Content Upload system
190-
- SSC-7: AI Flashcard generation
191-
- SSC-8: Quiz system
192-
- SSC-9: Core UI/UX implementation
58+
1. `packages/auth/src/index.ts` - Validation schemas (Zod), password hashing (bcrypt), JWT utilities
59+
2. `apps/api/src/routes/auth.routes.ts` - Auth endpoints with stricter rate limiting (10 req/15min)
60+
3. `apps/api/src/middleware/auth.middleware.ts` - `authenticateToken`, `optionalAuth`, `requireSubscription` middleware
61+
4. `apps/api/src/controllers/auth.controller.ts` - Full auth implementation
62+
63+
Token expiration: Access 7 days, Refresh 30 days. Sessions stored in database.
64+
65+
### Auth API Endpoints
66+
- `POST /api/auth/register` - User registration
67+
- `POST /api/auth/login` - Login with email/password
68+
- `POST /api/auth/refresh` - Refresh access token
69+
- `POST /api/auth/logout` - Invalidate session (protected)
70+
- `GET /api/auth/me` - Get current user (protected)
71+
- `PUT /api/auth/me` - Update profile (protected)
72+
- `PUT /api/auth/me/password` - Change password (protected)
73+
- `DELETE /api/auth/me` - Delete account (protected)
74+
- `POST /api/auth/forgot-password` - Request password reset
75+
- `POST /api/auth/reset-password` - Reset with token
76+
- `GET /api/auth/verify-email/:token` - Email verification
77+
78+
### Database Models
79+
Key models in `packages/database/prisma/schema.prisma`:
80+
- `User` - Subscription tiers: FREE, PREMIUM, STUDENT_PLUS, UNIVERSITY
81+
- `Session` - JWT refresh tokens and verification tokens
82+
- `Upload` - Processing status: PENDING → PROCESSING → COMPLETED/FAILED
83+
- `FlashcardSet`/`Flashcard` - Spaced repetition with EASY/MEDIUM/HARD difficulty
84+
- `Quiz`/`Question`/`Answer` - Types: MULTIPLE_CHOICE, TRUE_FALSE, SHORT_ANSWER, ESSAY
85+
- `Note`/`NoteConnection` - Knowledge graph for concept relationships
86+
87+
### Request Validation
88+
All inputs validated with Zod schemas. Auth schemas exported from `@studysync/auth`.
89+
90+
## Environment Variables
91+
92+
Required (see `.env.example`):
93+
- `DATABASE_URL` - PostgreSQL connection
94+
- `JWT_SECRET` / `JWT_REFRESH_SECRET` - Auth tokens
95+
- `REDIS_URL` - Caching
96+
- `OPENAI_API_KEY` - AI features
97+
98+
Ports: Frontend :3000, API :3001, PostgreSQL :5432, Redis :6379, MinIO :9001
99+
100+
## CI/CD
101+
102+
GitHub Actions (`.github/workflows/ci.yml`):
103+
1. Lint → 2. Tests (with PostgreSQL) → 3. Build → 4. Security scan
104+
- PRs: Deploy preview
105+
- Main branch: Deploy production
106+
107+
## Docker
108+
109+
`docker-compose.yml` provides PostgreSQL 15, Redis 7, MinIO (S3-compatible storage).
110+
111+
API Dockerfile uses multi-stage build with non-root user.

0 commit comments

Comments
 (0)