# greatsluggard/logandstore architecture

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

- Interactive diagram: https://gitdiagram.com/greatsluggard/logandstore
- Repository: https://github.com/greatsluggard/logandstore

## Overview

##### Main Components
- API Layer (LogAndStore.API): Contains the controllers (MyDataController, RequestLogController) that expose endpoints. This layer handles HTTP requests and responses, and integrates Swagger for API documentation.
- Application Layer (LogAndStore.Application): Contains business logic, dependency injection configurations, mapping profiles (using AutoMapper), and service implementations (e.g., MyDataService and RequestLoggerService). This layer orchestrates requests between the API and Data Access layers.
- Data Access Layer (LogAndStore.DAL): Responsible for database connections and operations. It includes the Entity Framework Core context (ApplicationDbContext), migration scripts, repository implementations, and configurations (such as MyDataConfiguration and RequestLogConfiguration).
- Domain Layer (LogAndStore.Domain): Defines the core entities (MyData, RequestLog), Data Transfer Objects (DTOs), and interfaces. This layer encapsulates business models and contracts.
- External Components: PostgreSQL (as the database) deployed via Docker, and Docker infrastructure orchestration via docker-compose. Swagger UI and logging via request logs to the RequestLogs table are also key external/interface elements.

##### Relationships and Interactions
- The API Layer receives HTTP requests and uses dependency-injected services from the Application Layer.
- The Application Layer uses AutoMapper for DTO to Entity conversions and interacts with the DAL for storage and retrieval.
- The DAL interacts with PostgreSQL via Entity Framework Core for data persistence and applies migrations at startup (managed by MigrationHostedService).
- The Domain Layer provides the essential business objects and interfaces that guide both the Application and DAL layers.
- Docker orchestrates the entire environment, spinning up the Web API application and PostgreSQL container, ensuring they work together.

##### Architectural Patterns and Design Principles
- Layered Architecture: Clear separation into API, Application, DAL, and Domain layers improves maintainability and testability.
- Dependency Injection: Both the Application and DAL projects provide DI configurations, promoting loose coupling.
- Repository Pattern: Used within the DAL to encapsulate data access logic, interfacing with EF Core.
- AutoMapper Integration: Simplifies object mapping between Entities and DTOs.
- Containerization: Docker and docker-compose are used to containerize the application along with PostgreSQL, ensuring consistency across environments.
- EF Core Migrations: Automatic migrations at startup ensure the database schema is updated as needed.

##### Relevant Technologies, Frameworks, and Libraries
- ASP.NET Core 8 for building the Web API.
- Entity Framework Core 9 for ORM and migrations.
- PostgreSQL as the primary database.
- Swagger UI for API documentation.
- AutoMapper for object-to-object mapping.
- Docker & docker-compose for containerized deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Docker Containerization
    subgraph "Containerization"
        direction TB
        G("Dockerfile"):::docker
        F("docker-compose.yml"):::docker
    end

    %% API Layer
    subgraph "API Layer (LogAndStore.API)"
        direction TB
        A1("MyDataController"):::controller
        A2("RequestLogController"):::controller
        A3("Program.cs (Swagger)"):::program
    end

    %% Application Layer
    subgraph "Application Layer (LogAndStore.Application)"
        direction TB
        B1("DependencyInjection.cs"):::di
        B2("MyDataMappingProfile.cs"):::mapping
        B3("MyDataService"):::service
        B4("RequestLoggerService"):::service
    end

    %% Data Access Layer
    subgraph "Data Access Layer (LogAndStore.DAL)"
        direction TB
        C1("ApplicationDbContext"):::database
        C2("Migrations"):::migration
        C3("BaseRepository.cs"):::repository
        C4("MyDataConfiguration"):::configuration
        C5("RequestLogConfiguration"):::configuration
        C6("MigrationHostedService"):::service
    end

    %% Domain Layer
    subgraph "Domain Layer (LogAndStore.Domain)"
        direction TB
        D1("MyData Entity"):::entity
        D2("RequestLog Entity"):::entity
        D3("DTOs (Input/Output/RequestLog)"):::dto
        D4("Interfaces (Repositories/Services)"):::interface
    end

    %% External Database
    E(["PostgreSQL Database"]):::pgsql

    %% Connections across layers
    A1 -->|"HTTP_Request"| B3
    A2 -->|"HTTP_Request"| B4
    A3 -->|"SwaggerUI"| A1

    B1 -->|"Registers"| B3
    B1 -->|"Registers"| B4
    B2 -->|"Mapping"| D3
    B3 -->|"ServiceCall"| C3
    B4 -->|"LogEntry"| C3
    B3 -.->|"Validates"| D1
    B4 -.->|"Validates"| D2

    C2 -->|"Migrates"| C1
    C3 -->|"RepoAccess"| C1
    C4 --> C1
    C5 --> C1
    C6 -->|"ExecutesMigration"| C1

    C1 <-->|"EFCoreOps"| E

    %% Containerization connections
    A3 -->|"DockerBuild"| G
    G -->|"Orchestrates"| F

    %% Click Events for API Layer
    click A1 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.API/Controllers/MyDataController.cs"
    click A2 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.API/Controllers/RequestLogController.cs"
    click A3 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.API/Program.cs"

    %% Click Events for Application Layer
    click B1 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.Application/DependencyInjection/DependencyInjection.cs"
    click B2 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.Application/Mapping/MyDataMappingProfile.cs"
    click B3 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.Application/Services/MyDataService.cs"
    click B4 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.Application/Services/RequestLoggerService.cs"

    %% Click Events for Data Access Layer
    click C1 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.DAL/ApplicationDbContext.cs"
    click C3 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.DAL/Repositories/BaseRepository.cs"
    click C4 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.DAL/Configurations/MyDataConfiguration.cs"
    click C5 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.DAL/Configurations/RequestLogConfiguration.cs"
    click C6 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.DAL/Services/MigrationHostedService.cs"

    %% Click Events for Domain Layer
    click D1 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.Domain/Entities/MyData.cs"
    click D2 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.Domain/Entities/RequestLog.cs"
    click D3 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.Domain/DTO/InputMyDataDto.cs"
    click D3 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.Domain/DTO/OutputMyDataDto.cs"
    click D3 "https://github.com/greatsluggard/logandstore/blob/main/LogAndStore.Domain/DTO/RequestLogDto.cs"
    click D4 "https://github.com/greatsluggard/logandstore/tree/main/LogAndStore.Domain/Interfaces"

    %% Click Events for Containerization Files
    click G "https://github.com/greatsluggard/logandstore/tree/main/LogAndStore.API/Dockerfile"
    click F "https://github.com/greatsluggard/logandstore/blob/main/docker-compose.yml"

    %% Styles
    classDef controller fill:#f9c,stroke:#333,stroke-width:2px;
    classDef program fill:#ff9,stroke:#333,stroke-width:2px;
    classDef di fill:#ccf,stroke:#333,stroke-width:2px;
    classDef mapping fill:#9cf,stroke:#333,stroke-width:2px;
    classDef service fill:#fc9,stroke:#333,stroke-width:2px;
    classDef migration fill:#cfc,stroke:#333,stroke-width:2px;
    classDef repository fill:#cff,stroke:#333,stroke-width:2px;
    classDef configuration fill:#fcf,stroke:#333,stroke-width:2px;
    classDef database fill:#eef,stroke:#333,stroke-width:2px;
    classDef entity fill:#9f9,stroke:#333,stroke-width:2px;
    classDef dto fill:#cf9,stroke:#333,stroke-width:2px;
    classDef interface fill:#f99,stroke:#333,stroke-width:2px;
    classDef pgsql fill:#ffcccc,stroke:#aa0000,stroke-width:2px;
    classDef docker fill:#ddd,stroke:#333,stroke-width:2px;
```
