# welissonarley/myrecipebook architecture

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

- Interactive diagram: https://gitdiagram.com/welissonarley/myrecipebook
- Repository: https://github.com/welissonarley/myrecipebook

## Overview

##### Project type and purpose
- This repository contains a **backend API** named “Meu Livro de Receitas” built on **.NET 8**, providing REST endpoints for user registration/login (including Google OAuth), recipe CRUD (create, read, update, delete, filter, generate via OpenAI), image upload, and account‐deletion messaging.
- It follows **Domain-Driven Design (DDD)** and **SOLID** principles, layered into API, Application, Domain, and Infrastructure modules, with shared DTOs/exception libraries and comprehensive unit/integration/web-api tests.

##### File structure
- Top-level artifacts: Dockerfile, GitHub Actions/workflows, Azure Pipelines YAML, solution file (.sln), README, and an images folder.
- src/Backend subdivides into four DDD layers:
- MyRecipeBook.API – Web API controllers, middleware, filters, HTTP binding, background services
- MyRecipeBook.Application – Use-case classes (Dashboard, Login, Recipe, User, Token), validation (FluentValidation via shared validators), AutoMapper profiles, DI extensions
- MyRecipeBook.Domain – Entities, value objects, DTOs, repository and service bus/storage/tokens/security abstractions
- MyRecipeBook.Infrastructure – EF Core DbContext, migrations, repository implementations, cryptography (BCrypt), JWT/refresh token generators/validators, Azure Service Bus processor, Azure Blob Storage, OpenAI ChatGPT service
- Shared libraries: Communication (request/response DTOs) and Exceptions (custom exception types).
- tests/ covers common utilities, unit tests for use cases and validators, WebAPI integration tests.

##### Architecture insights from README
- Supports MySQL or SQL Server via EF Core
- Uses JWT + Refresh Token for authentication, Google external login, Service Bus for asynchronous deletion, Azure Blob Storage for images, OpenAI for recipe generation
- CI/CD pipelines with SonarCloud quality/gate analysis
- Emphasizes modularity through DI, layered separation, and automated migrations

##### Attention to detail
- Every crucial component: middleware (culture, exception filter, authentication), background services, token providers, validators, repositories, and message processors.
- Don’t over-abstract: show both interface and concrete implementation for key services and repositories.
- Data flow for login, recipe generation, recipe CRUD, image upload, and account deletion.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    subgraph "Clients"
        direction TB
        Postman["Postman"]:::external
        SPA["SPA/Mobile App"]:::external
    end

    %% API Layer
    subgraph "API Layer" 
        direction TB
        Controllers["Controllers"]:::api
        Middleware["Middleware"]:::api
        Filters["Filters"]:::api
        DeleteService["BackgroundService (User Deletion)"]:::api
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        UseCases["Use Cases"]:::app
        Validators["FluentValidation Validators"]:::app
        AutoMapping["AutoMapper Profiles"]:::app
        AppDI["DI Extensions"]:::app
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        Entities["Entities"]:::domain
        ValueObjects["Value Objects"]:::domain
        DTOs["DTOs"]:::domain
        RepoInterfaces["Repository Interfaces"]:::domain
        SecurityInterfaces["Security Interfaces"]:::domain
        ServiceAbstractions["Service Abstractions"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        subgraph "DataAccess"
            direction TB
            DbContext["EF Core DbContext"]:::infra
            Repositories["Repository Implementations"]:::infra
            UnitOfWork["Unit Of Work"]:::infra
            Migrations["Migrations"]:::infra
        end
        subgraph "Security"
            direction TB
            Cryptography["BCrypt Cryptography"]:::infra
            TokenServices["JWT & Refresh Token Services"]:::infra
        end
        subgraph "Services"
            direction TB
            ServiceBus["Azure Service Bus"]:::infra
            BlobStorage["Azure Blob Storage"]:::infra
            OpenAIService["OpenAI ChatGPT Service"]:::infra
        end
        InfraDI["DI Extensions"]:::infra
    end

    %% External Services
    subgraph "External Services"
        direction TB
        MySQL["MySQL/SQLServer"]:::external
        GoogleOAuth["Google OAuth"]:::external
        OpenAIAPI["OpenAI API"]:::external
    end

    %% CI/CD
    subgraph "CI/CD & DevOps"
        direction TB
        GHActions["GitHub Actions"]:::external
        AzurePipelines["Azure Pipelines"]:::external
        SonarCloud["SonarCloud"]:::external
        DockerfileNode["Dockerfile"]:::external
    end

    %% Flows
    Postman -->|HTTP REST| Controllers
    SPA -->|HTTP REST| Controllers
    Controllers -->|calls| UseCases
    Controllers -->|uses| Middleware
    Controllers -->|applies| Filters
    Controllers -->|enqueue deletion| DeleteService

    UseCases -->|validate| Validators
    UseCases -->|map DTOs| AutoMapping
    UseCases -->|depends on| ServiceAbstractions
    UseCases -->|use| RepoInterfaces
    UseCases -->|use| SecurityInterfaces

    RepoInterfaces -->|implemented by| Repositories
    ServiceAbstractions -->|implemented by| ServiceBus
    ServiceAbstractions -->|implemented by| BlobStorage
    ServiceAbstractions -->|implemented by| OpenAIService
    SecurityInterfaces -->|implemented by| Cryptography
    SecurityInterfaces -->|implemented by| TokenServices

    Repositories -->|EF Core| DbContext
    DbContext -->|SQL| MySQL
    Migrations -->|migrate| DbContext

    DeleteService -->|AMQP| ServiceBus
    ServiceBus -->|process delete| DeleteService

    Controllers -->|upload images| BlobStorage
    UseCases -->|generate recipe| OpenAIService
    OpenAIService -->|REST API| OpenAIAPI

    Controllers -->|login/refresh| TokenServices
    Controllers -->|external login| GoogleOAuth

    %% CI/CD connections
    GHActions -->|build/test| Controllers
    AzurePipelines -->|deploy| Controllers
    SonarCloud -->|analysis| Controllers
    DockerfileNode -->|containerize| Controllers

    %% Click Events
    click Controllers "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.API/Controllers"
    click Middleware "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.API/Middleware"
    click Filters "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.API/Filters"
    click DeleteService "https://github.com/welissonarley/myrecipebook/blob/develop/src/Backend/MyRecipeBook.API/BackgroundServices/DeleteUserService.cs"
    click UseCases "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.Application/UseCases"
    click Validators "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.Application/SharedValidators"
    click AutoMapping "https://github.com/welissonarley/myrecipebook/blob/develop/src/Backend/MyRecipeBook.Application/Services/AutoMapper/AutoMapping.cs"
    click AppDI "https://github.com/welissonarley/myrecipebook/blob/develop/src/Backend/MyRecipeBook.Application/DependencyInjectionExtension.cs"
    click Entities "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.Domain/Entities"
    click ValueObjects "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.Domain/ValueObjects"
    click DTOs "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.Domain/Dtos"
    click RepoInterfaces "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.Domain/Repositories"
    click SecurityInterfaces "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.Domain/Security"
    click ServiceAbstractions "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.Domain/Services"
    click DbContext "https://github.com/welissonarley/myrecipebook/blob/develop/src/Backend/MyRecipeBook.Infrastructure/DataAccess/MyRecipeBookDbContext.cs"
    click Repositories "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.Infrastructure/DataAccess/Repositories"
    click UnitOfWork "https://github.com/welissonarley/myrecipebook/blob/develop/src/Backend/MyRecipeBook.Infrastructure/DataAccess/UnitOfWork.cs"
    click Migrations "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.Infrastructure/Migrations"
    click Cryptography "https://github.com/welissonarley/myrecipebook/blob/develop/src/Backend/MyRecipeBook.Infrastructure/Security/Cryptography/BCryptNet.cs"
    click TokenServices "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.Infrastructure/Security/Tokens"
    click ServiceBus "https://github.com/welissonarley/myrecipebook/tree/develop/src/Backend/MyRecipeBook.Infrastructure/Services/ServiceBus"
    click BlobStorage "https://github.com/welissonarley/myrecipebook/blob/develop/src/Backend/MyRecipeBook.Infrastructure/Services/Storage/AzureStorageService.cs"
    click OpenAIService "https://github.com/welissonarley/myrecipebook/blob/develop/src/Backend/MyRecipeBook.Infrastructure/Services/OpenAI/ChatGPTService.cs"
    click InfraDI "https://github.com/welissonarley/myrecipebook/blob/develop/src/Backend/MyRecipeBook.Infrastructure/DependencyInjectionExtension.cs"
    click SharedCommunication "https://github.com/welissonarley/myrecipebook/blob/develop/src/Shared/MyRecipeBook.Communication"
    click SharedExceptions "https://github.com/welissonarley/myrecipebook/blob/develop/src/Shared/MyRecipeBook.Exceptions"
    click GHActions "https://github.com/welissonarley/myrecipebook/blob/develop/.github/workflows/build.yml"
    click AzurePipelines "https://github.com/welissonarley/myrecipebook/blob/develop/release-pipeline.yml"
    click DockerfileNode "https://github.com/welissonarley/myrecipebook/tree/develop/Dockerfile"

    %% Styles
    classDef api fill:#D6EAF8,stroke:#3498DB
    classDef app fill:#D5F5E3,stroke:#27AE60
    classDef domain fill:#FCF3CF,stroke:#F1C40F
    classDef infra fill:#E5E7E9,stroke:#95A5A6
    classDef external fill:#FADBD8,stroke:#E74C3C
```
