# sven-seyfert/secure-web-auth-template architecture

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

- Interactive diagram: https://gitdiagram.com/sven-seyfert/secure-web-auth-template
- Repository: https://github.com/sven-seyfert/secure-web-auth-template

## Overview

Secure Web Auth Template is a compact browser-based authentication app. A user interacts with the web UI to register, log in, use a session-and-CSRF-protected action, and log out. The Go API owns those request flows: it validates credentials, hashes passwords, issues cookies, checks authorization, and updates SQLite-backed user/session records. The application entry point initializes storage, serves the UI and routes, and applies security headers. The README documents capabilities beyond the sampled implementation; those relationships are shown only where documented, and unsampled internals are not inferred.

Main entry points: [`internal/api/routes.go`](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go) (Login flow), [`internal/storage/db.go`](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/storage/db.go) (User and session storage), [`main.go`](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/main.go) (HTTP server entry), [`web/index.html`](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/web/index.html) (Auth UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser interface"]
  node_ui["Auth UI<br/>[index.html]"]
  node_browser_logic["Form and cookie logic<br/>[main.js]"]
end

subgraph group_http["HTTP application"]
  node_server["HTTP server entry<br/>[main.go]"]
  node_api["API routes and handlers<br/>[routes.go]"]
  node_security["Security headers<br/>[routes.go]"]
end

subgraph group_identity["Identity and sessions"]
  node_registration["Registration flow<br/>[routes.go]"]
  node_login["Login flow<br/>[routes.go]"]
  node_protected["Protected action<br/>[routes.go]"]
  node_logout["Logout flow<br/>[routes.go]"]
  node_authorization["Session and CSRF checks<br/>[authorize.go]"]
  node_session_cookies["Token and cookie handling<br/>[session.go]"]
  node_credential_rules["Credential validation<br/>[utils.go]"]
  node_password_hashing["Password hashing<br/>[utils.go]"]
  node_token_generation["Random token generation<br/>[utils.go]"]
end

subgraph group_persistence["User persistence"]
  node_user_store[("User and session storage<br/>[db.go]")]
  node_sqlite[("SQLite")]
end

node_user(("Browser user"))

node_user -->|"uses"| node_ui
node_ui -.->|"loads"| node_browser_logic
node_browser_logic -->|"submits requests"| node_api
node_server -->|"registers routes"| node_api
node_server -->|"initializes"| node_user_store
node_server -->|"serves assets"| node_ui
node_server -->|"wraps handler"| node_security
node_api -->|"applies headers"| node_security
node_api -->|"routes registration"| node_registration
node_api -->|"routes login"| node_login
node_api -->|"routes protected action"| node_protected
node_api -->|"routes logout"| node_logout
node_registration -->|"validates"| node_credential_rules
node_registration -->|"hashes password"| node_password_hashing
node_registration -->|"creates user"| node_user_store
node_login -->|"validates"| node_credential_rules
node_login -->|"loads user"| node_user_store
node_login -->|"checks hash"| node_password_hashing
node_login -->|"issues cookies"| node_session_cookies
node_login -->|"requests tokens"| node_token_generation
node_login -->|"stores session"| node_user_store
node_protected -->|"requires authorization"| node_authorization
node_authorization -->|"loads user"| node_user_store
node_logout -->|"requires authorization"| node_authorization
node_logout -->|"clears cookies"| node_session_cookies
node_logout -->|"clears session"| node_user_store
node_user_store -->|"reads and writes"| node_sqlite

click node_ui "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/web/index.html"
click node_browser_logic "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/web/js/main.js"
click node_server "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/main.go"
click node_api "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go"
click node_security "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go"
click node_registration "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go"
click node_login "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go"
click node_protected "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go"
click node_logout "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go"
click node_authorization "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/auth/authorize.go"
click node_session_cookies "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/auth/session.go"
click node_credential_rules "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/utils/utils.go"
click node_password_hashing "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/utils/utils.go"
click node_token_generation "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/utils/utils.go"
click node_user_store "https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/storage/db.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_ui,node_browser_logic,node_user toneBlue
class node_server,node_api,node_security toneAmber
class node_registration,node_login,node_protected,node_logout,node_authorization,node_session_cookies,node_credential_rules,node_password_hashing,node_token_generation toneMint
class node_user_store,node_sqlite toneRose
```

## Components

### Browser interface

- [Auth UI](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/web/index.html): `web/index.html`
- [Form and cookie logic](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/web/js/main.js): `web/js/main.js`

### HTTP application

- [HTTP server entry](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/main.go): `main.go`
- [API routes and handlers](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go): `internal/api/routes.go`
- [Security headers](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go): `internal/api/routes.go`

### Identity and sessions

- [Registration flow](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go): `internal/api/routes.go`
- [Login flow](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go): `internal/api/routes.go`
- [Protected action](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go): `internal/api/routes.go`
- [Logout flow](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/api/routes.go): `internal/api/routes.go`
- [Session and CSRF checks](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/auth/authorize.go): `internal/auth/authorize.go`
- [Token and cookie handling](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/auth/session.go): `internal/auth/session.go`
- [Credential validation](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/utils/utils.go): `internal/utils/utils.go`
- [Password hashing](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/utils/utils.go): `internal/utils/utils.go`
- [Random token generation](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/utils/utils.go): `internal/utils/utils.go`

### User persistence

- [User and session storage](https://github.com/sven-seyfert/secure-web-auth-template/blob/main/internal/storage/db.go): `internal/storage/db.go`
- **SQLite**

### Other components

- **Browser user**

## Connections

- Browser user → Auth UI: uses (evidence: `README.md`)
- Auth UI → Form and cookie logic: loads
- Form and cookie logic → API routes and handlers: submits requests (evidence: `web/js/main.js`)
- HTTP server entry → API routes and handlers: registers routes (evidence: `main.go`)
- HTTP server entry → User and session storage: initializes (evidence: `main.go`)
- HTTP server entry → Auth UI: serves assets (evidence: `main.go`)
- HTTP server entry → Security headers: wraps handler (evidence: `main.go`)
- API routes and handlers → Security headers: applies headers (evidence: `internal/api/routes.go`)
- API routes and handlers → Registration flow: routes registration (evidence: `internal/api/routes.go`)
- API routes and handlers → Login flow: routes login (evidence: `internal/api/routes.go`)
- API routes and handlers → Protected action: routes protected action (evidence: `internal/api/routes.go`)
- API routes and handlers → Logout flow: routes logout (evidence: `internal/api/routes.go`)
- Registration flow → Credential validation: validates (evidence: `internal/api/routes.go`)
- Registration flow → Password hashing: hashes password (evidence: `internal/api/routes.go`)
- Registration flow → User and session storage: creates user (evidence: `internal/api/routes.go`)
- Login flow → Credential validation: validates (evidence: `internal/api/routes.go`)
- Login flow → User and session storage: loads user (evidence: `internal/api/routes.go`)
- Login flow → Password hashing: checks hash (evidence: `internal/api/routes.go`)
- Login flow → Token and cookie handling: issues cookies (evidence: `internal/api/routes.go`)
- Login flow → Random token generation: requests tokens
- Login flow → User and session storage: stores session (evidence: `internal/api/routes.go`)
- Protected action → Session and CSRF checks: requires authorization (evidence: `internal/api/routes.go`)
- Session and CSRF checks → User and session storage: loads user (evidence: `internal/auth/authorize.go`)
- Logout flow → Session and CSRF checks: requires authorization (evidence: `internal/api/routes.go`)
- Logout flow → Token and cookie handling: clears cookies (evidence: `internal/api/routes.go`)
- Logout flow → User and session storage: clears session (evidence: `internal/api/routes.go`)
- User and session storage → SQLite: reads and writes (evidence: `README.md`)
