How georgesklavos/personal-trainer-server2 works
Project type and purpose
• This is a NestJS–TypeScript monolithic REST API backend for a fitness/training management system.
• It exposes endpoints for user/admin/client/trainer workflows, handles authentication/authorization (JWT & local), sends e-mails, processes payments, and persists data via TypeORM.
File structure
• Top-level files: nest-cli.json, ormconfig.ts (TypeORM config), package.json, tsconfig.json.
• src/ is organized into feature folders (auth, users, clients, trainers, payments, email, messages, etc.), each with its own module, controller, service, DTOs, and specs.
• Cross-cutting concerns: src/guards (role-based authorization), src/pipes (DTO validation), src/filters (exception handling), src/middleware (request logging), migrations/ & seeds/ (DB schema and initial data).
• Entities directory holds all TypeORM @Entity definitions that map to database tables.
Inspect README for insights
• Confirms standard NestJS starter with a modular structure.
Main components
a. API Gateway / HTTP Server
– NestJS application bootstrap (main.ts + app.module).
– Middleware → Pipes → Guards → Controllers.
b. Authentication subsystem
– local.strategy, jwt.strategy, local-auth.guard, jwt-auth.guard.
– DTOs for login and user info.
– User-management: users, auth, roles, login-information, reset-password.
– Client workflows: clients, days, macros, exercises, how-you-feel.
– Trainer workflows: trainers, programs, videos.
– Admin & support: admin, support, mutual.
– Communication: email (templates + SMTP), messages (chat DTOs).
– Payments: payments + verifyPayment DTO.
– Translations & helper data: translations, helper-tables.
d. Data layer
– TypeORM Repositories under the hood of each service.
– Database server (e.g., PostgreSQL) hosting all entities.
– Migrations and seed scripts.
e. External services
– Email provider (SMTP or API).
– Payment gateway (e.g., Stripe).
– Potential push notifications / chat service if applicable.
Relationships and interactions
– Client (mobile/web) → HTTP → NestJS HTTP server.
– HTTP server processing chain: Middleware → Pipe → Guard → Controller → Service → TypeORM Repository → DB.
– Services → external calls (SMTP, payment API).
– Auth module issuing JWTs consumed by Guards in other modules.
• Inter-module service injections (e.g., auth.service used by users.service).
Architectural patterns & design principles
• Modular decomposition: each feature is a Nest module.
• Layered architecture: Controllers (API), Services (business logic), Repositories (data access).
• Dependency Injection for loose coupling.
• DTO + Pipes for input validation.
• Guards for authorization.
• Exception Filters for error handling.
• Use of migrations and seeders for schema and initial data.