A comprehensive workout tracking backend API built with NestJS, designed to provide robust data management and authentication for fitness applications.
- JWT Authentication: Secure token-based authentication system
- User Registration: Complete user registration with email confirmation
- Password Security: Bcrypt password hashing for secure storage
- Email Verification: SendGrid integration for email confirmation
- User Profiles: Comprehensive user profile management with personal data
- Workout Sets: Create and manage custom workout routines
- Exercise Library: Comprehensive exercise database with muscle group categorization
- Workout Logging: Track daily workout sessions and progress
- Muscle Groups: Organize exercises by muscle groups for better categorization
- Workout History: Complete workout session tracking and analytics
- Weight Logging: Record and track weight measurements over time
- Progress Analytics: Data aggregation for weight progression analysis
- User Metrics: Track height, birth date, and other personal metrics
- Historical Data: Complete weight history with timestamps
- PostgreSQL Integration: Robust database with TypeORM
- Database Migrations: Version-controlled database schema management
- Entity Relationships: Well-structured data models with proper relationships
- Data Validation: Class-validator integration for input validation
- Framework: NestJS 11.x with TypeScript
- Database: PostgreSQL with TypeORM
- Authentication: JWT with Passport.js
- Email Service: SendGrid for email notifications
- Password Hashing: Bcrypt for secure password storage
- Validation: Class-validator and class-transformer
- Testing: Jest for unit and e2e testing
- Code Quality: ESLint and Prettier
-
Clone the repository
git clone <repository-url> cd tracking-my-workout-nest
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env # Configure your environment variables: # - DATABASE_URL # - JWT_SECRET # - SENDGRID_API_KEY # - PORT
-
Set up the database
# Run database migrations npm run migration:run -
Start the development server
npm run start:dev
-
API will be available at Navigate to http://localhost:3000
src/
βββ auth/ # Authentication module
β βββ auth.controller.ts # Auth endpoints
β βββ auth.service.ts # Auth business logic
β βββ jwt.strategy.ts # JWT strategy
β βββ jwt-auth.guard.ts # JWT guard
βββ users/ # User management
β βββ users.controller.ts # User endpoints
β βββ users.service.ts # User business logic
β βββ user.entity.ts # User data model
β βββ dtos/ # Data transfer objects
βββ exercises/ # Exercise management
β βββ exercises.controller.ts
β βββ exercises.service.ts
β βββ entities/
βββ muscles/ # Muscle group management
β βββ muscles.controller.ts
β βββ muscles.service.ts
β βββ entities/
βββ workouts/ # Workout management
β βββ workouts.controller.ts
β βββ workouts.service.ts
β βββ entities/
βββ workoutSets/ # Workout set management
β βββ workoutsets.controller.ts
β βββ workoutsets.service.ts
β βββ entities/
βββ workout-log/ # Workout logging
β βββ workout-log.controller.ts
β βββ workout-log.service.ts
β βββ entities/
βββ weight/ # Weight tracking
β βββ weight.controller.ts
β βββ weight.service.ts
β βββ entities/
βββ common/ # Shared utilities
β βββ middleware/ # Custom middleware
β βββ helpers/ # Helper functions
β βββ providers/ # Shared providers
βββ config/ # Configuration files
β βββ typeorm.config.ts # Database configuration
βββ migrations/ # Database migrations
POST /auth/register- User registrationPOST /auth/login- User loginPOST /auth/confirm-email- Email confirmationPOST /auth/resend-confirmation- Resend confirmation email
GET /users/profile- Get user profilePUT /users/profile- Update user profilePOST /users/finish-registration- Complete user registration
GET /exercises- Get all exercisesPOST /exercises- Create new exercisePUT /exercises/:id- Update exerciseDELETE /exercises/:id- Delete exercise
GET /workouts- Get user workoutsPOST /workouts- Create new workoutPUT /workouts/:id- Update workoutDELETE /workouts/:id- Delete workout
GET /workout-sets- Get user workout setsPOST /workout-sets- Create workout setPUT /workout-sets/:id- Update workout setDELETE /workout-sets/:id- Delete workout set
GET /weight- Get weight historyPOST /weight- Log new weightPUT /weight/:id- Update weight entryDELETE /weight/:id- Delete weight entry
GET /workout-log- Get workout historyPOST /workout-log- Log workout sessionPUT /workout-log/:id- Update workout logDELETE /workout-log/:id- Delete workout log
- User: User profiles with authentication data
- Exercise: Exercise library with muscle group associations
- Muscle: Muscle group definitions
- Workout: Individual workout sessions
- WorkoutSet: Collections of workouts
- WorkoutLog: Daily workout session logs
- Weight: Weight tracking entries
- User β WorkoutSets (One-to-Many)
- User β Weight (One-to-Many)
- WorkoutSet β Workouts (One-to-Many)
- Workout β Exercises (One-to-Many)
- Exercise β Muscles (Many-to-Many)
- Set up the database with PostgreSQL
- Configure environment variables for database and services
- Run database migrations to create tables
- Start the development server
- Register a new user via the API
- Create your first workout set with exercises
- Start logging workouts and tracking progress
npm run start- Start the applicationnpm run start:dev- Start in development mode with hot reloadnpm run start:debug- Start in debug modenpm run build- Build the applicationnpm run test- Run unit testsnpm run test:e2e- Run e2e testsnpm run test:cov- Run tests with coveragenpm run lint- Run ESLintnpm run format- Format code with Prettier
npm run migration:generate- Generate new migrationnpm run migration:run- Run pending migrationsnpm run migration:revert- Revert last migration
- TypeScript: Full type safety throughout the application
- ESLint: Code linting and style enforcement
- Prettier: Consistent code formatting
- Jest: Comprehensive testing framework
- Class-validator: Input validation and sanitization
- JWT-based authentication with secure token management
- Email confirmation system with SendGrid integration
- Password hashing with bcrypt for security
- Protected routes with JWT guards
- Complete workout set creation and management
- Exercise library with muscle group categorization
- Workout session logging and tracking
- Historical workout data analysis
- Comprehensive input validation with class-validator
- DTOs for all API endpoints
- Type-safe data transfer objects
- Automatic validation error handling
- Well-structured entity relationships
- Proper indexing for performance
- Migration-based schema management
- Support for both development and production environments
- JWT token authentication
- Password hashing with bcrypt
- CORS configuration for frontend integration
- Input validation and sanitization
- SQL injection protection through TypeORM
- Database connection pooling
- Efficient query optimization
- Proper indexing strategy
- Migration-based schema updates
- Production-ready configuration
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with NestJS
- Database powered by TypeORM
- Authentication with Passport.js
- Email service by SendGrid
Power your fitness tracking application with a robust backend! πͺ