# arieldiga/snake-game architecture

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

- Interactive diagram: https://gitdiagram.com/arieldiga/snake-game
- Repository: https://github.com/arieldiga/snake-game

## Overview

This is a small Snake-game web application with a Go HTTP server, static browser content, and a PostgreSQL-backed leaderboard. The visible server workflow serves the static files and routes score submissions and leaderboard reads to separate handlers; those handlers validate or retrieve score data and encode JSON responses. Startup configures the database and creates the leaderboard table. The static page’s contents were not sampled, so its interaction with the API is not asserted. The graph reflects the sampled Go source and file tree.

Main entry points: [`main.go`](https://github.com/arieldiga/snake-game/blob/main/main.go) (HTTP server and router), [`database/database.go`](https://github.com/arieldiga/snake-game/blob/main/database/database.go) (Database connection setup), [`handlers/score_handlers.go`](https://github.com/arieldiga/snake-game/blob/main/handlers/score_handlers.go) (Save score handler), [`models/score.go`](https://github.com/arieldiga/snake-game/blob/main/models/score.go) (Score model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web delivery"]
  node_server["HTTP server and router<br/>[main.go]"]
  node_static["Game static files<br/>[index.html]"]
end

subgraph group_api["Leaderboard API"]
  node_save["Save score handler<br/>[score_handlers.go]"]
  node_leaderboard["Leaderboard handler<br/>[score_handlers.go]"]
  node_score["Score model<br/>[score.go]"]
end

subgraph group_storage["Persistence"]
  node_dbconn["Database connection setup<br/>[database.go]"]
  node_postgres[("PostgreSQL")]
end

node_browser(("Player browser"))

node_server -->|"serves"| node_static
node_server -->|"routes POST"| node_save
node_server -->|"routes GET"| node_leaderboard
node_browser -.->|"requests pages"| node_server
node_save -->|"decodes"| node_score
node_leaderboard -->|"scans and encodes"| node_score
node_save -->|"inserts via DB"| node_dbconn
node_leaderboard -->|"queries via DB"| node_dbconn
node_server -->|"connects at startup"| node_dbconn
node_dbconn -->|"opens and initializes"| node_postgres

click node_server "https://github.com/arieldiga/snake-game/blob/main/main.go"
click node_static "https://github.com/arieldiga/snake-game/blob/main/static/index.html"
click node_save "https://github.com/arieldiga/snake-game/blob/main/handlers/score_handlers.go"
click node_leaderboard "https://github.com/arieldiga/snake-game/blob/main/handlers/score_handlers.go"
click node_score "https://github.com/arieldiga/snake-game/blob/main/models/score.go"
click node_dbconn "https://github.com/arieldiga/snake-game/blob/main/database/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_static,node_browser toneBlue
class node_save,node_leaderboard,node_score toneAmber
class node_dbconn,node_postgres toneMint
```

## Components

### Web delivery

- [HTTP server and router](https://github.com/arieldiga/snake-game/blob/main/main.go): `main.go`
- [Game static files](https://github.com/arieldiga/snake-game/blob/main/static/index.html): `static/index.html`

### Leaderboard API

- [Save score handler](https://github.com/arieldiga/snake-game/blob/main/handlers/score_handlers.go): `handlers/score_handlers.go`
- [Leaderboard handler](https://github.com/arieldiga/snake-game/blob/main/handlers/score_handlers.go): `handlers/score_handlers.go`
- [Score model](https://github.com/arieldiga/snake-game/blob/main/models/score.go): `models/score.go`

### Persistence

- [Database connection setup](https://github.com/arieldiga/snake-game/blob/main/database/database.go): `database/database.go`
- **PostgreSQL**

### Other components

- **Player browser**

## Connections

- HTTP server and router → Game static files: serves (evidence: `main.go`)
- HTTP server and router → Save score handler: routes POST (evidence: `main.go`)
- HTTP server and router → Leaderboard handler: routes GET (evidence: `main.go`)
- Player browser → HTTP server and router: requests pages
- Save score handler → Score model: decodes (evidence: `handlers/score_handlers.go`)
- Leaderboard handler → Score model: scans and encodes (evidence: `handlers/score_handlers.go`)
- Save score handler → Database connection setup: inserts via DB (evidence: `handlers/score_handlers.go`)
- Leaderboard handler → Database connection setup: queries via DB (evidence: `handlers/score_handlers.go`)
- HTTP server and router → Database connection setup: connects at startup (evidence: `main.go`)
- Database connection setup → PostgreSQL: opens and initializes (evidence: `database/database.go`)
