# elialbert/starchess architecture

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

- Interactive diagram: https://gitdiagram.com/elialbert/starchess
- Repository: https://github.com/elialbert/starchess

## Overview

##### Main Components

A. Frontend Layer:
- Angular Single Page Application (SPA)
- Key components:
- Controllers (HomeCtrl, StarchessGameCtrl, StarchessGamesCtrl)
- Directives (boardDirective, aiBoardDirective, chatBoxDirective)
- Services (boardService, gameService)

B. Backend Layer:
- Ruby on Rails Application
- API Controllers
- Models (User, StarchessGame, Rating, Event, Attendrequest)
- Game Logic (lib/starchess/)

C. External Services:
- Firebase (for real-time multiplayer features)
- OAuth providers (indicated by omniauth configuration)

D. Database Layer:
- SQL Database (indicated by ActiveRecord migrations)

**[Client Layer]**
- ↑↓
**[Application Layer]**
- ↑↓
**[Data Layer]**

##### Specific Implementation Details

a) Client Layer:
- Separate sections for:
- UI Components (templates)
- Game Controllers
- Services
- Directives

b) Application Layer:
- Rails API Controllers
- Game Logic Components:
- AI Module
- Board Logic
- Piece Definitions
- Game Rules

c) Real-time Communication:
- Firebase integration for multiplayer features
- WebSocket connections

d) Authentication Flow:
- OAuth providers
- Devise integration

##### Key Relationships to Highlight

- Real-time game state updates between players via Firebase
- API communication between Angular and Rails
- Authentication flow with OAuth providers
- Game logic interaction with both frontend and backend

Create distinct sections for:

##### Flow Indicators

- HTTP/HTTPS API calls
- WebSocket connections
- Database queries
- Real-time updates
- Authentication flows

This architecture requires special attention to the real-time gaming aspects while maintaining clarity about the overall web application structure.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef gamelogic fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        F[Frontend]:::frontend
        B[Backend]:::backend
        D[Database]:::database
        E[External Services]:::external
        G[Game Logic]:::gamelogic
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        %% Controllers
        HomeCtrl[Home Controller]:::frontend
        GameCtrl[Game Controller]:::frontend
        GamesCtrl[Games Controller]:::frontend

        %% Directives
        BoardDir[Board Directive]:::frontend
        AIBoardDir[AI Board Directive]:::frontend
        ChatDir[Chat Box Directive]:::frontend

        %% Services
        BoardSvc[Board Service]:::frontend
        GameSvc[Game Service]:::frontend

        %% Templates
        GameTemp[Game Template]:::frontend
        ChatTemp[Chat Template]:::frontend
        GameListTemp[Game List Template]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        APIBase[API Controller]:::backend
        GamesAPI[Games Controller]:::backend
        OAuthCtrl[OAuth Controller]:::backend
        DeviseConfig[Devise Config]:::backend
    end

    %% Game Logic Layer
    subgraph "Game Logic"
        GameLogic[Game Logic]:::gamelogic
        BoardLogic[Board Logic]:::gamelogic
        PieceDefs[Piece Definitions]:::gamelogic
        AISystem[AI System]:::gamelogic
    end

    %% Data Layer
    subgraph "Data Layer"
        DB[(SQL Database)]:::database
        GameModel[Game Model]:::database
        UserModel[User Model]:::database
        RatingModel[Rating Model]:::database
    end

    %% External Services
    subgraph "External Services"
        Firebase[Firebase]:::external
        OAuth[OAuth Providers]:::external
    end

    %% Relationships
    GameCtrl --> BoardDir
    GameCtrl --> ChatDir
    GamesCtrl --> GameListTemp
    BoardDir --> BoardSvc
    BoardSvc --> GameSvc
    GameSvc --> APIBase
    APIBase --> GamesAPI
    GamesAPI --> GameModel
    GameModel --> DB
    UserModel --> DB
    RatingModel --> DB
    GameLogic --> BoardLogic
    BoardLogic --> PieceDefs
    AISystem --> BoardLogic
    OAuth --> OAuthCtrl
    OAuthCtrl --> UserModel
    Firebase --> GameSvc

    %% Click Events
    click HomeCtrl "https://github.com/elialbert/starchess/blob/master/app/assets/javascripts/angular/controllers/HomeCtrl.js.coffee"
    click GameCtrl "https://github.com/elialbert/starchess/blob/master/app/assets/javascripts/angular/controllers/StarchessGameCtrl.js.coffee"
    click GamesCtrl "https://github.com/elialbert/starchess/blob/master/app/assets/javascripts/angular/controllers/StarchessGamesCtrl.js.coffee"
    click BoardDir "https://github.com/elialbert/starchess/blob/master/app/assets/javascripts/angular/directives/boardDirective.js.coffee"
    click AIBoardDir "https://github.com/elialbert/starchess/blob/master/app/assets/javascripts/angular/directives/aiBoardDirective.js.coffee"
    click ChatDir "https://github.com/elialbert/starchess/blob/master/app/assets/javascripts/angular/directives/chatBoxDirective.js.coffee"
    click BoardSvc "https://github.com/elialbert/starchess/blob/master/app/assets/javascripts/angular/services/boardService.js.coffee.erb"
    click GameSvc "https://github.com/elialbert/starchess/blob/master/app/assets/javascripts/angular/services/gameService.js.coffee"
    click GameLogic "https://github.com/elialbert/starchess/blob/master/lib/starchess/game.rb"
    click BoardLogic "https://github.com/elialbert/starchess/blob/master/lib/starchess/board.rb"
    click PieceDefs "https://github.com/elialbert/starchess/blob/master/lib/starchess/piece_defs.rb"
    click AISystem "https://github.com/elialbert/starchess/blob/master/lib/starchess/ai/ai.rb"
    click APIBase "https://github.com/elialbert/starchess/blob/master/app/controllers/api_controller.rb"
    click GamesAPI "https://github.com/elialbert/starchess/blob/master/app/controllers/starchess_games_controller.rb"
    click GameModel "https://github.com/elialbert/starchess/blob/master/app/models/starchess_game.rb"
    click UserModel "https://github.com/elialbert/starchess/blob/master/app/models/user.rb"
    click RatingModel "https://github.com/elialbert/starchess/blob/master/app/models/rating.rb"
    click OAuthCtrl "https://github.com/elialbert/starchess/blob/master/app/controllers/users/omniauth_callbacks_controller.rb"
    click DeviseConfig "https://github.com/elialbert/starchess/blob/master/config/initializers/devise.rb"
    click GameTemp "https://github.com/elialbert/starchess/blob/master/public/templates/starchessBoard.html"
    click ChatTemp "https://github.com/elialbert/starchess/blob/master/public/templates/chatBox.html"
    click GameListTemp "https://github.com/elialbert/starchess/blob/master/public/templates/starchess_games.html"
```
