# csslab/maia-platform-frontend architecture

> Architecture diagram of the GitHub repository csslab/maia-platform-frontend, 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/csslab/maia-platform-frontend
- Repository: https://github.com/csslab/maia-platform-frontend

## Overview

##### Main System Components

a. Frontend Layer:
- Next.js Application (Core)
- Component Structure
- Core Components (Header, Footer, etc.)
- Feature-specific Components (Board, Analysis, Training, etc.)
- Context Providers
- Public Assets (Stockfish, pieces, blog content)

b. Application Logic Layer:
- Custom Hooks
- Controllers (Game, Analysis, Training, Turing)
- Utilities
- Type Definitions

c. API Layer:
- Authentication
- Game Play
- Analysis
- Training
- Profile Management
- Turing Test Features

##### Component Relationships

Following interactions:

a. Data Flow:
- Context Providers → Components
- Hooks → Components
- API → Controllers
- Controllers → Components

b. State Management:
- AuthContext
- GameControllerContext
- AnalysisListContext
- ThemeContext
- WindowSizeContext
- ModalContext

##### Technical Implementation Details

Specific elements:

a. Core Technologies:
- Next.js Framework
- TypeScript
- SASS/Tailwind CSS
- Stockfish Integration

b. Feature Modules:
- Chess Board Interface
- Game Analysis Tools
- Training System
- Turing Test Implementation
- User Profiles

**[Client Browser]**
- ↓
**[Next.js Frontend]**
- Public Assets
- Stockfish Engine

- Components Layer
- Core Components
- Feature Components
- UI Elements

- Context Layer
- Auth Context
- Game Controller
- Other Contexts

- Hooks Layer
- Game Controllers
- Analysis Controllers
- Feature-specific Hooks

- API Layer
- Authentication
- Game Operations
- Analysis Services

##### Important Implementation Details to Highlight

- Separation between server-side and client-side rendering
- Role of Stockfish integration
- Modular component structure
- Demonstrate the context-based state management
- Relationship between pages and their corresponding components

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph NextApp["Next.js Application"]
        subgraph FrontendLayer["Frontend Layer"]
            CoreComp["Core Components"]:::component
            BoardComp["Board Components"]:::component
            AnalysisComp["Analysis Components"]:::component
            TrainingComp["Training Components"]:::component
            TuringComp["Turing Components"]:::component
        end

        subgraph ContextLayer["Context Providers"]
            AuthCtx["Auth Context"]:::context
            GameCtx["Game Controller Context"]:::context
            AnalysisCtx["Analysis List Context"]:::context
            ThemeCtx["Theme Context"]:::context
            WindowCtx["Window Size Context"]:::context
        end

        subgraph HooksLayer["Custom Hooks"]
            GameHook["Game Controller"]:::hook
            AnalysisHook["Analysis Controller"]:::hook
            TrainingHook["Training Controller"]:::hook
            StockfishHook["Stockfish Engine"]:::hook
            TuringHook["Turing Controller"]:::hook
        end

        subgraph APILayer["API Layer"]
            AuthAPI["Authentication API"]:::api
            GameAPI["Game Play API"]:::api
            AnalysisAPI["Analysis API"]:::api
            TrainingAPI["Training API"]:::api
            ProfileAPI["Profile API"]:::api
            TuringAPI["Turing API"]:::api
        end

        subgraph Assets["Public Assets"]
            Stockfish["Stockfish Engine"]:::asset
            Pieces["Chess Pieces"]:::asset
            Blog["Blog Content"]:::asset
        end

        subgraph Types["Type Definitions"]
            BaseTypes["Base Types"]:::type
            PlayTypes["Play Types"]:::type
            AnalysisTypes["Analysis Types"]:::type
            TrainingTypes["Training Types"]:::type
            TuringTypes["Turing Types"]:::type
        end

        subgraph Utils["Utilities"]
            GenUtils["General Utils"]:::util
            StockfishUtils["Stockfish Utils"]:::util
            MathUtils["Math Utils"]:::util
            ColorUtils["Colors Utils"]:::util
        end

        subgraph Pages["Application Pages"]
            PlayPage["Game Play"]:::page
            AnalysisPage["Analysis"]:::page
            TrainingPage["Training"]:::page
            TuringPage["Turing Test"]:::page
            ProfilePage["Profile"]:::page
        end
    end

    %% Relationships
    Browser --> NextApp
    
    %% Context relationships
    ContextLayer --> FrontendLayer
    
    %% Hook relationships
    HooksLayer --> FrontendLayer
    
    %% API relationships
    APILayer --> HooksLayer
    
    %% Asset relationships
    Assets --> FrontendLayer
    
    %% Page relationships
    Pages --> FrontendLayer
    
    %% Type relationships
    Types --> HooksLayer
    Types --> APILayer
    
    %% Utility relationships
    Utils --> HooksLayer
    Utils --> FrontendLayer

    %% Click events
    click CoreComp "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/components/Core"
    click BoardComp "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/components/Board"
    click AnalysisComp "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/components/Analysis"
    click TrainingComp "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/components/Training"
    click TuringComp "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/components/Turing"
    
    click AuthCtx "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/contexts/AuthContext"
    click GameCtx "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/contexts/GameControllerContext"
    click AnalysisCtx "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/contexts/AnalysisListContext"
    click ThemeCtx "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/contexts/ThemeContext"
    click WindowCtx "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/contexts/WindowSizeContext"
    
    click Stockfish "https://github.com/CSSLab/maia-platform-frontend/tree/main/public/stockfish"
    click Pieces "https://github.com/CSSLab/maia-platform-frontend/tree/main/public/assets/pieces"
    click Blog "https://github.com/CSSLab/maia-platform-frontend/tree/main/public/blog"
    
    click GameHook "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/hooks/useGameController"
    click AnalysisHook "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/hooks/useAnalysisController"
    click TrainingHook "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/hooks/useTrainingController"
    click StockfishHook "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/hooks/useStockfishEngine"
    click TuringHook "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/hooks/useTuringController"
    
    click AuthAPI "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/api/auth"
    click GameAPI "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/api/play"
    click AnalysisAPI "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/api/analysis"
    click TrainingAPI "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/api/train"
    click ProfileAPI "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/api/profile"
    click TuringAPI "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/api/turing"
    
    click BaseTypes "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/types/base"
    click PlayTypes "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/types/play"
    click AnalysisTypes "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/types/analysis"
    click TrainingTypes "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/types/training"
    click TuringTypes "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/types/turing"
    
    click GenUtils "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/utils"
    click StockfishUtils "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/utils/stockfish"
    click MathUtils "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/utils/math"
    click ColorUtils "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/utils/colours"
    
    click PlayPage "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/pages/play"
    click AnalysisPage "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/pages/analysis"
    click TrainingPage "https://github.com/CSSLab/maia-platform-frontend/blob/main/src/pages/train.tsx"
    click TuringPage "https://github.com/CSSLab/maia-platform-frontend/blob/main/src/pages/turing.tsx"
    click ProfilePage "https://github.com/CSSLab/maia-platform-frontend/tree/main/src/pages/profile"

    %% Styling
    classDef component fill:#3498db,stroke:#2980b9,color:white
    classDef context fill:#f1c40f,stroke:#f39c12,color:black
    classDef hook fill:#9b59b6,stroke:#8e44ad,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef asset fill:#e74c3c,stroke:#c0392b,color:white
    classDef type fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef util fill:#1abc9c,stroke:#16a085,color:white
    classDef page fill:#34495e,stroke:#2c3e50,color:white
```
