# wibu009/bookify architecture

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

- Interactive diagram: https://gitdiagram.com/wibu009/bookify
- Repository: https://github.com/wibu009/bookify

## Overview

##### Main Components
- API Layer (Bookify.Api): This is the entry point exposing HTTP endpoints (note the endpoints directories for Apartments, Bookings, Reviews, and Users) that handle HTTP requests. The API layer also sets up middleware (like exception handling and logging) and opens Swagger/OpenAPI for documentation.
- Application Layer (Bookify.Application): Contains business logic orchestrated through commands, queries, and domain events. It implements various “use cases” such as creating apartments, booking operations, and user authentication/registration. Include pipelines for caching, validation, and logging.
- Domain Layer (Bookify.Domain): Represents business entities – such as Apartments, Bookings, Reviews, and Users – along with their rules, validations, and domain events. This layer is the heart of the system, modeling core business logic using rich domain objects and events.
- Infrastructure Layer (Bookify.Infrastructure): Implements technical concerns such as persistence (via ApplicationDbContext and repository patterns), caching, emailing, authentication and authorization (including integration with Keycloak), outbox processing, audit logging, and background job scheduling. External library dependencies, configuration files (like appsettings.json), and migration scripts are also present here.
- Shared Layer (Bookify.Shared): Hosts common components, such as error handling and result objects, as well as common authorization constants.
- Testing Layers (Functional, Integration, Unit, and Architecture Tests): They ensure separation of concerns and validate the correct interplay between layers.

##### Representing Relationships & Data Flow
- That the Application Layer orchestrates business operations by invoking Domain Layer components.
- External resources such as key configuration files (Docker-related files, Docker Compose, and Keycloak settings) that allow deployment and integration with external services.
- Tests as separate layers that interact with various components to validate the implementation.

##### Architectural Patterns & Design Principles
- Use of Command/Query patterns: Represent how user actions (commands/queries) flow from the API through the Application layer and may trigger corresponding domain events.
- Repository Pattern & Unit of Work: Note the integration in the Infrastructure layer for persistence operations.
- Middleware pipelines: Include elements like exception handling, logging, and authentication, which are integrated at the API level.
- Asynchronous processing: The outbox and job scheduling mechanisms should be shown as additional architectural components that ensure reliable, decoupled processing.

##### Detailing Technologies, Frameworks, & Libraries
- .NET (C#) is the core platform.
- Entity Framework Core (or a similar ORM) is implied in persistence with migrations and database seeders.
- Docker (with Dockerfile, docker-compose) for containerization.
- Keycloak for authentication and authorization, as seen in the Keycloak files.
- Swagger/OpenAPI for API documentation.
- Testing frameworks covering functional, integration, unit, and architecture tests.

##### Final Recommendations
- Use clear labels for every component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        A_API("API Layer"):::api
        A_Endpoints("HTTP Endpoints"):::api
        A_Middleware("API Middleware"):::api
        A_Documentation("API Documentation"):::api
    end

    %% Application Layer
    subgraph "Application Layer"
        B_APP("Application Layer"):::application
        B_Handlers("Command/Query Handlers & Pipelines"):::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        C_DOMAIN("Domain Layer"):::domain
        C_Entities("Entities & Domain Events"):::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        D_INF("Infrastructure Layer"):::infrastructure
        D_Services("Persistence, Auth, Caching, Outbox, Jobs"):::infrastructure
    end

    %% Shared Utilities
    subgraph "Shared Utilities"
        E_SHARED("Shared Utilities"):::shared
    end

    %% Testing Layers
    subgraph "Testing"
        F_API_Test("API Functional Tests"):::testing
        G_AppInt_Test("Application Integration Tests"):::testing
        H_AppUnit_Test("Application Unit Tests"):::testing
        I_Arch_Test("Architecture Tests"):::testing
        J_Domain_Test("Domain Unit Tests"):::testing
    end

    %% Relationships between Layers
    A_API -->|"API_Request"| B_APP
    B_APP -->|"BusinessLogic"| C_DOMAIN
    B_APP -->|"DataAccess/Caching"| D_INF
    C_DOMAIN -->|"TriggersDomainEvents"| D_INF
    B_APP -->|"UsesUtilities"| E_SHARED
    C_DOMAIN -->|"UsesUtilities"| E_SHARED
    D_INF -->|"UsesUtilities"| E_SHARED

    %% Testing connections
    F_API_Test -->|"TestsAPI"| A_API
    G_AppInt_Test -->|"TestsIntegration"| B_APP
    H_AppUnit_Test -->|"TestsUnit"| B_APP
    I_Arch_Test -->|"TestsArchitecture"| A_API
    J_Domain_Test -->|"TestsDomain"| C_DOMAIN

    %% Click Events for Component Mappings
    click A_API "https://github.com/wibu009/bookify/blob/main/src/Bookify.Api"
    click A_Endpoints "https://github.com/wibu009/bookify/tree/main/src/Bookify.Api/Endpoints"
    click A_Middleware "https://github.com/wibu009/bookify/tree/main/src/Bookify.Api/Middleware"
    click A_Documentation "https://github.com/wibu009/bookify/blob/main/src/Bookify.Api/OpenApi/ConfigureSwaggerOptions.cs"
    click B_APP "https://github.com/wibu009/bookify/blob/main/src/Bookify.Application"
    click C_DOMAIN "https://github.com/wibu009/bookify/blob/main/src/Bookify.Domain"
    click D_INF "https://github.com/wibu009/bookify/blob/main/src/Bookify.Infrastructure"
    click E_SHARED "https://github.com/wibu009/bookify/blob/main/src/Bookify.Shared"
    click F_API_Test "https://github.com/wibu009/bookify/blob/main/test/Bookify.Api.FunctionalTests"
    click G_AppInt_Test "https://github.com/wibu009/bookify/blob/main/test/Bookify.Application.IntegrationTests"
    click H_AppUnit_Test "https://github.com/wibu009/bookify/blob/main/test/Bookify.Application.UnitTests"
    click I_Arch_Test "https://github.com/wibu009/bookify/blob/main/test/Bookify.ArchitectureTests"
    click J_Domain_Test "https://github.com/wibu009/bookify/blob/main/test/Bookify.Domain.UnitTests"

    %% Styles
    classDef api fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef application fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef domain fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef infrastructure fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef shared fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef testing fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
