How jufaa/fitness-app-backend works
Project Type and Purpose
• This is a backend service (“fitness-app-backend”) implemented in Node.js/TypeScript.
• It exposes a RESTful API (Express) for managing users, exercises, muscles, routines, and routine‐exercise mappings in a fitness app.
• The architecture follows a Clean/Hexagonal style with distinct layers: presentation (controllers), application (use‐cases), domain (entities & interfaces), and infrastructure (ORM repositories, DB, middlewares).
File Structure Analysis
• Top-level config and tooling: package.json, tsconfig.json, eslint.config.mjs, jest.config.js, .prettierrc, .env.example.
• src/presentation: Express routers & controllers—entry point for HTTP requests.
• src/application/use-cases: Business logic organized by aggregate (users, exercises, routines, etc.).
• src/domain: Entities models and repository interfaces (IUserRepository, IExerciseRepository, etc.).
• src/infrastructure:
• database: Sequelize-based implementations of repository interfaces and DB sync scripts.
• middlewares: auth, role checking, logging (Morgan).
• schemas: request/response validation or ORM schemas.
• libs and utils: logger, JWT, config.
• src/shared: Shared TypeScript types and helpers (e.g., Express augmentation, JWT utilities).
• tests: Jest tests.
README Insights
• Minimal content (project name only), so rely on conventions and file structure to infer architecture.
a. Main Components
• Clients (Web/Mobile/UI)
• HTTP/API Layer: Express Server, Global Middlewares (authMiddleware, morganMiddleware, roleMiddleware)
• Presentation Layer: Routers → Controllers
• Application Layer: Use-Case Handlers (e.g., GetAllExerciseUseCase)
• Domain Layer: Entities (User, Exercise, Routine, etc.), Repository Interfaces
• Infrastructure Layer: Sequelize Repositories, Database (e.g., PostgreSQL/MySQL)
• Shared Services: Logger, JWT Service, Config Loader
• External Systems (optional): Auth provider or third-party logging/metrics
b. Relationships and Data Flow
1. Client → HTTP Request → Middleware chain (auth, logging)
2. Middleware → Route matching → Controller
3. Controller → Invoke Use Case in Application layer, passing DTOs
4. Use Case → Calls Repository Interface (e.g., IUserRepository)
5. Infrastructure Repository Implementation (Sequelize) → Queries Database → Returns Entities
6. Use Case → Domain Entities → Controller → HTTP Response
7. Shared JWT Utility for token generation/validation in authMiddleware
c. Architectural Patterns & Principles
• Clean/Hexagonal Architecture: clear separation of concerns, dependency inversion (application depends on repository interfaces, not implementations).
• Single Responsibility: each layer handles a distinct responsibility.
• Dependency Injection (through constructor injection in controllers/use-cases).
• Layered validation: request schemas in infrastructure/schemas.
d. Key Technologies & Frameworks
• Node.js, TypeScript, Express
• Sequelize ORM (SQL DB)
• Jest for testing
• Morgan for HTTP logging, custom logger (winston or similar)
• JWT for authentication
Detailed Elements
• Authentication flow: JWT validation in authMiddleware.
• Error or exception handling flow if relevant.
• Configuration loader (config.ts) feeding environment variables into DB connection and JWT secrets.