# suchir-g/connected architecture

> Architecture diagram of the GitHub repository suchir-g/connected, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/suchir-g/connected
- Repository: https://github.com/suchir-g/connected

## Overview

##### Main Components

A. Frontend Layer (React Application):
- User Interface Components
- Game Logic Components
- Authentication Components
- State Management
- External Services Integration

B. Backend Layer (Flask Application):
- API Server
- Game Engine
- AI Components
- Authentication Service

C. External Services:
- Firebase (for authentication)
- Database (implied by user features)

##### Component Relationships

**[Client Layer] <-> [Backend Layer] <-> [External Services]**

##### Detailed Component Breakdown

A. Client Layer (Top Section):
- UI Components (Board, Navbar, Friends)
- Game State Management
- Authentication Context
- Theme Context
- API Service Layer

B. Backend Layer (Middle Section):
- Flask API Server
- Game Engine (Position Handler)
- AI Engine (Negamax Algorithm)
- Opening Book Storage
- Zobrist Hashing Module

C. External Services (Bottom Section):
- Firebase Authentication
- Database Storage

##### Connection and Data Flow

- API calls between frontend and backend
- Authentication flow with Firebase
- Data persistence flows
- Game state updates
- AI move calculations

**[User Interface Layer]**
- ↕
**[Frontend Logic Layer]**
- ↕
**[API Integration Layer]**
- ↕
**[Backend API Layer]**
- ↕
**[Game Engine Layer]**
- ↕
**[External Services Layer]**

##### Additional Elements

- Version/environment indicators
- Notes for scaling considerations
- Critical paths in the system

##### Technical Details

- React Components Structure
- Flask Endpoints
- AI Algorithm Flow
- Authentication Flow
- Data Persistence Patterns

Remember to:
- Keep components at a consistent abstraction level
- Clear boundaries between systems
- Asynchronous vs synchronous operations
- Public vs protected routes
- Error handling flows

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#a8d5ff,stroke:#333
    classDef backend fill:#ffb3b3,stroke:#333
    classDef external fill:#c2f0c2,stroke:#333
    classDef auth fill:#ffdb99,stroke:#333
    classDef ai fill:#e6b3ff,stroke:#333
    classDef data fill:#d9d9d9,stroke:#333

    %% Frontend Layer
    subgraph Frontend
        UI[User Interface Layer]
        Board[Game Board]:::frontend
        Nav[Navigation Bar]:::frontend
        Friends[Friends System]:::frontend
        Stats[Game Statistics]:::frontend
        Social[Social Features]:::frontend
        PlayBot[Bot Gameplay]:::frontend
        PlayLocal[Local Gameplay]:::frontend

        GameLogic[Game Logic]:::frontend
        AuthContext[Authentication Context]:::frontend
        ThemeContext[Theme Context]:::frontend
        APIConfig[API Configuration]:::frontend
        ProtectedRoute[Protected Routes]:::frontend
        FirebaseConfig[Firebase Config]:::frontend
    end

    %% Backend Layer
    subgraph Backend
        APIServer[Flask API Server]:::backend
        GameEngine[Game Engine]:::backend
        AIEngine[AI Engine]:::backend
        OpeningBook[Opening Book]:::data
        ZobristHash[Zobrist Hashing]:::backend
    end

    %% External Services
    subgraph External
        Firebase[Firebase Auth]:::external
        Database[(Database)]:::data
    end

    %% Relationships
    UI --> Board
    UI --> Nav
    UI --> Friends
    UI --> Stats
    UI --> Social
    UI --> PlayBot
    UI --> PlayLocal

    Board --> GameLogic
    GameLogic --> APIConfig
    AuthContext --> FirebaseConfig
    FirebaseConfig --> Firebase
    APIConfig --> APIServer
    ProtectedRoute --> AuthContext

    APIServer --> GameEngine
    APIServer --> AIEngine
    AIEngine --> OpeningBook
    AIEngine --> ZobristHash
    APIServer --> Database

    %% Click Events
    click Board "https://github.com/suchir-g/connected/blob/main/frontend/src/components/board/Board.js"
    click AuthContext "https://github.com/suchir-g/connected/blob/main/frontend/src/contexts/AuthContext.js"
    click ThemeContext "https://github.com/suchir-g/connected/blob/main/frontend/src/contexts/ThemeContext.js"
    click GameLogic "https://github.com/suchir-g/connected/blob/main/frontend/src/utilities/gameState.js"
    click Nav "https://github.com/suchir-g/connected/blob/main/frontend/src/components/navbar/Navbar.js"
    click Friends "https://github.com/suchir-g/connected/tree/main/frontend/src/components/friends/"
    click APIServer "https://github.com/suchir-g/connected/blob/main/backend/app.py"
    click AIEngine "https://github.com/suchir-g/connected/blob/main/backend/Negamaxer.py"
    click GameEngine "https://github.com/suchir-g/connected/blob/main/backend/position.py"
    click OpeningBook "https://github.com/suchir-g/connected/blob/main/backend/opening_book.pkl"
    click ZobristHash "https://github.com/suchir-g/connected/blob/main/backend/zobristHashing.py"
    click FirebaseConfig "https://github.com/suchir-g/connected/blob/main/frontend/src/config/firebase.js"
    click APIConfig "https://github.com/suchir-g/connected/blob/main/frontend/src/config/api.js"
    click ProtectedRoute "https://github.com/suchir-g/connected/blob/main/frontend/src/components/ProtectedRoute.js"
    click Stats "https://github.com/suchir-g/connected/blob/main/frontend/src/pages/stats/Stats.js"
    click Social "https://github.com/suchir-g/connected/blob/main/frontend/src/pages/social/Social.js"
    click PlayBot "https://github.com/suchir-g/connected/blob/main/frontend/src/pages/play/bot/PlayBot.js"
    click PlayLocal "https://github.com/suchir-g/connected/blob/main/frontend/src/pages/play/local/PlayLocal.js"

    %% Legend
    subgraph Legend
        Frontend_L[Frontend Components]:::frontend
        Backend_L[Backend Components]:::backend
        External_L[External Services]:::external
        Auth_L[Auth Components]:::auth
        AI_L[AI Components]:::ai
        Data_L[Data Storage]:::data
    end
```
