# muhafiq/go-web-ssr architecture

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

- Interactive diagram: https://gitdiagram.com/muhafiq/go-web-ssr
- Repository: https://github.com/muhafiq/go-web-ssr

## Overview

This is a learning-oriented Go server-rendered web app: browsers request pages, static assets, and login/logout actions; the server applies middleware, renders templates, and checks login credentials against Turso. The documented scope includes net/http, templates, static files, middleware, sessions, and Turso. Post and user CRUD handlers exist but are empty, so they are not represented as working workflows. The graph follows the sampled routes and source; it does not infer unsampled behavior.

Main entry points: [`main.go`](https://github.com/muhafiq/go-web-ssr/blob/master/main.go) (HTTP server and routes), [`internal/controllers/auth_controller.go`](https://github.com/muhafiq/go-web-ssr/blob/master/internal/controllers/auth_controller.go) (Login and logout), [`internal/controllers/helper.go`](https://github.com/muhafiq/go-web-ssr/blob/master/internal/controllers/helper.go) (Method dispatch), [`internal/middleware/session.go`](https://github.com/muhafiq/go-web-ssr/blob/master/internal/middleware/session.go) (Cookie sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["HTTP and middleware"]
  node_server["HTTP server and routes<br/>[main.go]"]
  node_logger["Request logger<br/>[logging.go]"]
  node_session["Cookie sessions<br/>[session.go]"]
  node_method_routes["Method dispatch<br/>[helper.go]"]
end

subgraph group_render["Server-rendered UI"]
  node_static["Static file serving<br/>[main.go]"]
  node_home["Home page"]
  node_template_helper["Template rendering<br/>[helper.go]"]
  node_views["HTML templates"]
  node_assets["CSS and JavaScript"]
end

subgraph group_auth["Authentication"]
  node_auth_controller["Login and logout<br/>[auth_controller.go]"]
end

subgraph group_data["Persistence"]
  node_user_model["User lookup<br/>[user.go]"]
  node_db_config["Database connection<br/>[database.go]"]
end

node_browser(("Browser"))
node_turso[("Turso database")]

node_browser -->|"sends requests"| node_server
node_server -->|"wraps routes"| node_logger
node_logger -->|"passes requests"| node_session
node_session -->|"passes requests"| node_method_routes
node_server -->|"registers routes"| node_method_routes
node_method_routes -->|"dispatches GET"| node_home
node_method_routes -->|"dispatches methods"| node_auth_controller
node_server -->|"serves assets"| node_static
node_browser -->|"requests files"| node_static
node_home -->|"renders page"| node_template_helper
node_auth_controller -->|"renders login"| node_template_helper
node_template_helper -->|"parses templates"| node_views
node_auth_controller -->|"reads and saves session"| node_session
node_auth_controller -->|"looks up email"| node_user_model
node_user_model -->|"queries database"| node_db_config
node_server -->|"connects database"| node_db_config
node_db_config -->|"opens connection"| node_turso

click node_server "https://github.com/muhafiq/go-web-ssr/blob/master/main.go"
click node_logger "https://github.com/muhafiq/go-web-ssr/blob/master/internal/middleware/logging.go"
click node_session "https://github.com/muhafiq/go-web-ssr/blob/master/internal/middleware/session.go"
click node_method_routes "https://github.com/muhafiq/go-web-ssr/blob/master/internal/controllers/helper.go"
click node_static "https://github.com/muhafiq/go-web-ssr/blob/master/main.go"
click node_home "https://github.com/muhafiq/go-web-ssr/blob/master/internal/controllers/public_controller.go"
click node_auth_controller "https://github.com/muhafiq/go-web-ssr/blob/master/internal/controllers/auth_controller.go"
click node_template_helper "https://github.com/muhafiq/go-web-ssr/blob/master/internal/controllers/helper.go"
click node_views "https://github.com/muhafiq/go-web-ssr/tree/master/views"
click node_assets "https://github.com/muhafiq/go-web-ssr/tree/master/public"
click node_user_model "https://github.com/muhafiq/go-web-ssr/blob/master/internal/models/user.go"
click node_db_config "https://github.com/muhafiq/go-web-ssr/blob/master/internal/config/database.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_logger,node_session,node_method_routes,node_browser toneBlue
class node_static,node_home,node_template_helper,node_views,node_assets,node_turso toneAmber
class node_auth_controller toneMint
class node_user_model,node_db_config toneRose
```

## Components

### HTTP and middleware

- [HTTP server and routes](https://github.com/muhafiq/go-web-ssr/blob/master/main.go): `main.go`
- [Request logger](https://github.com/muhafiq/go-web-ssr/blob/master/internal/middleware/logging.go): `internal/middleware/logging.go`
- [Cookie sessions](https://github.com/muhafiq/go-web-ssr/blob/master/internal/middleware/session.go): `internal/middleware/session.go`
- [Method dispatch](https://github.com/muhafiq/go-web-ssr/blob/master/internal/controllers/helper.go): `internal/controllers/helper.go`

### Server-rendered UI

- [Static file serving](https://github.com/muhafiq/go-web-ssr/blob/master/main.go): `main.go`
- [Home page](https://github.com/muhafiq/go-web-ssr/blob/master/internal/controllers/public_controller.go): `internal/controllers/public_controller.go`
- [Template rendering](https://github.com/muhafiq/go-web-ssr/blob/master/internal/controllers/helper.go): `internal/controllers/helper.go`
- [HTML templates](https://github.com/muhafiq/go-web-ssr/tree/master/views): `views`
- [CSS and JavaScript](https://github.com/muhafiq/go-web-ssr/tree/master/public): `public`

### Authentication

- [Login and logout](https://github.com/muhafiq/go-web-ssr/blob/master/internal/controllers/auth_controller.go): `internal/controllers/auth_controller.go`

### Persistence

- [User lookup](https://github.com/muhafiq/go-web-ssr/blob/master/internal/models/user.go): `internal/models/user.go`
- [Database connection](https://github.com/muhafiq/go-web-ssr/blob/master/internal/config/database.go): `internal/config/database.go`

### Other components

- **Browser**
- **Turso database**

## Connections

- Browser → HTTP server and routes: sends requests
- HTTP server and routes → Request logger: wraps routes
- Request logger → Cookie sessions: passes requests
- Cookie sessions → Method dispatch: passes requests
- HTTP server and routes → Method dispatch: registers routes
- Method dispatch → Home page: dispatches GET
- Method dispatch → Login and logout: dispatches methods
- HTTP server and routes → Static file serving: serves assets
- Browser → Static file serving: requests files
- Home page → Template rendering: renders page
- Login and logout → Template rendering: renders login
- Template rendering → HTML templates: parses templates
- Login and logout → Cookie sessions: reads and saves session
- Login and logout → User lookup: looks up email
- User lookup → Database connection: queries database
- HTTP server and routes → Database connection: connects database
- Database connection → Turso database: opens connection
