# 2chevskii/zerox2c-blog-backend architecture

> Architecture diagram of the GitHub repository 2chevskii/zerox2c-blog-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/2chevskii/zerox2c-blog-backend
- Repository: https://github.com/2chevskii/zerox2c-blog-backend

## Overview

#### Purpose and Entry Point
This is the backend API for 0x2c.dev: a modular ASP.NET Core 10 blog/CMS service. It exposes public post, image, profile, authentication, comment, and reaction APIs plus role-protected administration APIs. The composition root is `src/ZeroX2C.Blog.API/Program.cs`; solution entry is `ZeroX2C.Blog.slnx`.

#### HTTP and Application Composition
Controller endpoints are grouped by module and delegate to service interfaces rather than exposing persistence directly. Public/admin boundaries are explicit in controller and service layout:
- `src/ZeroX2C.Blog.API/Modules/Posts/Controllers/PostsController.cs`
- `src/ZeroX2C.Blog.API/Modules/Posts/Controllers/AdminPostsController.cs`
- `src/ZeroX2C.Blog.API/Modules/Users/Controllers/AuthController.cs`

`Program.cs` configures middleware, JWT authentication/authorization, EF Core, migrations, bootstrap work, and non-production OpenAPI/Scalar.

#### Posts and Content Management
Posts are the central domain: post metadata/status/slugs/tags support public filtered queries and admin lifecycle operations (create, edit, publish, unpublish, delete). Query and mutation responsibilities are separated:
- `src/ZeroX2C.Blog.API/Modules/Posts/PostQueryService.cs`
- `src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminPostService.cs`
- `src/ZeroX2C.Blog.API/Modules/Posts/Post.cs`

Tags are managed independently for administration and queried publicly, while comments and per-user reactions are post subdomains.

#### Markdown and Image Pipeline
Admin post authoring stores Markdown documents and associated Markdown images. Markdown is rendered server-side through Markdig and sanitized with HtmlSanitizer before output crosses the API boundary:
- `src/ZeroX2C.Blog.API/Modules/Posts/Markdown/MarkdownDocumentRenderer.cs`
- `src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminMarkdownService.cs`
- `src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminPostMarkdownImageService.cs`

General assets—including uploaded images and profile avatars—are persisted in MySQL-backed image storage and retrieved through public image endpoints:
- `src/ZeroX2C.Blog.API/Modules/Assets/Images/AdminImageService.cs`
- `src/ZeroX2C.Blog.API/Modules/Assets/Images/ImageQueryService.cs`

#### Identity, Authorization, and Profiles
Custom identity supports registration/login, JWT issuance, Steam OpenID, roles, blocking, profiles, and admin user management. Authentication context middleware establishes the current actor for authorization and audited writes:
- `src/ZeroX2C.Blog.API/Modules/Users/Auth/AuthService.cs`
- `src/ZeroX2C.Blog.API/Modules/Users/Auth/AuthenticationContextMiddleware.cs`
- `src/ZeroX2C.Blog.API/Modules/Users/Profile/ProfileService.cs`

Authorization includes role policies and a “not blocked” requirement. A system user and superadmin are technical identities, not ordinary login users.

#### Persistence, Auditing, and Startup
EF Core maps all module entities through one MySQL `BlogDbContext`; migrations are applied automatically at API startup. Entity writes require an authenticated context and are stamped by an EF save interceptor:
- `src/ZeroX2C.Blog.API/Persistence/BlogDbContext.cs`
- `src/ZeroX2C.Blog.API/Persistence/Auditing/EntityAuditSaveChangesInterceptor.cs`
- `src/ZeroX2C.Blog.API/CrossCutting/Bootstrap/ApplicationBootstrapper.cs`

Bootstrap handlers run after migrations, using the system context where needed, to initialize the superadmin and Markdown-related state.

#### Runtime and Deployment Boundary
The runtime is ASP.NET Core/.NET 10 with EF Core 9 and Pomelo MySQL integration. MySQL 8.4 is the primary external service, run locally through `docker-compose.yaml`. Container deployment is defined by `Dockerfile`, GitHub Actions deployment automation, and shell scripts:
- `Dockerfile`
- `docker-compose.yaml`
- `.github/workflows/deploy.yml`

Configuration supplies MySQL connection details, JWT issuer/audience/signing key/lifetime, and superadmin bootstrap behavior; production secrets are expected outside checked-in settings.

Main entry points: [`src/ZeroX2C.Blog.API/Persistence/BlogDbContext.cs`](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Persistence/BlogDbContext.cs) (BlogDbContext), [`src/ZeroX2C.Blog.API/Program.cs`](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Program.cs) (API composition root), [`src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminPostService.cs`](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminPostService.cs) (Admin post service), [`src/ZeroX2C.Blog.API/Modules/Posts/PostQueryService.cs`](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/PostQueryService.cs) (Post query service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API Host"]
  node_program{{"API composition root<br/>ASP.NET Core host<br/>[Program.cs]"}}
  node_public_post_api["Public post API<br/>controllers<br/>[PostsController.cs]"]
  node_admin_post_api["Admin post API<br/>controllers"]
  node_auth_api["Auth API<br/>controllers<br/>[AuthController.cs]"]
end

subgraph group_content["Content"]
  node_post_queries["Post query service"]
  node_admin_posts["Admin post service<br/>command service"]
  node_post_domain["Post domain<br/>entity model<br/>[Post.cs]"]
  node_admin_markdown["Admin Markdown service<br/>authoring service"]
  node_markdown_images["Markdown image service<br/>authoring service"]
  node_markdown_renderer["Sanitized Markdown renderer<br/>rendering service"]
  node_image_admin["Image upload service<br/>asset service"]
  node_image_queries["Public image service<br/>asset query service"]
end

subgraph group_identity["Identity"]
  node_auth_service["Authentication service<br/>identity service<br/>[AuthService.cs]"]
  node_auth_context["Authentication context<br/>middleware"]
  node_profiles["Profile service<br/>[ProfileService.cs]"]
end

subgraph group_persistence["Persistence"]
  node_db_context[("BlogDbContext<br/>EF Core context<br/>[BlogDbContext.cs]")]
  node_audit_interceptor["Audit write interceptor<br/>EF interceptor"]
  node_bootstrapper["Application bootstrapper<br/>startup service"]
end

subgraph group_runtime["Runtime &amp; Deploy"]
  node_mysql[("MySQL 8.4<br/>external database")]
  node_deployment["Container deployment<br/>Docker and CI"]
end

node_program -->|"hosts"| node_public_post_api
node_program -->|"hosts"| node_admin_post_api
node_program -->|"hosts"| node_auth_api
node_program -->|"configures"| node_auth_context
node_program -->|"configures EF"| node_db_context
node_program -->|"runs after migrations"| node_bootstrapper
node_public_post_api -->|"queries"| node_post_queries
node_admin_post_api -->|"manages"| node_admin_posts
node_auth_api -->|"authenticates"| node_auth_service
node_post_queries -->|"renders content"| node_markdown_renderer
node_post_queries -->|"reads"| node_db_context
node_admin_posts -->|"updates"| node_post_domain
node_admin_posts -->|"authors"| node_admin_markdown
node_admin_markdown -->|"associates"| node_markdown_images
node_admin_posts -->|"writes"| node_db_context
node_image_admin -->|"stores assets"| node_db_context
node_image_queries -->|"retrieves assets"| node_db_context
node_profiles -->|"manages profiles"| node_db_context
node_auth_service -->|"manages identities"| node_db_context
node_auth_context -->|"supplies actor"| node_audit_interceptor
node_audit_interceptor -->|"stamps writes"| node_db_context
node_db_context -->|"Pomelo EF Core"| node_mysql
node_bootstrapper -->|"initializes state"| node_db_context
node_deployment -.->|"runs container"| node_program

click node_program "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Program.cs"
click node_public_post_api "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Controllers/PostsController.cs"
click node_admin_post_api "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Controllers/AdminPostsController.cs"
click node_auth_api "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Users/Controllers/AuthController.cs"
click node_post_queries "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/PostQueryService.cs"
click node_admin_posts "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminPostService.cs"
click node_post_domain "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Post.cs"
click node_admin_markdown "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminMarkdownService.cs"
click node_markdown_images "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminPostMarkdownImageService.cs"
click node_markdown_renderer "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Markdown/MarkdownDocumentRenderer.cs"
click node_image_admin "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Assets/Images/AdminImageService.cs"
click node_image_queries "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Assets/Images/ImageQueryService.cs"
click node_auth_service "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Users/Auth/AuthService.cs"
click node_auth_context "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Users/Auth/AuthenticationContextMiddleware.cs"
click node_profiles "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Users/Profile/ProfileService.cs"
click node_db_context "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Persistence/BlogDbContext.cs"
click node_audit_interceptor "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Persistence/Auditing/EntityAuditSaveChangesInterceptor.cs"
click node_bootstrapper "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/CrossCutting/Bootstrap/ApplicationBootstrapper.cs"
click node_mysql "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/docker-compose.yaml"
click node_deployment "https://github.com/2chevskii/zerox2c-blog-backend/blob/master/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_program,node_public_post_api,node_admin_post_api,node_auth_api toneBlue
class node_post_queries,node_admin_posts,node_post_domain,node_admin_markdown,node_markdown_images,node_markdown_renderer,node_image_admin,node_image_queries toneAmber
class node_auth_service,node_auth_context,node_profiles toneMint
class node_db_context,node_audit_interceptor,node_bootstrapper toneRose
class node_mysql,node_deployment toneIndigo
```

## Components

### API Host

- [API composition root](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Program.cs): ASP.NET Core host · Configures middleware, auth, EF, startup work, and API tooling. · `src/ZeroX2C.Blog.API/Program.cs`
- [Public post API](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Controllers/PostsController.cs): controllers · `src/ZeroX2C.Blog.API/Modules/Posts/Controllers/PostsController.cs`
- [Admin post API](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Controllers/AdminPostsController.cs): controllers · Role-protected post lifecycle endpoints. · `src/ZeroX2C.Blog.API/Modules/Posts/Controllers/AdminPostsController.cs`
- [Auth API](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Users/Controllers/AuthController.cs): controllers · `src/ZeroX2C.Blog.API/Modules/Users/Controllers/AuthController.cs`

### Content

- [Post query service](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/PostQueryService.cs): query service · Provides filtered public post and tag reads. · `src/ZeroX2C.Blog.API/Modules/Posts/PostQueryService.cs`
- [Admin post service](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminPostService.cs): command service · Owns post creation, editing, publication, and deletion. · `src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminPostService.cs`
- [Post domain](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Post.cs): entity model · Posts carry metadata, status, slugs, and tags; comments and reactions are subdomains. · `src/ZeroX2C.Blog.API/Modules/Posts/Post.cs`
- [Admin Markdown service](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminMarkdownService.cs): authoring service · Stores post Markdown documents. · `src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminMarkdownService.cs`
- [Markdown image service](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminPostMarkdownImageService.cs): authoring service · Manages images associated with Markdown content. · `src/ZeroX2C.Blog.API/Modules/Posts/Admin/AdminPostMarkdownImageService.cs`
- [Sanitized Markdown renderer](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Posts/Markdown/MarkdownDocumentRenderer.cs): rendering service · Renders with Markdig and sanitizes HTML before API output. · `src/ZeroX2C.Blog.API/Modules/Posts/Markdown/MarkdownDocumentRenderer.cs`
- [Image upload service](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Assets/Images/AdminImageService.cs): asset service · Persists general images and avatars. · `src/ZeroX2C.Blog.API/Modules/Assets/Images/AdminImageService.cs`
- [Public image service](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Assets/Images/ImageQueryService.cs): asset query service · `src/ZeroX2C.Blog.API/Modules/Assets/Images/ImageQueryService.cs`

### Identity

- [Authentication service](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Users/Auth/AuthService.cs): identity service · Handles local auth, JWT issuance, Steam OpenID, and identity operations. · `src/ZeroX2C.Blog.API/Modules/Users/Auth/AuthService.cs`
- [Authentication context](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Users/Auth/AuthenticationContextMiddleware.cs): middleware · Establishes the current actor for authorization and audited writes. · `src/ZeroX2C.Blog.API/Modules/Users/Auth/AuthenticationContextMiddleware.cs`
- [Profile service](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Modules/Users/Profile/ProfileService.cs): profile service · `src/ZeroX2C.Blog.API/Modules/Users/Profile/ProfileService.cs`

### Persistence

- [BlogDbContext](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Persistence/BlogDbContext.cs): EF Core context · Single context mapping all module entities. · `src/ZeroX2C.Blog.API/Persistence/BlogDbContext.cs`
- [Audit write interceptor](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/Persistence/Auditing/EntityAuditSaveChangesInterceptor.cs): EF interceptor · Stamps entity writes from the authenticated context. · `src/ZeroX2C.Blog.API/Persistence/Auditing/EntityAuditSaveChangesInterceptor.cs`
- [Application bootstrapper](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/src/ZeroX2C.Blog.API/CrossCutting/Bootstrap/ApplicationBootstrapper.cs): startup service · Runs initialization after migrations using system context when required. · `src/ZeroX2C.Blog.API/CrossCutting/Bootstrap/ApplicationBootstrapper.cs`

### Runtime & Deploy

- [MySQL 8.4](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/docker-compose.yaml): external database · Primary database and image storage backend. · `docker-compose.yaml`
- [Container deployment](https://github.com/2chevskii/zerox2c-blog-backend/blob/master/Dockerfile): Docker and CI · Builds the API container and deploys through GitHub Actions. · `Dockerfile`

## Connections

- API composition root → Public post API: hosts
- API composition root → Admin post API: hosts
- API composition root → Auth API: hosts
- API composition root → Authentication context: configures
- API composition root → BlogDbContext: configures EF
- API composition root → Application bootstrapper: runs after migrations
- Public post API → Post query service: queries
- Admin post API → Admin post service: manages
- Auth API → Authentication service: authenticates
- Post query service → Sanitized Markdown renderer: renders content
- Post query service → BlogDbContext: reads
- Admin post service → Post domain: updates
- Admin post service → Admin Markdown service: authors
- Admin Markdown service → Markdown image service: associates
- Admin post service → BlogDbContext: writes
- Image upload service → BlogDbContext: stores assets
- Public image service → BlogDbContext: retrieves assets
- Profile service → BlogDbContext: manages profiles
- Authentication service → BlogDbContext: manages identities
- Authentication context → Audit write interceptor: supplies actor
- Audit write interceptor → BlogDbContext: stamps writes
- BlogDbContext → MySQL 8.4: Pomelo EF Core
- Application bootstrapper → BlogDbContext: initializes state
- Container deployment → API composition root: runs container
