# alik-r/casino-roulette architecture

> Architecture diagram of the GitHub repository alik-r/casino-roulette, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alik-r/casino-roulette
- Repository: https://github.com/alik-r/casino-roulette

## Overview

##### Main Components

a) Client Layer:
- HTML/CSS Frontend (HTMX + Alpine.js)
- Static Assets (images, fonts, styles)
- Client-side Scripts
- Nginx Server (serving static content)

b) API Layer:
- Go Backend Server (Chi framework)
- JWT Authentication System
- API Endpoints
- Middleware

c) Data Layer:
- PostgreSQL Database
- Data Models

d) Infrastructure:
- Docker Containers
- Docker Compose Orchestration

**[Frontend Container]**

- (HTTP/HTTPS)
- v
**[Backend Container]**

- (SQL)
- v
**[Database Container]**

##### Detailed Component Breakdown

Frontend Container (Port 81):
- Nginx Web Server
- Static Files (HTML, CSS, JS)
- Pages:
- Registration
- Roulette Game
- Leaderboard
- Profile

Backend Container (Port 8080):
- API Handlers (/pkg/api)
- Authentication (/pkg/auth)
- Database Interface (/pkg/db)
- Middleware (/pkg/middleware)
- Models (/pkg/models)
- Roulette Logic (/pkg/roulette)

Database Container (Port 5433):
- PostgreSQL Database
- User Data
- Transaction History
- Game States

##### Flow Indicators

- User authentication flow
- API requests/responses
- Database queries
- WebSocket connections (if implemented)
- JWT token flow

##### Additional Elements

- Environment variables
- Configuration files
- Docker Compose orchestration
- GitHub Actions deployment

##### Technical Details

- Port mappings (81, 8080, 5433)
- Technology stack labels
- Database schema references
- API endpoint groupings
- Authentication middleware placement

##### Optimization Notes

- Caching mechanisms (if any)
- Static file serving through Nginx
- Security middleware positions
- Scalable components

Remember to indicate the containerization boundary with Docker, showing how the three main services (frontend, backend, database) are orchestrated through Docker Compose.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend["Frontend Container (Port 81)"]
        NGINX["Nginx Server"]:::server
        click NGINX "https://github.com/alik-r/casino-roulette/blob/main/frontend/nginx.conf"
        
        subgraph Static["Static Content"]
            HTML["HTML Pages"]:::frontend
            click HTML "https://github.com/alik-r/casino-roulette/blob/main/frontend/index.html"
            ASSETS["Assets (Images/Fonts)"]:::frontend
            click ASSETS "https://github.com/alik-r/casino-roulette/tree/main/frontend/images/"
            STYLES["CSS Styles"]:::frontend
            click STYLES "https://github.com/alik-r/casino-roulette/tree/main/frontend/styles/"
            SCRIPTS["Client Scripts"]:::frontend
            click SCRIPTS "https://github.com/alik-r/casino-roulette/tree/main/frontend/scripts/"
        end
        
        subgraph Pages["Game Pages"]
            REG["Registration"]:::page
            click REG "https://github.com/alik-r/casino-roulette/blob/main/frontend/register.html"
            GAME["Roulette Game"]:::page
            click GAME "https://github.com/alik-r/casino-roulette/blob/main/frontend/roulette.html"
            LEAD["Leaderboard"]:::page
            click LEAD "https://github.com/alik-r/casino-roulette/blob/main/frontend/leaderboard.html"
            PROF["Profile"]:::page
            click PROF "https://github.com/alik-r/casino-roulette/blob/main/frontend/profile.html"
        end
    end

    subgraph Backend["Backend Container (Port 8080)"]
        MAIN["Main Server"]:::server
        click MAIN "https://github.com/alik-r/casino-roulette/blob/main/backend/cmd/main.go"
        
        subgraph API["API Layer"]
            HANDLERS["API Handlers"]:::api
            click HANDLERS "https://github.com/alik-r/casino-roulette/blob/main/backend/pkg/api/handlers.go"
            AUTH["Authentication"]:::auth
            click AUTH "https://github.com/alik-r/casino-roulette/blob/main/backend/pkg/auth/jwt.go"
            MIDDLE["Middleware"]:::api
            click MIDDLE "https://github.com/alik-r/casino-roulette/blob/main/backend/pkg/middleware/jwt_middleware.go"
        end
        
        subgraph Logic["Game Logic"]
            ROULETTE["Roulette Engine"]:::game
            click ROULETTE "https://github.com/alik-r/casino-roulette/blob/main/backend/pkg/roulette/roulette.go"
            MODELS["Data Models"]:::data
            click MODELS "https://github.com/alik-r/casino-roulette/blob/main/backend/pkg/models/models.go"
            DBIF["Database Interface"]:::data
            click DBIF "https://github.com/alik-r/casino-roulette/blob/main/backend/pkg/db/db.go"
        end
    end

    subgraph DB["Database Container (Port 5433)"]
        POSTGRES["PostgreSQL"]:::database
        USERDATA["User Data"]:::data
        HISTORY["Transaction History"]:::data
        GAMESTATE["Game States"]:::data
    end

    subgraph Infrastructure["Infrastructure"]
        DOCKER["Docker Compose"]:::infra
        click DOCKER "https://github.com/alik-r/casino-roulette/blob/main/docker-compose.yml"
        DEPLOY["GitHub Actions"]:::infra
        click DEPLOY "https://github.com/alik-r/casino-roulette/blob/main/.github/workflows/deploy.yml"
    end

    %% Connections
    NGINX --> |serves| Static
    Static --> |displays| Pages
    Pages --> |API Requests| HANDLERS
    HANDLERS --> |authenticates| AUTH
    HANDLERS --> |uses| MIDDLE
    HANDLERS --> |processes| ROULETTE
    ROULETTE --> |uses| MODELS
    MODELS --> |interfaces| DBIF
    DBIF --> |queries| POSTGRES
    POSTGRES --> USERDATA
    POSTGRES --> HISTORY
    POSTGRES --> GAMESTATE
    DOCKER --> |orchestrates| Frontend
    DOCKER --> |orchestrates| Backend
    DOCKER --> |orchestrates| DB
    DEPLOY --> |deploys| DOCKER

    %% Styles
    classDef frontend fill:#a8d5ff,stroke:#333,stroke-width:1px
    classDef server fill:#95ff95,stroke:#333,stroke-width:1px
    classDef api fill:#ffb366,stroke:#333,stroke-width:1px
    classDef auth fill:#ff99ff,stroke:#333,stroke-width:1px
    classDef game fill:#ff9999,stroke:#333,stroke-width:1px
    classDef data fill:#ffff99,stroke:#333,stroke-width:1px
    classDef database fill:#ff8533,stroke:#333,stroke-width:1px
    classDef infra fill:#c2c2f0,stroke:#333,stroke-width:1px
    classDef page fill:#b3e6ff,stroke:#333,stroke-width:1px

    %% Legend
    subgraph Legend
        L1["Frontend Component"]:::frontend
        L2["Server Component"]:::server
        L3["API Component"]:::api
        L4["Auth Component"]:::auth
        L5["Game Logic"]:::game
        L6["Data Component"]:::data
        L7["Database"]:::database
        L8["Infrastructure"]:::infra
    end
```
