# mhamednasser/nutrix architecture

> Architecture diagram of the GitHub repository mhamednasser/nutrix, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mhamednasser/nutrix
- Repository: https://github.com/mhamednasser/nutrix

## Overview

##### Project Type and Purpose
- Nutrix is a **backend Web API** (ASP.NET Core / .NET 8) that powers an AI-driven fitness & nutrition platform.
- It exposes REST endpoints for authentication, user management, workouts, meal logging, AI-powered plan generation, analytics, and more.
- It uses Entity Framework Core with SQL Server (or PostgreSQL), integrates Google Gemini AI, supports JWT & OAuth, and is containerized via Docker.

##### File Structure
- Top-level:
- graduationProject.sln | solution file
- graduationProject/Program.cs, launchSettings.json | ASP.NET Core startup
- Controllers/ | HTTP API layer
- Services/, Repositories/, Interfaces/ | Business logic & data layer
- Models/, Data/, Migrations/ | EF Core data model & seed data
- Configurations/ | strongly-typed settings (JWT, Database, Email, Gemini, OAuth)
- DTOs/ | request/response definitions
- Extensions/ | controller or service extension methods
- Dockerfile, docker-compose.yml | container setup
- Architectural patterns:
- Layered (API → Services → Repositories → Database)
- Dependency Injection (Interfaces + Services)
- Configuration separation (Settings classes)
- External integrations visible in code:
- Google Gemini AI + ChatBotService + PythonApiService
- EmailService (SMTP/Gmail)
- JwtService + GoogleAuthSettings
- Logging / Health Checks via built-in ASP.NET features

##### Extract Additional Insights from README
- Confirms tech stack: .NET 8, ASP.NET Core, EF Core, SQL Server, Docker, Google Gemini AI
- Highlights containerization (Docker Compose) for API + database
- Specifies key external dependencies: OAuth 2.0, SMTP, Gemini AI, cloud deployment options

##### Main Components
a. API Layer
- Controllers: AuthController, UserController, ExercisesController, AI-Controllers (Chat, Plan), etc.
- Swagger UI & Health-check endpoints
b. Business Logic Layer
- Services: ChallengeService, PlanGenerationService (and mock), ChatBotService, EmailService, JwtService, PythonApiService
- Interfaces for each service
c. Data Access Layer
- Repositories (GeneralPlanRepository, others)
- EF Core Migrations & AppDbContext → SQL Server database
d. External Services
- Google Gemini AI (Meal-Plan, Workout, Chat)
- Email (SMTP / third-party email provider)
- Google OAuth 2.0 for social login
e. Infrastructure / DevOps
- Docker container for API
- Docker container for SQL Server
- Docker Compose orchestration
- Environment configuration (.env, appsettings)
- Cloud targets (Azure/AWS/GCP)

##### Relationships & Data Flow
- User (Mobile/Web) → HTTPS request → API Gateway (ASP.NET Core)
- API Layer → AuthService (JWT validation, OAuth handshake)
- On protected endpoints → Services invoked → Repositories → Database
- AI endpoints → ChatBotService / PlanGenerationService → Google Gemini AI (external HTTP)
- PythonApiService (if external Python microservice exists)
- EmailService → SMTP provider
- Data flow returns through Service → Controller → HTTP response → User
- Container orchestration ensures isolation between API & DB

##### Architectural Patterns & Design Principles
- Layered architecture with clear separation of concerns
- Dependency Injection for testability and extensibility
- Repository pattern + Unit of Work (via DbContext)
- Configuration via strongly-typed settings
- DTO pattern for request/response contracts
- Multi-stage Docker builds for lean production images
- Health checks & structured logging for operations

##### Step-by-Step Creation
1. Sketch the **edge components** (Clients, External services)
2. Layer in **API → Services → Data** blocks
4. Encapsulate API + DB in **Docker Compose boundary**

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients"
        direction TB
        WebApp["Web App"]:::external
        MobileApp["Mobile App"]:::external
        SwaggerUI["Swagger UI"]:::external
    end

    %% Docker Compose Boundary
    subgraph "Docker Compose" 
        direction TB
        %% API Layer
        subgraph "API Layer"
            direction TB
            AuthController["AuthController"]:::backend
            UserController["UserController"]:::backend
            ExercisesController["ExercisesController"]:::backend
            ChatController["ChatController"]:::backend
            PlanController["PlanController"]:::backend
            GeneralPlansController["GeneralPlansController"]:::backend
            ChallengeController["ChallengeController"]:::backend
            FoodDetectionController["FoodDetectionController"]:::backend
            MuscleGroupsController["MuscleGroupsController"]:::backend
            ProfileController["ProfileController"]:::backend
            WeatherForecastController["WeatherForecastController"]:::backend
        end

        %% Service Layer
        subgraph "Service Layer"
            direction TB
            ChallengeService["ChallengeService"]:::service
            PlanGenerationService["PlanGenerationService"]:::service
            PlanGenerationMockService["PlanGenerationMockService"]:::service
            ChatBotService["ChatBotService"]:::service
            EmailService["EmailService"]:::service
            JwtService["JwtService"]:::service
            PythonApiService["PythonApiService"]:::service
            GeminiService["GeminiService"]:::service
            GeminiPlanService["GeminiPlanService"]:::service
            GeneralPlanService["GeneralPlanService"]:::service
        end

        %% Data Layer
        subgraph "Data Layer"
            direction TB
            GeneralPlanRepository["GeneralPlanRepository"]:::repository
            AppDbContext["AppDbContext"]:::repository
            EFCoreMigrations["EF Core Migrations"]:::repository
            DietPlanSeedData["DietPlanSeedData"]:::repository
            WorkoutPlanSeedData["WorkoutPlanSeedData"]:::repository
        end

        %% Database
        SQLServer["SQL Server"]:::db
    end

    %% External Services
    GoogleGemini["Google Gemini AI"]:::external
    SMTP["SMTP Email Provider"]:::external
    GoogleOAuth["Google OAuth 2.0"]:::external

    %% Connections
    WebApp -->|HTTPS| AuthController
    MobileApp -->|HTTPS| AuthController
    SwaggerUI -->|HTTPS| AuthController

    %% API to Services
    AuthController -->|calls| JwtService
    AuthController -->|calls| EmailService
    UserController -->|uses| GeneralPlanService
    ExercisesController -->|uses| GeneralPlanService
    ChatController -->|uses| ChatBotService
    PlanController -->|uses| PlanGenerationService
    GeneralPlansController -->|uses| GeneralPlanService
    ChallengeController -->|uses| ChallengeService
    FoodDetectionController -->|uses| PythonApiService
    MuscleGroupsController -->|uses| GeneralPlanService
    ProfileController -->|uses| GeneralPlanService
    WeatherForecastController -->|uses| PlanGenerationService

    %% Service to Data
    GeneralPlanService -->|CRUD| GeneralPlanRepository
    ChallengeService -->|CRUD| GeneralPlanRepository
    PlanGenerationService -->|reads| AppDbContext
    ChatBotService -->|reads| AppDbContext
    EmailService -->|reads| AppDbContext

    %% Data to DB
    GeneralPlanRepository -->|EF Core| SQLServer
    AppDbContext -->|EF Core| SQLServer
    EFCoreMigrations -->|migrates| SQLServer
    DietPlanSeedData -->|seeds| SQLServer
    WorkoutPlanSeedData -->|seeds| SQLServer

    %% Service to External
    ChatBotService -->|gRPC/HTTP| GoogleGemini
    PlanGenerationService -->|gRPC/HTTP| GoogleGemini
    GeminiService -->|HTTP| GoogleGemini
    GeminiPlanService -->|HTTP| GoogleGemini
    EmailService -->|SMTP| SMTP
    JwtService -->|OAuth flow| GoogleOAuth

    %% Docker Compose isolation
    DockerComposeBoundary(( )):::external
    DockerComposeBoundary --- DockerComposeBoundary

    %% Click Events - Controllers
    click AuthController "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Controllers/AuthController.cs"
    click UserController "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Controllers/UserController.cs"
    click ExercisesController "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Controllers/ExercisesController.cs"
    click ChatController "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Controllers/ChatController.cs"
    click PlanController "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Controllers/PlanController.cs"
    click GeneralPlansController "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Controllers/GeneralPlansController.cs"
    click ChallengeController "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Controllers/ChallengeController.cs"
    click FoodDetectionController "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Controllers/FoodDetectionController.cs"
    click MuscleGroupsController "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Controllers/MuscleGroupsController.cs"
    click ProfileController "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Controllers/ProfileController.cs"
    click WeatherForecastController "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Controllers/WeatherForecastController.cs"

    %% Click Events - Services
    click ChallengeService "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Services/ChallengeService.cs"
    click PlanGenerationService "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Services/PlanGenerationService.cs"
    click PlanGenerationMockService "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Services/PlanGenerationMockService.cs"
    click ChatBotService "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Services/ChatBotService.cs"
    click EmailService "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Services/EmailService.cs"
    click JwtService "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Services/JwtService.cs"
    click PythonApiService "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Services/PythonApiService.cs"
    click GeminiService "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Services/GeminiService.cs"
    click GeminiPlanService "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Services/GeminiPlanService.cs"
    click GeneralPlanService "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Services/GeneralPlanService.cs"

    %% Click Events - Data Layer
    click GeneralPlanRepository "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Repositories/GeneralPlanRepository.cs"
    click AppDbContext "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Models/AppDbContext.cs"
    click EFCoreMigrations "https://github.com/mhamednasser/nutrix/tree/main/graduationProject/Migrations/"
    click DietPlanSeedData "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Data/DietPlanSeedData.cs"
    click WorkoutPlanSeedData "https://github.com/mhamednasser/nutrix/blob/main/graduationProject/Data/WorkoutPlanSeedData.cs"

    %% Styles
    classDef backend fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1;
    classDef service fill:#C8E6C9,stroke:#2E7D32,color:#2E7D32;
    classDef repository fill:#FFE0B2,stroke:#EF6C00,color:#E65100;
    classDef db fill:#E1BEE7,stroke:#6A1B9A,color:#4A148C,stroke-width:2px;
    classDef external fill:#CFD8DC,stroke:#455A64,color:#37474F,stroke-dasharray: 5 5;
```
