# antimatterr/go-oauth architecture

> Architecture diagram of the GitHub repository antimatterr/go-oauth, 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/antimatterr/go-oauth
- Repository: https://github.com/antimatterr/go-oauth

## Overview

This Go service implements Google OAuth sign-in, verifies the returned identity, issues access and refresh tokens, and maintains an in-memory session used to protect the dashboard. The main workflow runs from HTTP routes through the auth handler, with middleware enforcing sessions and templates rendering the landing and dashboard pages. The README is empty; the map relies on the supplied source excerpts and tree. The tree spells the store directory `internal/Store`, while imports use `internal/store`; paths below follow the tree.

Main entry points: [`internal/handlers/googleLogin.go`](https://github.com/antimatterr/go-oauth/blob/main/internal/handlers/googleLogin.go) (Auth handler), [`cmd/api/main.go`](https://github.com/antimatterr/go-oauth/blob/main/cmd/api/main.go) (Route setup), [`internal/middleware/middleware.go`](https://github.com/antimatterr/go-oauth/blob/main/internal/middleware/middleware.go) (Auth middleware), [`internal/Store/sessionStore.go`](https://github.com/antimatterr/go-oauth/blob/main/internal/Store/sessionStore.go) (In-memory sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP application"]
  node_server["HTTP server<br/>[main.go]"]
  node_routes["Route setup<br/>[main.go]"]
end

subgraph group_auth["Authentication"]
  node_handler["Auth handler<br/>[googleLogin.go]"]
  node_config["OAuth config<br/>[config.go]"]
  node_access_jwt["Access JWT<br/>[googleLogin.go]"]
  node_token_utils["Token utilities<br/>[utils.go]"]
end

subgraph group_session["Session access"]
  node_middleware["Auth middleware<br/>[middleware.go]"]
  node_sessions[("In-memory sessions<br/>[sessionStore.go]")]
end

subgraph group_presentation["Web presentation"]
  node_landing["Landing template<br/>[landing.html]"]
  node_dashboard["Dashboard template<br/>[dashboard.html]"]
end

node_browser(("Browser"))
node_google_oauth["Google OAuth"]
node_google_identity["Google ID validation"]

node_browser -->|"HTTP requests"| node_server
node_server -->|"starts and routes"| node_routes
node_routes -->|"dispatches"| node_handler
node_routes -->|"protects dashboard"| node_middleware
node_middleware -->|"calls when authorized"| node_handler
node_middleware -->|"reads session"| node_sessions
node_handler -->|"uses OAuth config"| node_config
node_handler -->|"exchanges code"| node_google_oauth
node_google_oauth -->|"authorization redirect"| node_browser
node_handler -->|"validates ID token"| node_google_identity
node_handler -->|"generates access token"| node_access_jwt
node_handler -->|"generates session and refresh tokens"| node_token_utils
node_handler -->|"writes and deletes sessions"| node_sessions
node_handler -->|"reads landing session"| node_sessions
node_handler -->|"renders"| node_landing
node_handler -->|"renders"| node_dashboard

click node_server "https://github.com/antimatterr/go-oauth/blob/main/cmd/api/main.go"
click node_routes "https://github.com/antimatterr/go-oauth/blob/main/cmd/api/main.go"
click node_handler "https://github.com/antimatterr/go-oauth/blob/main/internal/handlers/googleLogin.go"
click node_config "https://github.com/antimatterr/go-oauth/blob/main/internal/config/config.go"
click node_access_jwt "https://github.com/antimatterr/go-oauth/blob/main/internal/handlers/googleLogin.go"
click node_token_utils "https://github.com/antimatterr/go-oauth/blob/main/internal/utils/utils.go"
click node_middleware "https://github.com/antimatterr/go-oauth/blob/main/internal/middleware/middleware.go"
click node_sessions "https://github.com/antimatterr/go-oauth/blob/main/internal/Store/sessionStore.go"
click node_landing "https://github.com/antimatterr/go-oauth/blob/main/template/landing.html"
click node_dashboard "https://github.com/antimatterr/go-oauth/blob/main/template/dashboard.html"

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_browser toneBlue
class node_handler,node_config,node_access_jwt,node_token_utils toneAmber
class node_middleware,node_sessions toneMint
class node_landing,node_dashboard toneRose
class node_google_oauth,node_google_identity toneIndigo
```

## Components

### HTTP application

- [HTTP server](https://github.com/antimatterr/go-oauth/blob/main/cmd/api/main.go): `cmd/api/main.go`
- [Route setup](https://github.com/antimatterr/go-oauth/blob/main/cmd/api/main.go): `cmd/api/main.go`

### Authentication

- [Auth handler](https://github.com/antimatterr/go-oauth/blob/main/internal/handlers/googleLogin.go): `internal/handlers/googleLogin.go`
- [OAuth config](https://github.com/antimatterr/go-oauth/blob/main/internal/config/config.go): `internal/config/config.go`
- [Access JWT](https://github.com/antimatterr/go-oauth/blob/main/internal/handlers/googleLogin.go): `internal/handlers/googleLogin.go`
- [Token utilities](https://github.com/antimatterr/go-oauth/blob/main/internal/utils/utils.go): `internal/utils/utils.go`

### Session access

- [Auth middleware](https://github.com/antimatterr/go-oauth/blob/main/internal/middleware/middleware.go): `internal/middleware/middleware.go`
- [In-memory sessions](https://github.com/antimatterr/go-oauth/blob/main/internal/Store/sessionStore.go): `internal/Store/sessionStore.go`

### Web presentation

- [Landing template](https://github.com/antimatterr/go-oauth/blob/main/template/landing.html): `template/landing.html`
- [Dashboard template](https://github.com/antimatterr/go-oauth/blob/main/template/dashboard.html): `template/dashboard.html`

### Other components

- **Browser**
- **Google OAuth**
- **Google ID validation**

## Connections

- Browser → HTTP server: HTTP requests
- HTTP server → Route setup: starts and routes
- Route setup → Auth handler: dispatches
- Route setup → Auth middleware: protects dashboard
- Auth middleware → Auth handler: calls when authorized
- Auth middleware → In-memory sessions: reads session
- Auth handler → OAuth config: uses OAuth config
- Auth handler → Google OAuth: exchanges code
- Google OAuth → Browser: authorization redirect
- Auth handler → Google ID validation: validates ID token
- Auth handler → Access JWT: generates access token
- Auth handler → Token utilities: generates session and refresh tokens
- Auth handler → In-memory sessions: writes and deletes sessions
- Auth handler → In-memory sessions: reads landing session
- Auth handler → Landing template: renders
- Auth handler → Dashboard template: renders
