# gemszen/jogo-cobrinha architecture

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

- Interactive diagram: https://gitdiagram.com/gemszen/jogo-cobrinha
- Repository: https://github.com/gemszen/jogo-cobrinha

## Overview

This repository is a simple browser-based Snake game. The player changes direction with the keyboard; a timed game loop advances the snake, handles food and collisions, and draws the board. The sampled JavaScript supports these runtime relationships. The HTML and CSS files are present in the tree, but their contents were not sampled, so their specific roles and connections are not shown.

Main entry points: [`scripts/script.js`](https://github.com/gemszen/jogo-cobrinha/blob/main/scripts/script.js) (Game loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_player(("Player"))
node_keyboard["Direction input<br/>[script.js]"]
node_timer["Browser timer"]
node_loop["Game loop<br/>[script.js]"]
node_state["Snake and food<br/>[script.js]"]
node_render["Canvas rendering<br/>[script.js]"]
node_canvas["Game canvas"]
node_browser["Browser alerts"]

node_player -->|"presses keys"| node_keyboard
node_keyboard -->|"changes direction"| node_state
node_timer -->|"ticks every 100ms"| node_loop
node_loop -->|"advances and checks"| node_state
node_loop -->|"calls"| node_render
node_render -->|"draws"| node_canvas
node_loop -->|"alerts on collision"| node_browser

click node_keyboard "https://github.com/gemszen/jogo-cobrinha/blob/main/scripts/script.js"
click node_loop "https://github.com/gemszen/jogo-cobrinha/blob/main/scripts/script.js"
click node_state "https://github.com/gemszen/jogo-cobrinha/blob/main/scripts/script.js"
click node_render "https://github.com/gemszen/jogo-cobrinha/blob/main/scripts/script.js"

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_player,node_canvas toneIndigo
class node_keyboard,node_loop,node_state,node_render toneTeal
class node_timer,node_browser toneBlue
```

## Components

### Other components

- **Player**
- [Direction input](https://github.com/gemszen/jogo-cobrinha/blob/main/scripts/script.js): `scripts/script.js`
- **Browser timer**
- [Game loop](https://github.com/gemszen/jogo-cobrinha/blob/main/scripts/script.js): `scripts/script.js`
- [Snake and food](https://github.com/gemszen/jogo-cobrinha/blob/main/scripts/script.js): `scripts/script.js`
- [Canvas rendering](https://github.com/gemszen/jogo-cobrinha/blob/main/scripts/script.js): `scripts/script.js`
- **Game canvas**
- **Browser alerts**

## Connections

- Player → Direction input: presses keys
- Direction input → Snake and food: changes direction
- Browser timer → Game loop: ticks every 100ms
- Game loop → Snake and food: advances and checks
- Game loop → Canvas rendering: calls
- Canvas rendering → Game canvas: draws
- Game loop → Browser alerts: alerts on collision
