# murillofilho86/customerregister architecture

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

- Interactive diagram: https://gitdiagram.com/murillofilho86/customerregister
- Repository: https://github.com/murillofilho86/customerregister

## Overview

##### Project Type and Purpose
- This is a full-stack customer registration web application:
- Frontend: Angular 16 SPA (“customer-app” directory).
- Backend: .NET 7 microservice (“Customer-Api” solution) following a layered (Onion/Clean) architecture.
- Data store: SQL Server.
- Optional: Docker containerization, Brasil API integration for address lookup.

##### High-Level File Structure Analysis
- Top-level directories:
- Customer-Api: the .NET solution, split into projects:
– CustomerMicroService.Domain: domain entities & repository interfaces.
– CustomerMicroService.Core: shared base classes, messages, results, utilities.
– CustomerMicroService.Data: EF Core DbContext, mappings, repository implementations, external API service.
– CustomerMicroService.Application: application layer—CQRS commands/queries, handlers, DTOs, AutoMapper profiles.
– CustomerMicroService.API: ASP.NET Core project—controllers, configuration, DI, FluentValidation, program entry.
- customer-app: Angular client—module structure (core services, pages, shared components), environment config, assets.
- Key architectural patterns:
- Onion/Clean layers in backend.
- CQRS in Application layer (Commands vs. Queries).
- Repository pattern (ICustomerRepository).
- AutoMapper for domain⇄viewmodel mapping.
- Dependency injection and configuration via ApiConfig, DependenceInjectionConfig.
- External integration: BrasilApiService.

##### README Insights
- Describes tech stack: Angular CLI, Node.js, .NET 7, SQL Server, Docker.
- Setup instructions: database scripts creating Customer & Address tables with a FK.
- Run instructions: start .NET service, configure Angular’s environment.ts to match backend port, run ng serve.

a. Main Components
1. Angular Client (Browser)
2. ASP.NET Core Web API (CustomerMicroService.API)
3. Application Layer (CQRS handlers, DTOs)
4. Domain Layer (Entities, business rules)
5. Data Layer
– EF Core DbContext & Mappings
– Repository Implementations
– BrasilApiService (external HTTP service)
6. SQL Server Database
7. (Optional) Docker Host / Docker Compose network
b. Relationships & Data Flow
1. Browser ⇄ HTTP ↔ CustomerController (API Layer)
2. Controller → Injected Application Services (ICommandHandler, IQuery)
3. Handlers → Domain Entities & Repository Interfaces
4. Repository Implementations → EF Core → SQL Server
5. Data Layer → HTTP Calls → BrasilApiService → External Address API
6. DI Container wires all layers at startup (DependenceInjectionConfig)
c. Architectural Patterns/Design Principles
- Layered/Onion architecture: controllers depend on application layer → domain → data.
- CQRS separation: Commands vs. Queries with distinct handlers.
- Repository abstraction for data persistence.
- AutoMapper decouples domain from view models.
- FluentValidation for request validation.
d. Technologies & Frameworks
- Frontend: Angular 16, TypeScript, RxJS, Angular CLI
- Backend: .NET 7, ASP.NET Core Web API, Entity Framework Core, AutoMapper, FluentValidation, Dependency Injection
- Database: SQL Server
- External: BrasilApiService via HttpClient
- Deployment: Dockerfile, docker-compose (optional)

- Blue rectangles for frontend (Angular modules/components)
- Green for API and application services
- Yellow for domain entities & business logic
- Orange for data/infrastructure (EF Core, repositories, external API)

##### Essential Details to Capture
- Controller endpoints and their routing (e.g., GET /api/customers, POST /api/customers).
- CQRS command vs. query handlers.
- Entity relationships (Customer ⇄ Address via AddressId).
- BrasilApiService as an external module invoked during address validation/lookup.
- DI configuration class injecting IRepository, IBrasilApiService, AutoMapper profiles, FluentValidation rules.
- Database schema primary keys, FKs, row version for concurrency.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Angular 16 SPA)"
        direction TB
        AngularClient["Angular Client (SPA)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer (ASP.NET Core Web API)" 
        direction TB
        Program["Program.cs"]:::api
        ApiConfig["ApiConfig.cs"]:::api
        DIConfig["DependenceInjectionConfig.cs"]:::api
        AutoMapAPI["AutoMapperConfig.cs"]:::api
        FluentVal["FluentValidationConfig.cs"]:::api
        Controller["CustomerController"]:::api
    end

    %% Application Layer
    subgraph "Application Layer (CQRS, DTOs)" 
        direction TB
        Commands["Commands"]:::app
        Queries["Queries"]:::app
        Handler["CustomerCommandHandler / CustomerQuery Handler"]:::app
        AutoMapApp["AutoMapper Profiles"]:::app
    end

    %% Domain Layer
    subgraph "Domain Layer (Entities & Interfaces)"
        direction TB
        CustomerEntity["Customer.cs"]:::domain
        AddressEntity["Address.cs"]:::domain
        RepoInterface["ICustomerRepository"]:::domain
    end

    %% Data/Infrastructure Layer
    subgraph "Data Layer (EF Core & Repos)"
        direction TB
        DbContext["CustomerContext"]:::infra
        Mapping["CustomerMapping"]:::infra
        RepoImpl["CustomerRepository"]:::infra
        BrasilService["BrasilApiService"]:::infra
        IBrasil["IBrasilApiService"]:::infra
        BrasilOptions["BrasilApiOptions"]:::infra
        Responses["DocumentInfo (Response Models)"]:::infra
    end

    %% External & Database
    subgraph "External Services & Database"
        direction TB
        SQLServer["SQL Server"]:::db
        ExternalAPI["External Address API"]:::external
        DockerHost["Docker Host / Compose"]:::docker
    end

    %% Connections
    AngularClient -->|"HTTP/JSON"| Controller
    Controller -->|"calls Handler"| Handler
    Handler -->|"uses Commands/Queries"| Commands
    Handler -->|"uses Commands/Queries"| Queries
    Handler -->|"AutoMapper"| AutoMapApp
    Handler -->|"calls Repository"| RepoInterface
    RepoInterface -->|"implemented by"| RepoImpl
    RepoImpl -->|"EF Core LINQ"| DbContext
    DbContext -->|"SQL queries"| SQLServer
    RepoImpl -->|"HttpClient"| BrasilService
    BrasilService -->|"calls"| ExternalAPI

    Program --> ApiConfig
    Program --> DIConfig
    Program --> AutoMapAPI
    Program --> FluentVal
    DIConfig --> RepoInterface
    DIConfig --> IBrasil
    DIConfig --> AutoMapAPI
    DIConfig --> FluentVal
    AutoMapAPI --> AutoMapApp

    %% Click Events
    click AngularClient "https://github.com/murillofilho86/customerregister/tree/master/customer-app/"
    click Program "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService/Program.cs"
    click ApiConfig "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService/Configuration/ApiConfig.cs"
    click DIConfig "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService/Configuration/DependenceInjectionConfig.cs"
    click AutoMapAPI "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService/Configuration/AutoMapperConfig.cs"
    click FluentVal "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService/Configuration/FluentValidationConfig.cs"
    click Controller "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService/Controllers/CustomerController.cs"
    click Commands "https://github.com/murillofilho86/customerregister/tree/master/Customer-Api/CustomerMicroService.Application/Commands/"
    click Handler "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService.Application/Handlers/CustomerCommandHandler.cs"
    click Queries "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService.Application/Queries/Concrete/CustomerQuery.cs"
    click RepoInterface "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService.Domain/Repository/ICustomerRepository.cs"
    click CustomerEntity "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService.Domain/Entities/Customer.cs"
    click AddressEntity "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService.Domain/Entities/Address.cs"
    click DbContext "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService.Data/Context/CustomerContext.cs"
    click Mapping "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService.Data/Mapping/CustomerMapping.cs"
    click RepoImpl "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService.Data/Repository/CustomerRepository.cs"
    click BrasilService "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService.Data/Services/BrasilApiService.cs"
    click IBrasil "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService.Data/Services/IBrasilApiService.cs"
    click BrasilOptions "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService.Data/Services/BrasilApiOptions.cs"
    click Responses "https://github.com/murillofilho86/customerregister/blob/master/Customer-Api/CustomerMicroService.Data/Services/Responses/DocumentInfo.cs"
    click RepoImpl "https://github.com/murillofilho86/customerregister/tree/master/Customer-Api/CustomerMicroService/Dockerfile"

    %% Styles
    classDef frontend fill:#cfe2ff,stroke:#0d6efd,stroke-width:2px
    classDef api fill:#d1e7dd,stroke:#198754,stroke-width:2px
    classDef app fill:#cff4fc,stroke:#0dcaf0,stroke-width:2px
    classDef domain fill:#fff3cd,stroke:#ffc107,stroke-width:2px
    classDef infra fill:#ffe5d9,stroke:#fd7e14,stroke-width:2px
    classDef db fill:#e2e3e5,stroke:#6c757d,stroke-width:2px
    classDef external fill:#f8d7da,stroke:#dc3545,stroke-width:2px
    classDef docker fill:#e7d6f1,stroke:#6f42c1,stroke-width:2px
```
