# ypathan/blog architecture

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

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

## Overview

This is a Go web application for publishing and administering blog posts. A browser reaches the app through the HTTP router: public requests render or fetch blog content, while admin requests use login-issued cookies and protected routes for management pages and CRUD actions. Handlers delegate persistence to repositories backed by PostgreSQL; authentication handlers also use password hashing and token utilities. The source excerpts show routing and handler-to-repository calls, but do not establish how the browser’s JavaScript consumes every API response, so those links are omitted.

Main entry points: [`main.go`](https://github.com/ypathan/blog/blob/main/main.go) (HTTP router), [`handlers/blogHandlers.go`](https://github.com/ypathan/blog/blob/main/handlers/blogHandlers.go) (Blog handlers), [`handlers/authHandlers.go`](https://github.com/ypathan/blog/blob/main/handlers/authHandlers.go) (Auth handlers), [`repository/blogRepository.go`](https://github.com/ypathan/blog/blob/main/repository/blogRepository.go) (Blog repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["HTTP runtime"]
  node_router["HTTP router<br/>[main.go]"]
  node_dbsetup["Database setup<br/>[dbconn.go]"]
  node_postgres[("PostgreSQL store")]
end

subgraph group_blog["Blog content"]
  node_bloghandlers["Blog handlers<br/>[blogHandlers.go]"]
  node_blogrepo["Blog repository<br/>[blogRepository.go]"]
  node_blogtypes["Blog data types<br/>[blog.go]"]
  node_adminhandlers["Admin handlers<br/>[adminHandlers.go]"]
end

subgraph group_identity["Admin identity"]
  node_authhandlers["Auth handlers<br/>[authHandlers.go]"]
  node_authrepo["Auth repository<br/>[authRepository.go]"]
  node_authutils["Password and tokens<br/>[authUtils.go]"]
  node_authtypes["User data types<br/>[auth.go]"]
end

subgraph group_presentation["Web presentation"]
  node_indexview["Blog index view<br/>[index.gohtml]"]
  node_blogview["Blog detail view<br/>[blog.gohtml]"]
  node_loginview["Admin login view<br/>[adminLogin.gohtml]"]
  node_adminviews["Admin management views"]
  node_staticassets["Static assets"]
end

node_browser(("Browser user"))

node_browser -->|"sends requests"| node_router
node_router -->|"opens database"| node_dbsetup
node_dbsetup -->|"connects and initializes"| node_postgres
node_router -->|"routes blog requests"| node_bloghandlers
node_router -->|"routes auth requests"| node_authhandlers
node_router -->|"routes admin pages"| node_adminhandlers
node_bloghandlers -->|"reads and changes posts"| node_blogrepo
node_adminhandlers -->|"loads admin posts"| node_blogrepo
node_blogrepo -->|"queries posts"| node_postgres
node_authhandlers -->|"reads and updates users"| node_authrepo
node_authhandlers -->|"hashes and verifies credentials"| node_authutils
node_authrepo -->|"queries user records"| node_postgres
node_bloghandlers -->|"renders index"| node_indexview
node_bloghandlers -->|"renders post detail"| node_blogview
node_authhandlers -->|"renders login"| node_loginview
node_adminhandlers -->|"renders admin pages"| node_adminviews
node_router -->|"serves static files"| node_staticassets
node_bloghandlers -->|"uses post data"| node_blogtypes
node_blogrepo -->|"stores post data"| node_blogtypes
node_authhandlers -->|"decodes user data"| node_authtypes
node_authrepo -->|"stores user data"| node_authtypes

click node_router "https://github.com/ypathan/blog/blob/main/main.go"
click node_dbsetup "https://github.com/ypathan/blog/blob/main/database/dbconn.go"
click node_bloghandlers "https://github.com/ypathan/blog/blob/main/handlers/blogHandlers.go"
click node_blogrepo "https://github.com/ypathan/blog/blob/main/repository/blogRepository.go"
click node_blogtypes "https://github.com/ypathan/blog/blob/main/types/blog.go"
click node_adminhandlers "https://github.com/ypathan/blog/blob/main/handlers/adminHandlers.go"
click node_authhandlers "https://github.com/ypathan/blog/blob/main/handlers/authHandlers.go"
click node_authrepo "https://github.com/ypathan/blog/blob/main/repository/authRepository.go"
click node_authutils "https://github.com/ypathan/blog/blob/main/auth/authUtils.go"
click node_authtypes "https://github.com/ypathan/blog/blob/main/types/auth.go"
click node_indexview "https://github.com/ypathan/blog/blob/main/static/index.gohtml"
click node_blogview "https://github.com/ypathan/blog/blob/main/static/blog.gohtml"
click node_loginview "https://github.com/ypathan/blog/blob/main/static/adminLogin.gohtml"
click node_adminviews "https://github.com/ypathan/blog/tree/main/static"
click node_staticassets "https://github.com/ypathan/blog/tree/main/static"

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_router,node_dbsetup,node_postgres,node_browser toneBlue
class node_bloghandlers,node_blogrepo,node_blogtypes,node_adminhandlers toneAmber
class node_authhandlers,node_authrepo,node_authutils,node_authtypes toneMint
class node_indexview,node_blogview,node_loginview,node_adminviews,node_staticassets toneRose
```

## Components

### HTTP runtime

- [HTTP router](https://github.com/ypathan/blog/blob/main/main.go): `main.go`
- [Database setup](https://github.com/ypathan/blog/blob/main/database/dbconn.go): `database/dbconn.go`
- **PostgreSQL store**

### Blog content

- [Blog handlers](https://github.com/ypathan/blog/blob/main/handlers/blogHandlers.go): `handlers/blogHandlers.go`
- [Blog repository](https://github.com/ypathan/blog/blob/main/repository/blogRepository.go): `repository/blogRepository.go`
- [Blog data types](https://github.com/ypathan/blog/blob/main/types/blog.go): `types/blog.go`
- [Admin handlers](https://github.com/ypathan/blog/blob/main/handlers/adminHandlers.go): `handlers/adminHandlers.go`

### Admin identity

- [Auth handlers](https://github.com/ypathan/blog/blob/main/handlers/authHandlers.go): `handlers/authHandlers.go`
- [Auth repository](https://github.com/ypathan/blog/blob/main/repository/authRepository.go): `repository/authRepository.go`
- [Password and tokens](https://github.com/ypathan/blog/blob/main/auth/authUtils.go): `auth/authUtils.go`
- [User data types](https://github.com/ypathan/blog/blob/main/types/auth.go): `types/auth.go`

### Web presentation

- [Blog index view](https://github.com/ypathan/blog/blob/main/static/index.gohtml): `static/index.gohtml`
- [Blog detail view](https://github.com/ypathan/blog/blob/main/static/blog.gohtml): `static/blog.gohtml`
- [Admin login view](https://github.com/ypathan/blog/blob/main/static/adminLogin.gohtml): `static/adminLogin.gohtml`
- [Admin management views](https://github.com/ypathan/blog/tree/main/static): `static`
- [Static assets](https://github.com/ypathan/blog/tree/main/static): `static`

### Other components

- **Browser user**

## Connections

- Browser user → HTTP router: sends requests (evidence: `main.go`)
- HTTP router → Database setup: opens database (evidence: `main.go`)
- Database setup → PostgreSQL store: connects and initializes (evidence: `database/dbconn.go`)
- HTTP router → Blog handlers: routes blog requests (evidence: `main.go`)
- HTTP router → Auth handlers: routes auth requests (evidence: `main.go`)
- HTTP router → Admin handlers: routes admin pages (evidence: `main.go`)
- Blog handlers → Blog repository: reads and changes posts (evidence: `handlers/blogHandlers.go`)
- Admin handlers → Blog repository: loads admin posts (evidence: `handlers/adminHandlers.go`)
- Blog repository → PostgreSQL store: queries posts (evidence: `repository/blogRepository.go`)
- Auth handlers → Auth repository: reads and updates users (evidence: `handlers/authHandlers.go`)
- Auth handlers → Password and tokens: hashes and verifies credentials (evidence: `handlers/authHandlers.go`)
- Auth repository → PostgreSQL store: queries user records (evidence: `repository/authRepository.go`)
- Blog handlers → Blog index view: renders index (evidence: `handlers/blogHandlers.go`)
- Blog handlers → Blog detail view: renders post detail (evidence: `handlers/blogHandlers.go`)
- Auth handlers → Admin login view: renders login (evidence: `handlers/authHandlers.go`)
- Admin handlers → Admin management views: renders admin pages (evidence: `handlers/adminHandlers.go`)
- HTTP router → Static assets: serves static files (evidence: `main.go`)
- Blog handlers → Blog data types: uses post data (evidence: `handlers/blogHandlers.go`)
- Blog repository → Blog data types: stores post data (evidence: `repository/blogRepository.go`)
- Auth handlers → User data types: decodes user data (evidence: `handlers/authHandlers.go`)
- Auth repository → User data types: stores user data (evidence: `repository/authRepository.go`)
