# dheeraj-gurramkonda/snippetbox architecture

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

- Interactive diagram: https://gitdiagram.com/dheeraj-gurramkonda/snippetbox
- Repository: https://github.com/dheeraj-gurramkonda/snippetbox

## Overview

Snippetbox is a server-rendered Go application for publishing expiring text snippets and managing user accounts. A browser request reaches the HTTPS server and route middleware, then page handlers validate forms or retrieve data through snippet and user models; handlers render pages or redirect with session messages. Signup, login, authenticated snippet creation, logout, CSRF protection, health checks, and embedded static files are distinct capabilities. The graph follows documented routes and sampled calls; unsampled details are represented only where the README establishes them.

Main entry points: [`cmd/web/main.go`](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/main.go) (HTTPS server), [`cmd/web/handlers.go`](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/handlers.go) (Page handlers), [`cmd/web/routes.go`](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/routes.go) (Route dispatch), [`internal/models/users.go`](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/internal/models/users.go) (User model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_server["HTTPS server<br/>[main.go]"]
  node_routes["Route dispatch<br/>[routes.go]"]
  node_middleware["Request middleware<br/>[middleware.go]"]
  node_handlers["Page handlers<br/>[handlers.go]"]
  node_validation["Form validation<br/>[validator.go]"]
end

subgraph group_identity["Accounts and sessions"]
  node_usermodel["User model<br/>[users.go]"]
  node_sessions["Session manager<br/>[main.go]"]
end

subgraph group_content["Snippet publishing"]
  node_snippetmodel["Snippet model<br/>[snippet.go]"]
end

subgraph group_presentation["Page delivery"]
  node_rendering["Render helpers<br/>[helpers.go]"]
  node_templatecache["Template cache<br/>[templates.go]"]
  node_html["HTML templates"]
  node_static["Static assets"]
end

node_visitor(("Browser visitor"))
node_mysql[("MySQL database")]
node_sessionstore[("MySQL session store")]

node_visitor -->|"sends HTTPS"| node_server
node_server -->|"serves through"| node_routes
node_routes -->|"wraps requests"| node_middleware
node_routes -->|"dispatches to"| node_handlers
node_routes -->|"serves files"| node_static
node_middleware -->|"loads and saves"| node_sessions
node_middleware -->|"checks account"| node_usermodel
node_handlers -->|"checks fields"| node_validation
node_handlers -->|"reads and writes"| node_snippetmodel
node_handlers -->|"registers and authenticates"| node_usermodel
node_handlers -->|"updates session"| node_sessions
node_handlers -->|"renders pages"| node_rendering
node_templatecache -->|"parses templates"| node_html
node_server -->|"builds cache"| node_templatecache
node_server -->|"configures manager"| node_sessions
node_server -->|"configures model"| node_snippetmodel
node_server -->|"configures model"| node_usermodel
node_snippetmodel -->|"queries"| node_mysql
node_usermodel -->|"queries"| node_mysql
node_sessions -->|"stores sessions"| node_sessionstore
node_sessionstore -.->|"persists in"| node_mysql

click node_server "https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/main.go"
click node_routes "https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/routes.go"
click node_middleware "https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/middleware.go"
click node_handlers "https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/handlers.go"
click node_validation "https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/internal/validator/validator.go"
click node_rendering "https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/helpers.go"
click node_templatecache "https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/templates.go"
click node_html "https://github.com/dheeraj-gurramkonda/snippetbox/tree/main/assets/html"
click node_static "https://github.com/dheeraj-gurramkonda/snippetbox/tree/main/assets/static"
click node_snippetmodel "https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/internal/models/snippet.go"
click node_usermodel "https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/internal/models/users.go"
click node_sessions "https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/main.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_routes,node_middleware,node_handlers,node_validation,node_visitor toneBlue
class node_usermodel,node_sessions,node_mysql,node_sessionstore toneAmber
class node_snippetmodel toneMint
class node_rendering,node_templatecache,node_html,node_static toneRose
```

## Components

### Web application

- [HTTPS server](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/main.go): `cmd/web/main.go`
- [Route dispatch](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/routes.go): `cmd/web/routes.go`
- [Request middleware](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/middleware.go): `cmd/web/middleware.go`
- [Page handlers](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/handlers.go): `cmd/web/handlers.go`
- [Form validation](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/internal/validator/validator.go): `internal/validator/validator.go`

### Accounts and sessions

- [User model](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/internal/models/users.go): `internal/models/users.go`
- [Session manager](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/main.go): `cmd/web/main.go`

### Snippet publishing

- [Snippet model](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/internal/models/snippet.go): `internal/models/snippet.go`

### Page delivery

- [Render helpers](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/helpers.go): `cmd/web/helpers.go`
- [Template cache](https://github.com/dheeraj-gurramkonda/snippetbox/blob/main/cmd/web/templates.go): `cmd/web/templates.go`
- [HTML templates](https://github.com/dheeraj-gurramkonda/snippetbox/tree/main/assets/html): `assets/html`
- [Static assets](https://github.com/dheeraj-gurramkonda/snippetbox/tree/main/assets/static): `assets/static`

### Other components

- **Browser visitor**
- **MySQL database**
- **MySQL session store**

## Connections

- Browser visitor → HTTPS server: sends HTTPS (evidence: `README.md`)
- HTTPS server → Route dispatch: serves through (evidence: `cmd/web/main.go`)
- Route dispatch → Request middleware: wraps requests (evidence: `cmd/web/routes.go`)
- Route dispatch → Page handlers: dispatches to (evidence: `cmd/web/routes.go`)
- Route dispatch → Static assets: serves files (evidence: `cmd/web/routes.go`)
- Request middleware → Session manager: loads and saves
- Request middleware → User model: checks account (evidence: `cmd/web/middleware.go`)
- Page handlers → Form validation: checks fields (evidence: `cmd/web/handlers.go`)
- Page handlers → Snippet model: reads and writes (evidence: `cmd/web/handlers.go`)
- Page handlers → User model: registers and authenticates (evidence: `cmd/web/handlers.go`)
- Page handlers → Session manager: updates session (evidence: `cmd/web/handlers.go`)
- Page handlers → Render helpers: renders pages (evidence: `cmd/web/handlers.go`)
- Template cache → HTML templates: parses templates (evidence: `cmd/web/templates.go`)
- HTTPS server → Template cache: builds cache (evidence: `cmd/web/main.go`)
- HTTPS server → Session manager: configures manager (evidence: `cmd/web/main.go`)
- HTTPS server → Snippet model: configures model (evidence: `cmd/web/main.go`)
- HTTPS server → User model: configures model (evidence: `cmd/web/main.go`)
- Snippet model → MySQL database: queries (evidence: `internal/models/snippet.go`)
- User model → MySQL database: queries (evidence: `internal/models/users.go`)
- Session manager → MySQL session store: stores sessions (evidence: `cmd/web/main.go`)
- MySQL session store → MySQL database: persists in
