4.8 KiB
4.8 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Development Commands
Core Development
yarn start:dev- Start development server with hot reloadyarn start:debug- Start development server with debugging enabledyarn build- Build production bundleyarn start:prod- Start production server from built files
Testing
yarn test- Run unit testsyarn test:watch- Run tests in watch modeyarn test:cov- Run tests with coverage reportyarn test:e2e- Run end-to-end testsyarn test:debug- Run tests with debugging
Code Quality
yarn lint- Run ESLint with auto-fixyarn format- Format code with Prettier
Production Deployment
yarn pm2:start- Start with PM2 in production modeyarn pm2:start:dev- Start with PM2 in development modeyarn pm2:status- Check PM2 process statusyarn pm2:logs- View PM2 logsyarn pm2:restart- Restart PM2 processes
Deployment Scripts
./deploy-optimized.sh- Recommended deployment (builds on server)./deploy.sh- Full deployment with options (--helpfor usage)./deploy-simple.sh- Basic deployment script
Architecture Overview
Core Framework
This is a NestJS-based fitness and health tracking API using TypeScript, MySQL with Sequelize ORM, and JWT authentication. The architecture follows NestJS conventions with modular design.
Module Structure
The application is organized into domain-specific modules:
Health & Fitness Core:
users/- User management, authentication (Apple Sign-In, guest), payments, subscriptionsdiet-records/- Food logging and nutrition tracking integrationfood-library/- Food database with categories and nutritional informationexercises/- Exercise library with categories and instructionstraining-plans/- Workout plan management and schedulingworkouts/- Workout session tracking and historygoals/- Goal setting with task management systemmood-checkins/- Mental health and mood tracking
AI & Intelligence:
ai-coach/- OpenAI-powered fitness coaching with diet analysisrecommendations/- Personalized content recommendation engine
Content & Social:
articles/- Health and fitness article managementcheckins/- User check-in and progress trackingactivity-logs/- User activity and engagement tracking
Key Architectural Patterns
Database Layer:
- Sequelize ORM with MySQL
- Models use
@Tableand@Columndecorators fromsequelize-typescript - Database configuration in
database.module.tswith async factory pattern - Auto-loading models with
autoLoadModels: true
Authentication & Security:
- JWT-based authentication with refresh tokens
- Apple Sign-In integration via
apple-auth.service.ts - AES-256-GCM encryption service for sensitive data
- Custom
@CurrentUser()decorator andJwtAuthGuard
API Design:
- Controllers use Swagger decorators for API documentation
- DTOs for request/response validation using
class-validator - Base DTO pattern in
base.dto.tsfor consistent responses - Encryption support for sensitive endpoints
Logging & Monitoring:
- Winston logging with daily rotation
- Separate log files: app, error, debug, exceptions, rejections
- PM2 clustering with memory limits (1GB)
- Structured logging with context and metadata
Configuration Management
- Environment-based configuration using
@nestjs/config - Global configuration module
- Environment variables for database, JWT, Apple auth, encryption keys
- Production/development environment separation
External Integrations
- OpenAI: AI coaching and diet analysis
- Apple: Sign-in and purchase verification
- RevenueCat: Subscription management webhooks
- Tencent Cloud COS: File storage service
Testing Strategy
- Unit tests with Jest (
*.spec.tsfiles) - E2E tests in
test/directory - Test configuration in
package.jsonjest section - Encryption service has comprehensive test coverage
Development Patterns
- Each module follows NestJS structure: controller → service → model
- Services are injected using
@Injectable()decorator - Models are Sequelize entities with TypeScript decorators
- DTOs handle validation and transformation
- Guards handle authentication and authorization
Database Schema Patterns
SQL scripts in sql-scripts/ directory contain table creation scripts organized by feature:
*-tables-create.sqlfor table definitions*-sample-data.sqlfor seed data- Migration scripts for database upgrades
Production Environment
- Server: 129.204.155.94
- Deployment Path:
/usr/local/web/pilates-server - Ports: 3002 (production), 3001 (development)
- Process Management: PM2 with cluster mode
- Logging: Daily rotated logs in
logs/directory