# baptistelecat/dhomotic-api architecture

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

- Interactive diagram: https://gitdiagram.com/baptistelecat/dhomotic-api
- Repository: https://github.com/baptistelecat/dhomotic-api

## Overview

##### Main Components Identification
a. API Gateway/Controller Layer: Represent the controller endpoints (e.g., weekplan controllers) that route incoming HTTP requests.
b. Core Modules: Zoom into each domain module:
- Auth Module: Contains strategies (API key, JWT), guards, entities (auth-user), and services (auth and firebase auth). It handles user authentication and authorization.
- Meal Module: Manages meal entities and associated converters and services to transform and manipulate meal data.
- ProductItem Module: Manages product item entities, converters, and services related to product items.
- User Module: Handles user entities (user, nestedUser), converters, and related business logic.
- Weekplan Module: This module is a bit more extensive. It contains controllers for weekplan endpoints; converters (for menu, menuMeal, cartProduct, cartProductItem, weekplan); DTOs for data transfer and validation; entities for representing weekplan and its components; and corresponding services to execute business logic.
c. Infrastructure/Providers: The Firebase provider used to connect, authenticate, and manage interactions with Firebase services (FireStore, auth, etc.).
d. External Interfaces: Include connections to Firebase (both export/import paths for authentication and Firestore data) and any deployment pipelines (Dockerfile, CI/CD workflow integrations).

##### Relationships and Interactions
a. Central NestJS application where the app.module.ts bundles and integrates all modules.
c. Internal data flow within each module, such as:
- The Auth module using guards, strategies, and services to validate user credentials.
- The Weekplan module’s controller calling its service, which internally uses converters to translate DTOs into entity representations and vice versa.
d. Interactions with Firebase for authentication and persistence layers.
e. Link external CI/CD components and deployment (aligned with GitHub workflows and Docker configuration) as separate infrastructure nodes that interact with repository updates.

##### Architectural Patterns and Design Principles
a. Modular Design: Clearly indicate that each domain (auth, meal, productItem, user, weekplan) is self-contained with its own controllers, services, entities, and converters.
b. Clean Separation of Concerns: For example, converters transform data between representations, while services encapsulate business logic.
c. Use of Dependency Injection: NestJS modules integration manages dependencies across modules.
d. External API Integration: Emphasize Firebase integration as a key external service.

## Diagram (Mermaid)

```mermaid
graph TD
    NJApp["NestJS Application (app.module)"]:::external
    APIGateway["API Gateway/Controllers"]:::external
    NJApp --> APIGateway

    CICD["GitHub Workflows (CI/CD)"]:::external
    Docker["Docker Deployment"]:::external
    CICD --> NJApp
    Docker --> NJApp

    FirebaseProvider["Firebase Provider"]:::external

    %% API Gateway directs incoming requests to Weekplan Controller
    APIGateway --> WeekplanControllerDetail["Weekplan Controller"]:::controller

    %% Weekplan Module Subgraph
    subgraph "Weekplan Module"
        WeekplanModuleHeader["Weekplan Module"]:::moduleHeader
        WeekplanControllerDetailInside["Weekplan Controller"]:::controller
        WeekplanService["Weekplan Service"]:::service
        CreateWeekplanDTO["Create Weekplan DTO"]:::dto
        AddOrUpdateCartProductDTO["AddOrUpdate CartProduct DTO"]:::dto
        CreateMenuMealDTO["Create MenuMeal DTO"]:::dto
        WeekplanConverter["Weekplan Converter"]:::converter
        MenuConverter["Menu Converter"]:::converter
        MenuMealConverter["MenuMeal Converter"]:::converter
        CartProductConverter["CartProduct Converter"]:::converter
        CartProductItemConverter["CartProductItem Converter"]:::converter
        WeekplanEntity["Weekplan Entity"]:::entity
        MenuEntity["Menu Entity"]:::entity
        MenuMealEntity["MenuMeal Entity"]:::entity
        CartProductEntity["CartProduct Entity"]:::entity
        CartProductItemEntity["CartProductItem Entity"]:::entity

        WeekplanModuleHeader --> WeekplanControllerDetailInside
        WeekplanControllerDetailInside --> CreateWeekplanDTO
        WeekplanControllerDetailInside --> AddOrUpdateCartProductDTO
        WeekplanControllerDetailInside --> CreateMenuMealDTO
        WeekplanControllerDetailInside --> WeekplanService
        WeekplanService --> WeekplanConverter
        WeekplanConverter --> WeekplanEntity
        WeekplanService --> MenuConverter
        MenuConverter --> MenuEntity
        WeekplanService --> MenuMealConverter
        MenuMealConverter --> MenuMealEntity
        WeekplanService --> CartProductConverter
        CartProductConverter --> CartProductEntity
        CartProductEntity --> CartProductItemConverter
        CartProductItemConverter --> CartProductItemEntity

        %% Weekplan Service interacts with Firebase
        WeekplanService --> FirebaseProvider
    end

    %% Auth Module Subgraph
    subgraph "Auth Module"
        AuthModuleHeader["Auth Module"]:::moduleHeader
        APIKeyGuard["API Key Guard"]:::guard
        FirebaseThrottlerGuard["Firebase Throttler Guard"]:::guard
        JWTGuard["JWT Guard"]:::guard
        APIKeyStrategy["API Key Strategy"]:::strategy
        JWTStrategy["JWT Strategy"]:::strategy
        AuthService["Auth Service"]:::service
        FirebaseAuthService["Firebase Auth Service"]:::service
        AuthUserEntity["Auth-User Entity"]:::entity

        AuthModuleHeader --> APIKeyGuard
        AuthModuleHeader --> FirebaseThrottlerGuard
        AuthModuleHeader --> JWTGuard
        AuthModuleHeader --> APIKeyStrategy
        AuthModuleHeader --> JWTStrategy
        APIKeyGuard --> AuthService
        FirebaseThrottlerGuard --> AuthService
        JWTGuard --> AuthService
        APIKeyStrategy --> AuthService
        JWTStrategy --> AuthService
        AuthService --> FirebaseAuthService
        AuthService --> AuthUserEntity

        %% Auth Service interacts with Firebase
        AuthService --> FirebaseProvider
    end

    %% Meal Module Subgraph
    subgraph "Meal Module"
        MealModuleHeader["Meal Module"]:::moduleHeader
        MealService["Meal Service"]:::service
        MealEntity["Meal Entity"]:::entity
        MealConverter["Meal Converter"]:::converter
        MealProductConverter["Meal Product Converter"]:::converter
        MealProductItemConverter["Meal Product Item Converter"]:::converter

        MealModuleHeader --> MealService
        MealService --> MealConverter
        MealConverter --> MealEntity
        MealService --> MealProductConverter
        MealService --> MealProductItemConverter

        %% Meal Service interacts with Firebase
        MealService --> FirebaseProvider
    end

    %% ProductItem Module Subgraph
    subgraph "ProductItem Module"
        ProductItemModuleHeader["ProductItem Module"]:::moduleHeader
        ProductItemService["ProductItem Service"]:::service
        ProductItemEntity["ProductItem Entity"]:::entity
        ProductItemConverter["ProductItem Converter"]:::converter

        ProductItemModuleHeader --> ProductItemService
        ProductItemService --> ProductItemConverter
        ProductItemConverter --> ProductItemEntity

        %% ProductItem Service interacts with Firebase
        ProductItemService --> FirebaseProvider
    end

    %% User Module Subgraph
    subgraph "User Module"
        UserModuleHeader["User Module"]:::moduleHeader
        UserService["User Service"]:::service
        UserEntity["User Entity"]:::entity
        NestedUserEntity["Nested User Entity"]:::entity
        UserConverter["User Converter"]:::converter
        NestedUserConverter["NestedUser Converter"]:::converter

        UserModuleHeader --> UserService
        UserService --> UserConverter
        UserService --> NestedUserConverter
        UserConverter --> UserEntity
        NestedUserConverter --> NestedUserEntity

        %% User Service interacts with Firebase
        UserService --> FirebaseProvider
    end

    %% Connect NestJS Application to all Module Headers
    NJApp --> AuthModuleHeader
    NJApp --> MealModuleHeader
    NJApp --> ProductItemModuleHeader
    NJApp --> UserModuleHeader
    NJApp --> WeekplanModuleHeader

    %% API Gateway directs also to Weekplan Controller inside Weekplan Module
    APIGateway --> WeekplanControllerDetailInside

    %% Click Events
    click WeekplanControllerDetail "https://github.com/baptistelecat/dhomotic-api/blob/main/meal-plan-service/src/modules/weekplan/controllers/weekplan.controller.ts"
    click AuthModuleHeader "https://github.com/baptistelecat/dhomotic-api/tree/main/meal-plan-service/src/modules/auth"
    click MealModuleHeader "https://github.com/baptistelecat/dhomotic-api/tree/main/meal-plan-service/src/modules/meal"
    click ProductItemModuleHeader "https://github.com/baptistelecat/dhomotic-api/tree/main/meal-plan-service/src/modules/productItem"
    click UserModuleHeader "https://github.com/baptistelecat/dhomotic-api/tree/main/meal-plan-service/src/modules/user"
    click WeekplanModuleHeader "https://github.com/baptistelecat/dhomotic-api/tree/main/meal-plan-service/src/modules/weekplan"
    click FirebaseProvider "https://github.com/baptistelecat/dhomotic-api/blob/main/meal-plan-service/src/providers/firebase.provider.ts"
    click CICD "https://github.com/baptistelecat/dhomotic-api/tree/main/.github/workflows"
    click Docker "https://github.com/baptistelecat/dhomotic-api/tree/main/meal-plan-service/Dockerfile"

    %% Styles
    classDef moduleHeader fill:#f9c,stroke:#333,stroke-width:2px;
    classDef service fill:#cfc,stroke:#333,stroke-width:2px;
    classDef entity fill:#ccf,stroke:#333,stroke-width:2px;
    classDef converter fill:#fc9,stroke:#333,stroke-width:2px;
    classDef dto fill:#cff,stroke:#333,stroke-width:2px;
    classDef guard fill:#f99,stroke:#333,stroke-width:2px;
    classDef strategy fill:#9cf,stroke:#333,stroke-width:2px;
    classDef external fill:#eee,stroke:#333,stroke-width:2px;
    classDef controller fill:#ffa,stroke:#333,stroke-width:2px;
    class NJApp,APIGateway,CICD,Docker,FirebaseProvider external;
    class WeekplanControllerDetail,WeekplanControllerDetailInside controller;
```
