# adamster/lazy-blog architecture

> Architecture diagram of the GitHub repository adamster/lazy-blog, 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/adamster/lazy-blog
- Repository: https://github.com/adamster/lazy-blog

## Overview

##### Main Components

- API/Gateway:
– Components: The “Lazy.Blog.Api” project serves as the entry point. It contains the Program.cs, Startup/configuration (e.g., OpenApi.cs), and service dependency definitions.
– Role: Accepts HTTP requests, binds routes, handles middleware, and forwards requests to underlying layers.

- Presentation Layer:
– Components: “Lazy.Blog.Presentation” contains ApiController abstractions, API contracts (DTOs), and the Controllers (like CommentsController, PostsController, UsersController, etc.).
– Role: This layer is responsible for handling external HTTP requests and responses.

- Application Layer:
– Components: “Lazy.Blog.Application” contains command/query definitions, handlers, validators, and business logic (e.g., commands for adding or deleting posts/comments, media operations, etc.).
– Role: Implements use-case logic, managing business rules, and coordinating between requests from the outer layers and domain logic.

- Domain Layer:
– Components: “Lazy.Blog.Domain” holds the core business entities (Post, Comment, User, MediaItem, etc.), domain events, value objects, and common primitives.
– Role: Encapsulates business rules and domain models. It defines the types, errors, and events that drive the business logic.

- Infrastructure Layer:
– Components: “Lazy.Blog.Infrastructure” provides implementations for external services (e.g., Email sending with SendGrid, JWT authentication, Azure Blob Storage for media). It also contains implementation classes for current user context and idempotence strategies.
– Role: Offers cross-cutting concerns and integrates with third-party systems or external resources.

- Persistence Layer:
– Components: “Lazy.Blog.Persistence” includes EF Core configurations, repositories, migration files, and the database context (LazyBlogDbContext).
– Role: Manages data storage, repository implementations for all domain aggregates, and ensures data is stored and retrieved efficiently.

- Supporting Components:
– Build and CI/CD: The Azure Pipelines YAML files and Docker/Dockerfile indicate containerization and continuous integration/deployment.
– Testing/Documentation: Postman collections and docs directories exist (likely used for API testing and documentation).

##### Relationships and Interactions

- Overall Flow:
– External clients (or API consumers) use HTTP to send requests to the API gateway (Lazy.Blog.Api).
– The API controllers in the Presentation layer receive these requests and translate them (using DTOs) to Application Layer commands/queries.
– The Application layer then coordinates calls to the Domain layer for business rules and to the Infrastructure/Persistence layers for external service calls and database operations.
– Responses flow back from the Domain/Persistence via the Application layer, are transformed into transport objects by the Presentation layer, and then returned to the client.

- Dependency Direction:
– The dependencies flow inward: from Presentation (outermost) → Application → Domain (core) with Infrastructure/Persistence as supporting layers that provide implementations.
– External services (like SMTP for emails via SendGrid, Azure Blob Storage) interact with the Infrastructure layer.

##### Architectural Patterns and Design Principles

- Domain-Driven Design (DDD): The separation into Domain, Application, Infrastructure, and Persistence clearly reflects a DDD approach.
- Command/Query Responsibility Segregation (CQRS) patterns: The Application layer is segmented into commands (e.g., CreatePostCommand, AddCommentCommand) and queries (e.g., GetPostByIdQuery, GetPublishedPostsQuery).
- Clean Architecture: The explicit separation of concerns helps to build a system that is both maintainable and testable.
- Use of Dependency Injection: Evident by extension methods and options setup files (e.g., for JWT and Azure Blob Storage) used in the API project.

##### Relevant Technologies and Frameworks

- .NET (C#): This is a .NET-based project using the typical layered architecture.
- Entity Framework Core: Used for ORM, as seen in Persistence with migrations and DbContext.
- Docker: Containerization is enabled through the provided Docker configuration files.
- Azure Services: Integration with Azure Blob Storage and Application Insights.
- SendGrid: For email services.
- Postman: Collections are provided indicating API testing and documentation.
- CI/CD: Azure Pipelines for continuous integration and deployment.

##### Elements

- Create distinct nodes for each component: API Gateway (Lazy.Blog.Api), Presentation (Controllers & Contracts), Application (Commands, Handlers, Validators), Domain (Entities, Domain Events, Value Objects), Infrastructure (Authentication, Services, Storage), and Persistence (EF Core DbContext, Repositories).
- With Key Technologies:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Flow
    Client["External Client"]:::client

    subgraph "API Gateway Layer"
        API["API Gateway (Lazy.Blog.Api)"]:::api
    end

    subgraph "Presentation Layer"
        Presentation["Presentation (Lazy.Blog.Presentation)"]:::presentation
    end

    subgraph "Application Layer"
        Application["Application (Lazy.Blog.Application)"]:::application
    end

    subgraph "Domain Layer"
        Domain["Domain (Lazy.Blog.Domain)"]:::domain
    end

    subgraph "Infrastructure Layer"
        Infra["Infrastructure (Lazy.Blog.Infrastructure)"]:::infrastructure
    end

    subgraph "Persistence Layer"
        Persistence["Persistence (Lazy.Blog.Persistence)"]:::persistence
    end

    %% Supporting Components: CI/CD & Containerization
    subgraph "CI/CD & Containerization"
        Pip1["Azure Pipelines (azure-pipelines.yml)"]:::ci
        Pip2["Azure Pipelines (azure-pipelines-1.yml)"]:::ci
        Docker["Docker (src/Dockerfile)"]:::ci
    end

    %% Supporting Components: Testing & Documentation
    subgraph "Testing & Documentation"
        Postman["Postman (postman)"]:::testing
        Docs["Documentation (docs)"]:::testing
    end

    %% Main Connections (vertical flow)
    Client -->|"HTTP-Request"| API
    API -->|"Routing/Middleware"| Presentation
    Presentation -->|"DTOs/APIContracts"| Application
    Application -->|"UseCaseLogic"| Domain
    Application -->|"ServiceCalls"| Infra
    Application -->|"DataOperations"| Persistence

    %% Infrastructure Internal External Services
    Infra -->|"Email(SendGrid)"| EmailService["Email Service (SendGrid)"]:::infrastructure
    Infra -->|"Auth(JWT)"| AuthService["Authentication (JWT)"]:::infrastructure
    Infra -->|"Storage(AzureBlob)"| StorageService["Storage Service (Azure Blob)"]:::infrastructure

    %% Supporting Components Connections (dashed)
    Pip1 --- API
    Pip2 --- API
    Docker --- Infra
    Postman --- API
    Docs --- Presentation

    %% Click Events
    click API "https://github.com/adamster/lazy-blog/blob/main/src/Lazy.Blog.Api"
    click Presentation "https://github.com/adamster/lazy-blog/blob/main/src/Lazy.Blog.Presentation"
    click Application "https://github.com/adamster/lazy-blog/blob/main/src/Lazy.Blog.Application"
    click Domain "https://github.com/adamster/lazy-blog/blob/main/src/Lazy.Blog.Domain"
    click Infra "https://github.com/adamster/lazy-blog/blob/main/src/Lazy.Blog.Infrastructure"
    click Persistence "https://github.com/adamster/lazy-blog/blob/main/src/Lazy.Blog.Persistence"
    click Pip1 "https://github.com/adamster/lazy-blog/blob/main/azure-pipelines.yml"
    click Pip2 "https://github.com/adamster/lazy-blog/blob/main/azure-pipelines-1.yml"
    click Docker "https://github.com/adamster/lazy-blog/tree/main/src/Dockerfile"
    click Postman "https://github.com/adamster/lazy-blog/tree/main/postman"
    click Docs "https://github.com/adamster/lazy-blog/tree/main/docs"

    %% Style Classes
    classDef client fill:#fff2cc,stroke:#d4a017,stroke-width:2px;
    classDef api fill:#FFCCCC,stroke:#FF0000,stroke-width:2px;
    classDef presentation fill:#CCFFCC,stroke:#00AA00,stroke-width:2px;
    classDef application fill:#CCCCFF,stroke:#0000FF,stroke-width:2px;
    classDef domain fill:#FFFFCC,stroke:#FFAA00,stroke-width:2px;
    classDef infrastructure fill:#CCE5FF,stroke:#3399FF,stroke-width:2px;
    classDef persistence fill:#E6CCFF,stroke:#9933FF,stroke-width:2px;
    classDef ci fill:#D9EDF7,stroke:#31708F,stroke-width:2px;
    classDef testing fill:#F2DEDE,stroke:#A94442,stroke-width:2px;
```
