# s-14chess-p/senior-project-chessai architecture

> Architecture diagram of the GitHub repository s-14chess-p/senior-project-chessai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/s-14chess-p/senior-project-chessai
- Repository: https://github.com/s-14chess-p/senior-project-chessai

## Overview

##### Main components
- Frontend: This includes all the static files (HTML, JavaScript, CSS in wwwroot) and the Razor Views (located in the Views folder). These render the game interface, rules, and game result pages.
- Backend – ASP.NET Core:
- Controllers: e.g., HomeController.cs which orchestrates the flow of the application.
- SignalR Hub: ChessHub.cs for real-time multiplayer communication.
- Models: The core business logic representing game entities such as Board, Game, Piece, and the dynamic AI logic found under Models/AIs (with classes like AIFactory, MiniMaxAI, RandyRandom, and SmartyAI).
- Program and Startup configuration: Responsible for app startup, configuration (e.g., appsettings.json), and dependency injection.
- Dynamic AI Integration: The module that allows chess AI models to be added dynamically by placing new files in the designated directory. This is critical and should be highlighted as a plug-in architecture.

##### Relationships and Data Flow
- Client Side (Web browser) interacts with the backend by:
- Requesting web pages rendered by Razor views.
- Initiating game commands (for moves or lobby creation) through HTTP requests (via the controllers).
- Communicating in real-time with the server via SignalR (handled by ChessHub).
- Controller Layer: Receives and processes user requests, it then manipulates models (i.e., game state, AI moves) and renders responses via views.
- SignalR Component: Acts as the gateway for real-time data; it receives moves/updates and broadcasts game state changes back to connected clients.
- AI Module: The AIFactory and individual AI model classes (e.g., MiniMaxAI) dynamically provide chess engine logic. They are integrated into the game’s flow when a user selects PvAI mode.

##### Architectural Patterns & Design Principles
- MVC Pattern: The separation of concerns is clear with controllers handling incoming request routing, models holding business logic/data, and views presenting the interface.
- Real-time Communication: The use of SignalR enforces a layered communication approach for dynamic and responsive gameplay.
- Plug-in Architecture for AIs: This allows extension and easy replacement of chess AI models without modifying the core game logic.

##### Technologies and Frameworks to Highlight
- ASP.NET Core (C#) for the server-side application.
- SignalR for real-time multiplayer interactions.
- Razor Views for dynamic HTML content.
- JavaScript and CSS (with Bootstrap and jQuery libraries) for frontend interactivity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        Browser["Web Browser (UI)"]:::client
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        StaticAssets["Static Assets (wwwroot)"]:::frontend
        RazorViews["Razor Views (Views)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        subgraph "Controllers & Hubs"
            HomeController["HomeController"]:::controller
            ChessHub["ChessHub"]:::signalr
        end
        subgraph "Business Logic & Models"
            GameModels["Models (Game Logic)"]:::models
            DynamicAI["Dynamic AI Integration (AIs)"]:::ai
        end
        Startup["Startup Configuration"]:::config
    end

    %% Data Flow / Interactions
    Browser -->|"HTTP Request"| HomeController
    HomeController -->|"ProcessesGameData"| GameModels
    HomeController -->|"InvokesAI"| DynamicAI
    HomeController -->|"ReturnView"| RazorViews
    Browser -->|"LoadsStaticFiles"| StaticAssets
    Browser <-->|"RealTimeCommunication"| ChessHub
    Startup -->|"Configures"| HomeController
    Startup -->|"Configures"| ChessHub
    Startup -->|"Configures"| GameModels
    Startup -->|"Configures"| DynamicAI

    %% Click Events
    click StaticAssets "https://github.com/s-14chess-p/senior-project-chessai/tree/master/ChessAI/wwwroot"
    click RazorViews "https://github.com/s-14chess-p/senior-project-chessai/tree/master/ChessAI/Views"
    click HomeController "https://github.com/s-14chess-p/senior-project-chessai/blob/master/ChessAI/Controllers/HomeController.cs"
    click ChessHub "https://github.com/s-14chess-p/senior-project-chessai/blob/master/ChessAI/Hubs/ChessHub.cs"
    click GameModels "https://github.com/s-14chess-p/senior-project-chessai/tree/master/ChessAI/Models"
    click DynamicAI "https://github.com/s-14chess-p/senior-project-chessai/tree/master/ChessAI/Models/AIs"
    click Startup "https://github.com/s-14chess-p/senior-project-chessai/blob/master/ChessAI/Program.cs"

    %% Styles
    classDef client fill:#DDEEFF,stroke:#333,stroke-width:2px;
    classDef frontend fill:#FFE0B2,stroke:#333,stroke-width:2px;
    classDef controller fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef signalr fill:#FFF9C4,stroke:#333,stroke-width:2px;
    classDef models fill:#F8BBD0,stroke:#333,stroke-width:2px;
    classDef ai fill:#E1BEE7,stroke:#333,stroke-width:2px;
    classDef config fill:#B2EBF2,stroke:#333,stroke-width:2px;
```
