# thiagoluzia/gerenciadorclinica architecture

> Architecture diagram of the GitHub repository thiagoluzia/gerenciadorclinica, 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/thiagoluzia/gerenciadorclinica
- Repository: https://github.com/thiagoluzia/gerenciadorclinica

## Overview

##### Project type and purpose
- Project Type: This is a backend-only system—an ASP.NET Core RESTful API implementing a Clean Architecture with CQRS for clinic management.
- Purpose: Expose CRUD endpoints for Pacientes, Médicos, Atendimentos and Serviços, send confirmation emails, and integrate with Google Calendar and the ViaCEP web service.

##### File structure
- Top-level solution `GerenciadorClinica.sln` contains four .NET projects:
- GC.API – the Web API (Presentation layer)
- GC.Application – the Use Case layer (business logic, CQRS)
- GC.Core – the Domain layer (entities, enums, repository interfaces)
- GC.Infrastructure – the Infrastructure layer (EF Core, database, external integrations)
- There are also two test projects: GC.ApplicationTests and Gc.ApiTests.
- Notice patterns:
- Clean Architecture layers
- CQRS folders under Application/CQRS/Commands and Queries
- Repository interfaces in Core/Repositories and implementations in Infrastructure/Persistence/Repositories
- External integrations in Infrastructure/Integrations (Google Calendar, ViaCEP)
- Configuration and migrations in Infrastructure/Migrations.
- Middleware and filters under API (ExceptionHandler, Filters).

##### README insights
- Confirms technologies: ASP.NET Core, EF Core, Fluent Validation, Repository Pattern, CQRS, Clean Architecture, SQL Server.
- Lists functional features and integrations.

##### Main components
a. Presentation Layer
- Inside: Controllers, Middleware (Exception Handler), Filters, Swagger
b. Application Layer
- Inside: CommandHandlers, QueryHandlers, DTOs, Validators, External service interfaces (IGoogleCalendarService, IViaCepService)
c. Domain Layer
- Inside: Entities, Enums, Repository Interfaces
d. Infrastructure Layer
- Persistence: EF Core DbContext, Migrations, Repository implementations
- Integrations: Google Calendar API, ViaCEP Web Service
- Config Files (credential.json, token.json)
e. External Systems
f. Database
- EF Core Migrations push schema to it

##### Relationships and data flows
- DI container in API to wire up interfaces to implementations.

##### Architectural patterns
- Clean Architecture: revolve around Dependency Rule (outer layers depend inward on Core)
- CQRS: separate Commands and Queries in Application layer
- Repository Pattern: repository interfaces in Core, implemented in Infrastructure
- Fluent Validation in Application validators
- Middleware pipeline in API for exception handling and validation

##### Technologies and frameworks
- ASP.NET Core 8.0 (API)
- Entity Framework Core (ORM, Migrations)
- SQL Server
- FluentValidation
- Dependency Injection
- Google.Apis.Calendar.v3 REST client
- ViaCEP HTTP client

##### Final advice
- Be exhaustive: include all four layers, the database, and external integrations.
- Patterns (CQRS, Repository, Middleware) and technology choices.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation: GC.API"
        direction TB
        Controllers["Controllers"]:::presentation
        ExceptionHandler["ApiExceptionHandler Middleware"]:::presentation
        ValidationFilter["ValidationFilter"]:::presentation
        Swagger["Swagger"]:::presentation
    end

    %% Application Layer
    subgraph "Application: GC.Application"
        direction TB
        CQRSContract["CQRSContract"]:::application
        CommandHandlers["Command Handlers"]:::application
        QueryHandlers["Query Handlers"]:::application
        DTOs["DTOs"]:::application
        Validators["FluentValidation Validators"]:::application
        IGoogleCalendarService["IGoogleCalendarService"]:::application
        IViaCepService["IViaCepService"]:::application
    end

    %% Domain Layer
    subgraph "Domain: GC.Core"
        direction TB
        Entities["Entities"]:::domain
        Enums["Enums"]:::domain
        RepoInterfaces["Repository Interfaces"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure: GC.Infrastructure"
        direction TB
        subgraph Persistence
            direction TB
            DbContext["DBClinicaContexto"]:::infrastructure
            Configurations["Entity Configurations"]:::infrastructure
            RepositoriesImpl["Repository Implementations"]:::infrastructure
            Migrations["EF Core Migrations"]:::infrastructure
        end
        subgraph Integrations
            direction TB
            subgraph GoogleCalendar
                direction TB
                CredentialFile["credential.json"]:::infrastructure
                TokenFile["token.json"]:::infrastructure
                ApiGoogleService["ApiGoogleCalendarService"]:::infrastructure
                EventoModel["EventoGoogleAgenda Model"]:::infrastructure
            end
            subgraph ViaCep
                direction TB
                ApiViaCepService["ApiViaCEPService"]:::infrastructure
                EnderecoModel["Endereco Model"]:::infrastructure
            end
        end
        Extensions["Extensions"]:::infrastructure
    end

    %% External Systems
    GoogleCalendarExt["Google Calendar API"]:::external
    ViaCepExt["ViaCEP REST API"]:::external
    SMTP["SMTP / Email Service"]:::external

    %% Database
    SQLServer["SQL Server Database"]:::database

    %% Connections
    Controllers -->|"Execute Command/Query"| CQRSContract
    CommandHandlers -->|Uses| RepoInterfaces
    QueryHandlers -->|Uses| RepoInterfaces
    CQRSContract -->|References| CommandHandlers
    CQRSContract -->|References| QueryHandlers
    DTOs -->|Data Transfer| Controllers
    Validators -->|Validate DTOs| CommandHandlers
    IGoogleCalendarService <--> ApiGoogleService
    IViaCepService <--> ApiViaCepService
    CommandHandlers -->|Invoke External| IGoogleCalendarService
    CommandHandlers -->|Invoke External| IViaCepService

    CQRSContract -->|Calls| Entities
    CQRSContract -->|Calls| Enums

    RepoInterfaces -->|Implemented By| RepositoriesImpl
    RepositoriesImpl -->|Uses| DbContext

    DbContext -->|Apply Migrations| Migrations
    Configurations -->|Configure Entities| DbContext

    RepositoriesImpl -->|CRUD Operations| SQLServer
    Migrations -->|Schema Updates| SQLServer

    ApiGoogleService -->|Calls API| GoogleCalendarExt
    ApiViaCepService -->|Calls API| ViaCepExt
    CommandHandlers -->|Send Email| SMTP

    Controllers -->|DI/Service Resolution| RepositoriesImpl
    Controllers -->|DI/Service Resolution| ApiGoogleService
    Controllers -->|DI/Service Resolution| ApiViaCepService
    Controllers -->|DI/Service Resolution| Validators

    %% Click Events
    click Controllers "https://github.com/thiagoluzia/gerenciadorclinica/tree/main/GerenciadorClinica/GC.API/Controllers"
    click ExceptionHandler "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.API/ExeptionHandler/ApiExceptionHandler.cs"
    click ValidationFilter "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.API/Filters/ValidationFilter.cs"
    click CQRSContract "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.Application/CQRS/CQRSContract.cs"
    click CommandHandlers "https://github.com/thiagoluzia/gerenciadorclinica/tree/main/GerenciadorClinica/GC.Application/CQRS/Commands"
    click QueryHandlers "https://github.com/thiagoluzia/gerenciadorclinica/tree/main/GerenciadorClinica/GC.Application/CQRS/Queries"
    click DTOs "https://github.com/thiagoluzia/gerenciadorclinica/tree/main/GerenciadorClinica/GC.Application/DTOs"
    click IGoogleCalendarService "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.Application/Services/External/GoogleCalendar/IGoogleCalendarService.cs"
    click IViaCepService "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.Application/Services/External/ViaCEP/IViaCepService.cs"
    click Validators "https://github.com/thiagoluzia/gerenciadorclinica/tree/main/GerenciadorClinica/GC.Application/Validators"
    click Entities "https://github.com/thiagoluzia/gerenciadorclinica/tree/main/GerenciadorClinica/GC.Core/Entityes"
    click Enums "https://github.com/thiagoluzia/gerenciadorclinica/tree/main/GerenciadorClinica/GC.Core/Enums"
    click RepoInterfaces "https://github.com/thiagoluzia/gerenciadorclinica/tree/main/GerenciadorClinica/GC.Core/Repositories"
    click DbContext "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.Infrastructure/Persistence/DBClinicaContexto.cs"
    click Configurations "https://github.com/thiagoluzia/gerenciadorclinica/tree/main/GerenciadorClinica/GC.Infrastructure/Persistence/Configuration"
    click RepositoriesImpl "https://github.com/thiagoluzia/gerenciadorclinica/tree/main/GerenciadorClinica/GC.Infrastructure/Persistence/Repositories"
    click Migrations "https://github.com/thiagoluzia/gerenciadorclinica/tree/main/GerenciadorClinica/GC.Infrastructure/Migrations"
    click CredentialFile "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.Infrastructure/Integrations/GoogleCalendar/Credential/credential.json"
    click TokenFile "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.Infrastructure/Integrations/GoogleCalendar/token.Json"
    click ApiGoogleService "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.Infrastructure/Integrations/GoogleCalendar/Services/ApiGoogleCalendarService.cs"
    click EventoModel "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.Infrastructure/Integrations/GoogleCalendar/Models/EventoGoogleAgenda.cs"
    click ApiViaCepService "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.Infrastructure/Integrations/ViaCep/Services/ApiViaCEPService.cs"
    click EnderecoModel "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.Infrastructure/Integrations/ViaCep/Models/Endereco.cs"
    click Extensions "https://github.com/thiagoluzia/gerenciadorclinica/blob/main/GerenciadorClinica/GC.Infrastructure/Extensions/Extensions.cs"

    %% Styles
    classDef presentation fill:#AED6F1,stroke:#217DBB,color:#000
    classDef application fill:#ABEBC6,stroke:#28B463,color:#000
    classDef domain fill:#F9E79F,stroke:#B7950B,color:#000
    classDef infrastructure fill:#F5CBA7,stroke:#D35400,color:#000
    classDef external fill:#D5D8DC,stroke:#7F8C8D,color:#000
    classDef database fill:#ABEBC6,stroke:#1E8449,stroke-width:2px,color:#000,shape:cylinder
```
