# brewpipeline/blog-server architecture

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

- Interactive diagram: https://gitdiagram.com/brewpipeline/blog-server
- Repository: https://github.com/brewpipeline/blog-server

## Overview

##### Project Type and Purpose
- This is a backend‐only, modular blog platform written in Rust. It exposes a JSON/HTTP API for posts, comments, and author management, applies database migrations on startup, and broadcasts events to Telegram and Discord (optionally via RabbitMQ). The web front-end lives in a separate `blog-ui` repository (server-side rendering supported via a feature).

##### File Structure
- Top-level files:
- Cargo.toml (workspace)
- config.yaml (runtime notifications config)
- index.html (fallback/static file)
- .github/workflows (CI for builds/tests)
- Three workspace crates:
a. blog-server-api
– Entry point (main.rs), HTTP router (router.rs), endpoint modules (`src/endpoints/*`), DB migrations (`src/migrations/*`), authentication & JWT utilities (`src/utils/*`).
b. blog-server-services
– Business‐logic service layer: traits (`src/traits/*`) and implementations (`src/impls/*`) for posts, comments, authors, and event bus (RabbitMQ) plus external integrations (Discord, Telegram).
c. blog-generic
– Shared domain entities (`src/entities/*`), domain events (`src/events/*`), page processing utilities, author/slug helpers.
- Look for architectural patterns:
- Clear separation of HTTP layer (API), service/domain layer, and persistence/events
- Trait-based abstractions for easy replacement/mocking (e.g., Rbatis, RabbitMQ)
- Cargo workspace for modular reuse

##### README for Additional Insights
- Tech stack: Screw ecosystem + Hyper for HTTP, Rbatis + PostgreSQL for the database, RabbitMQ for the event bus.
- Features: Optional SSR, optional Yandex/Telegram login, config‐driven notification channels.
- Startup sequence: apply migrations → connect to RabbitMQ (if available) → listen on SERVER_ADDRESS.
- API path prefix: `/api/*` with standard CRUD routes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Client Layer"
        User["User / blog-ui"]:::external
    end

    %% HTTP/API Layer
    subgraph "HTTP/API Layer"
        API["blog-server-api\n(HTTP Server)"]:::internal
        Router["Router & Middleware"]:::internal
        Endpoints["Endpoints"]:::internal
        Migrations["DB Migrations"]:::internal
        AuthUtils["Auth & JWT Utils"]:::internal
    end

    %% Service Layer
    subgraph "Service Layer"
        ServiceTraits["Trait Interfaces"]:::internal
        ServiceImpls["Service Implementations"]:::internal
        UtilsSL["Service Utils"]:::internal
    end

    %% Domain & Core
    subgraph "Domain & Core"
        Entities["Entities"]:::internal
        Events["Domain Events"]:::internal
        PageProc["Page Processor"]:::internal
    end

    %% Persistence & Messaging
    DB[(PostgreSQL)]:::db
    MQ[(RabbitMQ)]:::mq

    %% External Integrations
    subgraph "External Integrations"
        TeleService["Telegram Bot API"]:::external
        DisService["Discord Webhook"]:::external
    end

    %% Config & CI
    Config["Config (config.yaml & env)"]:::config
    CI["CI/CD Workflows"]:::ci

    %% Connections
    User -->|HTTP Request| API
    API --> Router
    Router --> Endpoints
    Router --> AuthUtils
    Endpoints --> ServiceTraits
    ServiceTraits --> ServiceImpls
    ServiceImpls --> Entities
    ServiceImpls --> Events
    ServiceImpls --> DB
    Events --> MQ
    MQ --> ServiceImpls
    ServiceImpls --> TeleService
    ServiceImpls --> DisService
    API -->|apply migrations| Migrations
    API --> Entities
    API --> Config
    API --> CI

    %% Click Events
    click API "https://github.com/brewpipeline/blog-server/blob/main/blog-server-api/src/main.rs"
    click Router "https://github.com/brewpipeline/blog-server/blob/main/blog-server-api/src/router.rs"
    click Endpoints "https://github.com/brewpipeline/blog-server/tree/main/blog-server-api/src/endpoints/"
    click Migrations "https://github.com/brewpipeline/blog-server/tree/main/blog-server-api/src/migrations/"
    click AuthUtils "https://github.com/brewpipeline/blog-server/blob/main/blog-server-api/src/utils/auth.rs"
    click AuthUtils "https://github.com/brewpipeline/blog-server/blob/main/blog-server-api/src/utils/jwt.rs"
    click AuthUtils "https://github.com/brewpipeline/blog-server/blob/main/blog-server-api/src/utils/password.rs"
    click ServiceTraits "https://github.com/brewpipeline/blog-server/tree/main/blog-server-services/src/traits/"
    click ServiceImpls "https://github.com/brewpipeline/blog-server/tree/main/blog-server-services/src/impls/"
    click UtilsSL "https://github.com/brewpipeline/blog-server/tree/main/blog-server-services/src/utils/"
    click Entities "https://github.com/brewpipeline/blog-server/tree/main/blog-generic/src/entities/"
    click Events "https://github.com/brewpipeline/blog-server/tree/main/blog-generic/src/events/"
    click PageProc "https://github.com/brewpipeline/blog-server/blob/main/blog-generic/src/page_processor.rs"
    click TeleService "https://github.com/brewpipeline/blog-server/blob/main/blog-server-services/src/impls/telegram_new_post_published_service.rs"
    click TeleService "https://github.com/brewpipeline/blog-server/blob/main/blog-server-services/src/impls/telegram_user_updates_service.rs"
    click DisService "https://github.com/brewpipeline/blog-server/blob/main/blog-server-services/src/impls/discord_new_post_published_service.rs"
    click Config "https://github.com/brewpipeline/blog-server/blob/main/config.yaml"
    click CI "https://github.com/brewpipeline/blog-server/blob/main/ .github/workflows/builds.yml"
    click CI "https://github.com/brewpipeline/blog-server/blob/main/ .github/workflows/tests.yml"

    %% Styles
    classDef internal fill:#D5E8D4,stroke:#4CAF50,color:#000
    classDef db fill:#E1F5FE,stroke:#0277BD,color:#000
    classDef mq fill:#FFE0B2,stroke:#FB8C00,color:#000
    classDef external fill:#F5F5F5,stroke:#9E9E9E,color:#000
    classDef config fill:#FCE4EC,stroke:#EC407A,color:#000
    classDef ci fill:#EDE7F6,stroke:#7E57C2,color:#000
```
