# zifrit/gomicroblog architecture

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

- Interactive diagram: https://gitdiagram.com/zifrit/gomicroblog
- Repository: https://github.com/zifrit/gomicroblog

## Overview

MicroBlog is a small in-memory Go REST service for registering users, publishing and listing posts, and asynchronously applying likes. Requests enter through the HTTP server and handlers, which call the service or submit validated like jobs; a worker applies queued likes. The service maintains synchronized state and publishes events to an asynchronous stdout logger. The README also documents Go pprof. Runtime wiring is shown from the sampled entry point; peripheral implementation details are omitted.

Main entry points: [`internal/service/service.go`](https://github.com/zifrit/gomicroblog/blob/master/internal/service/service.go) (Blog service), [`cmd/main.go`](https://github.com/zifrit/gomicroblog/blob/master/cmd/main.go) (HTTP server), [`internal/handlers/register_handler.go`](https://github.com/zifrit/gomicroblog/blob/master/internal/handlers/register_handler.go) (API routes), [`internal/logger/logger.go`](https://github.com/zifrit/gomicroblog/blob/master/internal/logger/logger.go) (Event logger)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime wiring"]
  node_server["HTTP server<br/>[main.go]"]
  node_profiler["pprof endpoint<br/>[main.go]"]
end

subgraph group_api["HTTP API"]
  node_routes["API routes"]
  node_registration["User registration"]
  node_post_api["Post endpoints<br/>[posts_handler.go]"]
  node_like_api["Like endpoint<br/>[like_handler.go]"]
end

subgraph group_domain["Blog domain"]
  node_service["Blog service<br/>[service.go]"]
  node_memory[("In-memory state<br/>[service.go]")]
  node_models["User and post<br/>[models.go]"]
  node_id_counter["Post ID counter<br/>[counter.go]"]
end

subgraph group_async["Async operations"]
  node_like_queue["Like queue<br/>[like_queue.go]"]
  node_like_worker["Like worker<br/>[like_queue.go]"]
  node_event_logger["Event logger<br/>[logger.go]"]
end

node_client(("HTTP client"))
node_stdout(("stdout"))

node_server -->|"mounts routes"| node_routes
node_server -->|"mounts pprof"| node_profiler
node_client -->|"sends requests"| node_server
node_routes -->|"routes registration"| node_registration
node_routes -->|"routes posts"| node_post_api
node_routes -->|"routes post actions"| node_like_api
node_registration -->|"registers user"| node_service
node_post_api -->|"creates or lists"| node_service
node_like_api -->|"validates like"| node_service
node_like_api -->|"submits job"| node_like_queue
node_service -->|"reads and writes"| node_memory
node_service -->|"uses models"| node_models
node_service -->|"allocates IDs"| node_id_counter
node_server -->|"initializes"| node_service
node_server -->|"configures worker"| node_like_queue
node_like_queue -->|"dispatches jobs"| node_like_worker
node_server -->|"worker calls likes"| node_service
node_service -->|"publishes events"| node_event_logger
node_server -->|"initializes logger"| node_event_logger
node_server -->|"logs queue failures"| node_event_logger
node_event_logger -->|"writes events"| node_stdout
node_client -->|"requests profiles"| node_profiler

click node_server "https://github.com/zifrit/gomicroblog/blob/master/cmd/main.go"
click node_profiler "https://github.com/zifrit/gomicroblog/blob/master/cmd/main.go"
click node_routes "https://github.com/zifrit/gomicroblog/blob/master/internal/handlers/register_handler.go"
click node_registration "https://github.com/zifrit/gomicroblog/blob/master/internal/handlers/register_handler.go"
click node_post_api "https://github.com/zifrit/gomicroblog/blob/master/internal/handlers/posts_handler.go"
click node_like_api "https://github.com/zifrit/gomicroblog/blob/master/internal/handlers/like_handler.go"
click node_service "https://github.com/zifrit/gomicroblog/blob/master/internal/service/service.go"
click node_memory "https://github.com/zifrit/gomicroblog/blob/master/internal/service/service.go"
click node_models "https://github.com/zifrit/gomicroblog/blob/master/internal/models/models.go"
click node_id_counter "https://github.com/zifrit/gomicroblog/blob/master/internal/syncutils/counter.go"
click node_like_queue "https://github.com/zifrit/gomicroblog/blob/master/internal/queue/like_queue.go"
click node_like_worker "https://github.com/zifrit/gomicroblog/blob/master/internal/queue/like_queue.go"
click node_event_logger "https://github.com/zifrit/gomicroblog/blob/master/internal/logger/logger.go"

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_server,node_profiler,node_client toneBlue
class node_routes,node_registration,node_post_api,node_like_api toneAmber
class node_service,node_memory,node_models,node_id_counter toneMint
class node_like_queue,node_like_worker,node_event_logger toneRose
class node_stdout toneIndigo
```

## Components

### Runtime wiring

- [HTTP server](https://github.com/zifrit/gomicroblog/blob/master/cmd/main.go): `cmd/main.go`
- [pprof endpoint](https://github.com/zifrit/gomicroblog/blob/master/cmd/main.go): `cmd/main.go`

### HTTP API

- [API routes](https://github.com/zifrit/gomicroblog/blob/master/internal/handlers/register_handler.go): `internal/handlers/register_handler.go`
- [User registration](https://github.com/zifrit/gomicroblog/blob/master/internal/handlers/register_handler.go): `internal/handlers/register_handler.go`
- [Post endpoints](https://github.com/zifrit/gomicroblog/blob/master/internal/handlers/posts_handler.go): `internal/handlers/posts_handler.go`
- [Like endpoint](https://github.com/zifrit/gomicroblog/blob/master/internal/handlers/like_handler.go): `internal/handlers/like_handler.go`

### Blog domain

- [Blog service](https://github.com/zifrit/gomicroblog/blob/master/internal/service/service.go): `internal/service/service.go`
- [In-memory state](https://github.com/zifrit/gomicroblog/blob/master/internal/service/service.go): `internal/service/service.go`
- [User and post](https://github.com/zifrit/gomicroblog/blob/master/internal/models/models.go): `internal/models/models.go`
- [Post ID counter](https://github.com/zifrit/gomicroblog/blob/master/internal/syncutils/counter.go): `internal/syncutils/counter.go`

### Async operations

- [Like queue](https://github.com/zifrit/gomicroblog/blob/master/internal/queue/like_queue.go): `internal/queue/like_queue.go`
- [Like worker](https://github.com/zifrit/gomicroblog/blob/master/internal/queue/like_queue.go): `internal/queue/like_queue.go`
- [Event logger](https://github.com/zifrit/gomicroblog/blob/master/internal/logger/logger.go): `internal/logger/logger.go`

### Other components

- **HTTP client**
- **stdout**

## Connections

- HTTP server → API routes: mounts routes (evidence: `cmd/main.go`)
- HTTP server → pprof endpoint: mounts pprof (evidence: `cmd/main.go`)
- HTTP client → HTTP server: sends requests (evidence: `README.md`)
- API routes → User registration: routes registration (evidence: `internal/handlers/register_handler.go`)
- API routes → Post endpoints: routes posts (evidence: `internal/handlers/register_handler.go`)
- API routes → Like endpoint: routes post actions (evidence: `internal/handlers/register_handler.go`)
- User registration → Blog service: registers user (evidence: `internal/handlers/register_handler.go`)
- Post endpoints → Blog service: creates or lists (evidence: `internal/handlers/posts_handler.go`)
- Like endpoint → Blog service: validates like (evidence: `internal/handlers/like_handler.go`)
- Like endpoint → Like queue: submits job (evidence: `internal/handlers/like_handler.go`)
- Blog service → In-memory state: reads and writes (evidence: `internal/service/service.go`)
- Blog service → User and post: uses models (evidence: `internal/service/service.go`)
- Blog service → Post ID counter: allocates IDs (evidence: `internal/service/service.go`)
- HTTP server → Blog service: initializes (evidence: `cmd/main.go`)
- HTTP server → Like queue: configures worker (evidence: `cmd/main.go`)
- Like queue → Like worker: dispatches jobs (evidence: `internal/queue/like_queue.go`)
- HTTP server → Blog service: worker calls likes (evidence: `cmd/main.go`)
- Blog service → Event logger: publishes events (evidence: `internal/service/service.go`)
- HTTP server → Event logger: initializes logger (evidence: `cmd/main.go`)
- HTTP server → Event logger: logs queue failures (evidence: `cmd/main.go`)
- Event logger → stdout: writes events (evidence: `internal/logger/logger.go`)
- HTTP client → pprof endpoint: requests profiles (evidence: `README.md`)
