# lcps1/realstate architecture

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

- Interactive diagram: https://gitdiagram.com/lcps1/realstate
- Repository: https://github.com/lcps1/realstate

## Overview

##### Main Components
- API / Presentation Layer: Represented by the various API projects (e.g. src/RealState.Api) and controllers (AuthenticationController, PropertyController, etc.).
- Application Layer: Contains the command and query handlers, validators, and business logic (src/RealState.Application) that implement the use cases for property management, image management, authentication, etc.
- Domain Layer: Contains the core entities (PropertyBuilding, PropertyImage, Owner, etc.), domain events (OwnerCreated, PropertyPriceChanged), value objects, and interfaces that define the business rules (src/RealState.Domain).
- Infrastructure Layer: Manages data persistence and external integration with the database using Entity Framework Core, repository implementations, the Unit of Work, and migration management (src/RealState.Infrastructure).
- Contracts: This layer (src/RealState.Contracts) defines data transfer objects (DTOs) and shared models used for communication between layers or external systems.
- External Services: Include the SQL Server database (launched via Docker), Docker containers (referenced in docker-compose.yaml and Dockerfile), and any client tools used for testing (like Postman).

##### Relationships and Interactions
- That the application layer uses the domain layer (business logic, domain events) to ensure consistency.
- That the infrastructure layer is responsible for the actual data persistence, with repositories and the Unit of Work mediating between the domain and the database.
- Contracts layer as the mechanism for transferring data between the external API and internal processing.
- Dependency of each layer on the other, for example:
- API → Application (via Dependency Injection)
- Application → Domain (invoking domain services and publishing events)
- Application → Infrastructure (to persist data using repository interfaces)
- All layers may also communicate with external services like the SQL Server container managed via Docker.

##### Incorporate Key Architectural Patterns
- Domain-Driven Design (DDD): Highlight how the Domain layer encapsulates entities, value objects, and domain events.
- Clean/Onion Architecture: Emphasize the separation between presentation, application, domain, and infrastructure.
- Command Handler Pattern: Mark the presence of commands and queries in the Application layer.
- Unit of Work and Repository Patterns: Specifically pinpoint where interfaces in the application and domain connect with concrete repository implementations in the infrastructure layer.

##### Relevant Technologies & Frameworks
- .NET 6+ (or later) and ASP.NET Core for the backend API.
- Entity Framework Core for ORM and database interactions.
- Testing frameworks with FluentAssertions and NSubstitute shown as part of the unit tests.
- Docker (docker-compose.yaml, Dockerfile) for containerizing the database (SQL Server).
- The use of dependency injection as configured across the application.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "API / Presentation Layer"
        A1["AuthenticationController"]:::api
        A2["PropertyController"]:::api
    end

    subgraph "Contracts"
        C1["Data Transfer Objects (DTOs)"]:::contracts
    end

    subgraph "Application Layer"
        AP1["Command & Query Handlers"]:::app
        AP2["Validators & Business Logic"]:::app
    end

    subgraph "Domain Layer"
        D1["Domain Entities"]:::domain
        D2["Domain Events"]:::domain
    end

    subgraph "Infrastructure Layer"
        INF1["Persistence (Repositories & UoW)"]:::infra
        INF2["Migrations"]:::infra
    end

    subgraph "External Services"
        EX1["SQL Server (Docker)"]:::external
    end

    %% Relationships between layers
    A1 -->|"uses"| C1
    A2 -->|"uses"| C1
    C1 -->|"mapsTo"| AP1
    AP1 -->|"invokes"| D1
    AP1 -->|"publishes"| D2
    AP1 -->|"persists"| INF1
    AP2 -->|"validates"| AP1
    INF1 -->|"storesDataIn"| EX1

    %% Click Events
    click A1 "https://github.com/lcps1/realstate/blob/master/src/RealState.Api/Controllers/AuthenticationController.cs"
    click A2 "https://github.com/lcps1/realstate/blob/master/src/RealState.Api/Controllers/PropertyController.cs"
    click C1 "https://github.com/lcps1/realstate/blob/master/src/RealState.Contracts"
    click AP1 "https://github.com/lcps1/realstate/blob/master/src/RealState.Application"
    click D1 "https://github.com/lcps1/realstate/tree/master/src/RealState.Domain/Entities"
    click D2 "https://github.com/lcps1/realstate/tree/master/src/RealState.Domain/Events"
    click INF1 "https://github.com/lcps1/realstate/tree/master/src/RealState.Infrastructure/Persistence"
    click INF2 "https://github.com/lcps1/realstate/tree/master/src/RealState.Infrastructure/Migrations"
    click EX1 "https://github.com/lcps1/realstate/blob/master/docker-compose.yaml"

    %% Styles
    classDef api fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef app fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef domain fill:#FF6347,stroke:#000,stroke-width:1px;
    classDef infra fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef contracts fill:#DDA0DD,stroke:#000,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px;
```
