# jnisa/snake-go architecture

> Architecture diagram of the GitHub repository jnisa/snake-go, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jnisa/snake-go
- Repository: https://github.com/jnisa/snake-go

## Overview

##### Main Components Identification

The project follows a clear modular structure with these main components:
- Game Engine (Ebitengine)
- Core Game Logic
- Input Handling
- Rendering System
- State Management

##### Component Relationships

- User Input → Frontend Component
- Frontend Component → Game Core
- Game Core ↔ State Management
- Game Core ↔ Movement System
- Game Core ↔ Game Objects
- All Components ↔ Auxiliary Functions

##### Detailed Component Descriptions

Frontend Component:
- Handles game window and rendering
- Manages game loop

Game Core:
- Controls game logic
- Manages snake movement
- Handles collision detection
- Controls food placement

Movement System:
- Processes directional input
- Calculates next positions
- Validates movements

State Management:
- Tracks game state
- Manages score
- Handles game over conditions

Game Objects:
- Defines snake segments
- Defines food objects
- Manages object positions

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        EBI[Ebitengine Library]:::external
    end

    subgraph Presentation
        UI[Frontend Component]:::frontend
        RENDER[Rendering System]:::frontend
        INPUT[Input Handler]:::frontend
    end

    subgraph GameLogic
        CORE[Snake Game Core]:::core
        MOVE[Movement System]:::core
        STATE[State Management]:::core
        OBJ[Game Objects]:::core
    end

    subgraph Support
        AUX[Auxiliary Functions]:::support
        MAIN[Main Application]:::support
    end

    subgraph Testing
        GTEST[Game Logic Tests]:::test
        MTEST[Movement Tests]:::test
        STEST[State Tests]:::test
        ATEST[Auxiliary Tests]:::test
    end

    %% Relationships
    INPUT --> UI
    UI --> CORE
    UI --> RENDER
    RENDER --> EBI
    
    CORE <--> STATE
    CORE <--> MOVE
    CORE <--> OBJ
    
    STATE --> AUX
    MOVE --> AUX
    OBJ --> AUX
    
    MAIN --> UI
    MAIN --> CORE

    %% Testing Relationships
    GTEST -.-> CORE
    MTEST -.-> MOVE
    STEST -.-> STATE
    ATEST -.-> AUX

    %% Click Events
    click UI "https://github.com/jnisa/snake-go/blob/main/pkg/game/frontend.go"
    click CORE "https://github.com/jnisa/snake-go/blob/main/pkg/game/snake.go"
    click MOVE "https://github.com/jnisa/snake-go/blob/main/pkg/moves/moves.go"
    click STATE "https://github.com/jnisa/snake-go/blob/main/pkg/states/states.go"
    click OBJ "https://github.com/jnisa/snake-go/blob/main/pkg/objects/objects.go"
    click AUX "https://github.com/jnisa/snake-go/blob/main/pkg/auxiliars/auxiliars.go"
    click MAIN "https://github.com/jnisa/snake-go/blob/main/cmp/snake/main.go"
    click GTEST "https://github.com/jnisa/snake-go/blob/main/internal/tests/game_test.go"
    click MTEST "https://github.com/jnisa/snake-go/blob/main/internal/tests/moves_test.go"
    click STEST "https://github.com/jnisa/snake-go/blob/main/internal/tests/states_test.go"
    click ATEST "https://github.com/jnisa/snake-go/blob/main/internal/tests/auxiliars_test.go"

    %% Styles
    classDef external fill:#e6e6fa,stroke:#333,stroke-width:2px
    classDef frontend fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px
    classDef support fill:#d3d3d3,stroke:#333,stroke-width:2px
    classDef test fill:#ffb366,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[External Dependencies]:::external
        L2[Frontend Components]:::frontend
        L3[Core Components]:::core
        L4[Support Components]:::support
        L5[Test Components]:::test
    end
```
