# essem/game-logger architecture

> Architecture diagram of the GitHub repository essem/game-logger, 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/essem/game-logger
- Repository: https://github.com/essem/game-logger

## Overview

##### Main Components

A. Frontend Layer (React Application)
- Main React application container
- Component groups:
- User Management (Login, Users, NewUser)
- Game Management (Games, NewGame)
- Event Management (Events, NewEvent)
- Player Management (Players, NewPlayer)
- Statistics (Stats, Summary)
- Redux store structure (based on the reducers folder)

B. Backend Layer (Node.js Server)
- Main server application
- Authentication service (auth.js)
- Core business logic modules:
- Events management
- Users management
- Statistics calculation
- WebSocket handling
- Model layer showing relationships between:
- Events
- Games
- Players
- Users
- Winners/Losers

C. Database Layer (PostgreSQL)
- Database container
- Main tables based on the models and migrations

**[Client Tier]**
- ↕
**[Application Tier]**
- ↕
**[Data Tier]**

##### Component Relationships to Highlight

A. Frontend-Backend Communication:
- HTTP requests (shown in http.js)
- WebSocket connections (websocket.js)
- API endpoints

B. Data Flow:
- User authentication flow
- Game logging process
- Statistics calculation pipeline
- Event management workflow

##### Specific Implementation Details

A. Frontend Section:
**[React Application]**
- Components Layer
- User Management
- Game Management
- Event Management
- Statistics
- Redux Store
- App State
- User State
- Event State
- Events State

B. Backend Section:
**[Node.js Server]**
- API Routes
- Authentication
- Business Logic
- Events Handler
- Users Handler
- Stats Calculator
- WebSocket Handler
- Model Layer

C. Database Section:
**[PostgreSQL]**
- Users Table
- Events Table
- Games Table
- Players Table
- Winners Table
- Losers Table

##### Additional Elements

- Configuration management (config folder)
- Development tools (Docker containers)
- Migration system
- Environment-specific settings

##### Important Notes

- Docker container boundaries
- Development port (5001)
- WebSocket connections separately from HTTP routes
- Authentication flow across all layers
- How the statistics calculation pipeline works

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#b3d9ff,stroke:#333
    classDef backend fill:#98FB98,stroke:#333
    classDef database fill:#FFE4B5,stroke:#333
    classDef auth fill:#FFB6C1,stroke:#333
    classDef config fill:#D3D3D3,stroke:#333

    %% Frontend Layer
    subgraph Frontend
        ReactApp["React Application"]
        
        subgraph Components
            UserMgmt["User Management"]
            GameMgmt["Game Management"]
            EventMgmt["Event Management"]
            PlayerMgmt["Player Management"]
            StatComp["Statistics Components"]
        end

        subgraph ReduxStore
            AppState["App State"]
            UserState["User State"]
            EventState["Event State"]
            EventsState["Events State"]
        end

        HTTPClient["HTTP Client"]
        WSClient["WebSocket Client"]
    end

    %% Backend Layer
    subgraph Backend
        NodeServer["Node.js Server"]
        
        subgraph Services
            AuthService["Authentication Service"]
            EventHandler["Event Handler"]
            UserHandler["User Handler"]
            StatsCalc["Statistics Calculator"]
            WSHandler["WebSocket Handler"]
        end

        subgraph Models
            EventModel["Event Model"]
            GameModel["Game Model"]
            PlayerModel["Player Model"]
            UserModel["User Model"]
            WinnerModel["Winner Model"]
            LoserModel["Loser Model"]
        end
    end

    %% Database Layer
    subgraph Database
        PostgreSQL[(PostgreSQL)]
        Users[("Users Table")]
        Events[("Events Table")]
        Games[("Games Table")]
        Players[("Players Table")]
        Winners[("Winners Table")]
        Losers[("Losers Table")]
    end

    %% Configuration
    Config["Configuration"]

    %% Relationships
    ReactApp --> Components
    Components --> ReduxStore
    ReduxStore --> HTTPClient
    ReduxStore --> WSClient
    HTTPClient --> NodeServer
    WSClient --> WSHandler
    NodeServer --> Services
    Services --> Models
    Models --> PostgreSQL
    PostgreSQL --> Users
    PostgreSQL --> Events
    PostgreSQL --> Games
    PostgreSQL --> Players
    PostgreSQL --> Winners
    PostgreSQL --> Losers
    Config --> NodeServer

    %% Style Applications
    class ReactApp,UserMgmt,GameMgmt,EventMgmt,PlayerMgmt,StatComp,HTTPClient,WSClient frontend
    class NodeServer,EventHandler,UserHandler,StatsCalc,WSHandler backend
    class PostgreSQL,Users,Events,Games,Players,Winners,Losers database
    class AuthService auth
    class Config config

    %% Click Events
    click UserMgmt "https://github.com/essem/game-logger/blob/master//front/src/components/User.jsx"
    click GameMgmt "https://github.com/essem/game-logger/blob/master//front/src/components/Games.jsx"
    click EventMgmt "https://github.com/essem/game-logger/blob/master//front/src/components/Events.jsx"
    click PlayerMgmt "https://github.com/essem/game-logger/blob/master//front/src/components/Players.jsx"
    click StatComp "https://github.com/essem/game-logger/blob/master//front/src/components/Stats.jsx"
    click AppState "https://github.com/essem/game-logger/blob/master//front/src/reducers/app.js"
    click UserState "https://github.com/essem/game-logger/blob/master//front/src/reducers/user.js"
    click EventState "https://github.com/essem/game-logger/blob/master//front/src/reducers/event.js"
    click EventsState "https://github.com/essem/game-logger/blob/master//front/src/reducers/events.js"
    click HTTPClient "https://github.com/essem/game-logger/blob/master//front/src/http.js"
    click AuthService "https://github.com/essem/game-logger/blob/master//server/src/auth.js"
    click EventHandler "https://github.com/essem/game-logger/blob/master//server/src/events.js"
    click UserHandler "https://github.com/essem/game-logger/blob/master//server/src/users.js"
    click StatsCalc "https://github.com/essem/game-logger/blob/master//server/src/stats.js"
    click WSHandler "https://github.com/essem/game-logger/blob/master//server/src/websocket.js"
    click EventModel "https://github.com/essem/game-logger/blob/master//server/src/models/event.js"
    click GameModel "https://github.com/essem/game-logger/blob/master//server/src/models/game.js"
    click PlayerModel "https://github.com/essem/game-logger/blob/master//server/src/models/player.js"
    click UserModel "https://github.com/essem/game-logger/blob/master//server/src/models/user.js"
    click WinnerModel "https://github.com/essem/game-logger/blob/master//server/src/models/winner.js"
    click LoserModel "https://github.com/essem/game-logger/blob/master//server/src/models/loser.js"
    click Config "https://github.com/essem/game-logger/tree/master//server/config"
```
