# rsmacias/bookify architecture

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

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

## Overview

##### Main Components
- Bookify.Api: This is the entry point. It contains controllers (e.g., ApartmentsController, BookingsController) and handles HTTP requests. It serves as a gateway to the system.
- Bookify.Application: Implements the core business logic using patterns like CQRS. It contains command/query handlers, validators, domain event handlers, and abstractions for cross-cutting concerns (e.g., logging, email, clock, data). Represent this as the “Application Layer”.
- Bookify.Domain: Contains domain models (e.g., Apartment, Booking, Review, User) along with domain logic, events, and value objects. This is the heart of the business logic.
- Bookify.Infrastructure: Provides concrete implementations for database access (via ApplicationDbContext and repository classes), email services, and other external integrations. It implements abstractions defined in the Application and Domain layers.
- Docker and Deployment Files: Reference to docker-compose files and Dockerfile indicates containerization and deployment architecture. You may include a cloud or container layer node if relevant.

##### Relationships and Interactions
- The API layer (Bookify.Api) receives incoming HTTP requests, routes them to controllers, and then hands off to appropriate application services.
- Within the Application Layer, commands and queries are processed. Handlers interact with Domain logic (for instance, validating bookings or searching apartments) and may publish domain events.
- The Domain Layer encapsulates the core business entities and domain events. Domain events (like BookingReservedDomainEvent) might trigger secondary actions that are handled within the Application Layer.
- The Infrastructure Layer supports persistence (e.g., Entity Framework’s ApplicationDbContext and repositories), external services (e.g., EmailService), and low-level utilities (e.g., DateTimeProvider). This layer is consumed by the Application Layer via dependency injection.
· From Bookify.Api (controllers) to Application Layer (command/query handlers).
· From Application Layer to Domain Layer when applying business rules.
· From Application Layer to Infrastructure when fetching or storing data.

##### Architectural Patterns and Design Principles
- Layered (clean architecture) separation of concerns. Clearly delineate the API, Application, Domain, and Infrastructure layers.
- Use of patterns such as CQRS in the Application Layer (separate queries from commands) and Domain-Driven Design (entities, value objects, and domain events in the Domain Layer).
- Dependency inversion: High-level modules in the Application depend on abstractions, while the Infrastructure provides concrete implementations.
- Design patterns such as Repository and Unit of Work (visible in the Infrastructure and Domain).

##### Relevant Technologies and Frameworks
- .NET Core (using csproj files and the Controller pattern indicates ASP.NET Core).
- Entity Framework (or a similar ORM) likely used, as evidenced by ApplicationDbContext and repository implementations.
- Docker containers to support deployment.
- The project’s naming indicates the use of standard patterns seen in enterprise .NET applications.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    CLIENT["Client/HTTP Request"]:::external

    %% API Layer
    subgraph "API Layer"
        API["Bookify.Api"]:::api
        AC["ApartmentsController"]:::api
        BC["BookingsController"]:::api
    end

    %% Application Layer
    subgraph "Application Layer"
        APP["Bookify.Application"]:::app
        RBCH["ReserveBookingCommandHandler"]:::app
        SACH["SearchApartmentsQueryHandler"]:::app
        BEH["Behaviors"]:::app
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DOM["Bookify.Domain"]:::domain
        APT["Apartment Model"]:::domain
        BK["Booking Model"]:::domain
        BRE["BookingReservedEvent"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        INF["Bookify.Infrastructure"]:::infra
        DB["ApplicationDbContext"]:::infra
        BR["BookingRepository"]:::infra
        EMAIL["EmailService"]:::infra
        CLOCK["DateTimeProvider"]:::infra
    end

    %% Deployment/Containerization
    subgraph "Deployment/Containers"
        DOCKER["Dockerfile (Bookify.Api)"]:::deploy
        DC["Docker Compose"]:::deploy
    end

    %% Data Flow
    CLIENT -->|"sends_request"| API
    API -->|"routes_to"| AC
    API -->|"routes_to"| BC

    AC -->|"calls_handler"| RBCH
    BC -->|"calls_handler"| SACH

    RBCH -->|"applies_logic_to"| APT
    RBCH -->|"triggers_event"| BRE
    SACH -->|"fetches_data_from"| APT

    RBCH -->|"persists_booking"| BR
    RBCH -->|"uses_db"| DB
    RBCH -->|"notifies_via"| EMAIL
    SACH -->|"queries_db"| DB

    RBCH -->|"validates_with"| DOM
    SACH -->|"gets_info_from"| DOM

    BRE -->|"handled_by"| RBCH

    BEH -->|"implements_using"| CLOCK

    DOCKER -->|"builds_container_for"| API
    DOCKER -->|"builds_container_for"| APP
    DC -->|"orchestrates"| DOCKER
    DC -->|"orchestrates"| INF

    %% Click Events
    click API "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Api"
    click AC "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Api/Controllers/Apartments/ApartmentsController.cs"
    click BC "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Api/Controllers/Bookings/BookingsController.cs"
    click APP "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Application"
    click RBCH "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Application/Bookings/ReserveBooking/ReserveBookingCommandHandler.cs"
    click SACH "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Application/Apartments/SearchApartments/SearchApartmentsQueryHandler.cs"
    click BEH "https://github.com/rsmacias/bookify/tree/main/src/Bookify.Application/Abstractions/Behaviors"
    click DOM "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Domain"
    click APT "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Domain/Apartments/Apartment.cs"
    click BK "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Domain/Bookings/Booking.cs"
    click BRE "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Domain/Bookings/Events/BookingReservedDomainEvent.cs"
    click INF "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Infrastructure"
    click DB "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Infrastructure/ApplicationDbContext.cs"
    click BR "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Infrastructure/Repositories/BookingRepository.cs"
    click EMAIL "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Infrastructure/Email/EmailService.cs"
    click CLOCK "https://github.com/rsmacias/bookify/blob/main/src/Bookify.Infrastructure/Clock/DateTimeProvider.cs"
    click DOCKER "https://github.com/rsmacias/bookify/tree/main/src/Bookify.Api/Dockerfile"
    click DC "https://github.com/rsmacias/bookify/blob/main/docker-compose.yml"

    %% Styles
    classDef api fill:#F7C6C7,stroke:#333,stroke-width:2px;
    classDef app fill:#C7EFCF,stroke:#333,stroke-width:2px;
    classDef domain fill:#C7D2F7,stroke:#333,stroke-width:2px;
    classDef infra fill:#F7EFC7,stroke:#333,stroke-width:2px;
    classDef deploy fill:#D2C7F7,stroke:#333,stroke-width:2px;
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:2px;
```
