# matissavadogo/spotthedifference architecture

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

- Interactive diagram: https://gitdiagram.com/matissavadogo/spotthedifference
- Repository: https://github.com/matissavadogo/spotthedifference

## Overview

##### Project Type & Purpose
- This is a full-stack, multiplayer mobile game.
- The Android client (built with Java/Kotlin and XML layouts in Android Studio) provides the interactive “Spot the Difference” gameplay.
- The backend (implemented in C# with ASP.NET Core and structured into controllers, business logic, data access, and tests) supports game sessions, player management, image handling, and the real-time game logic.
- Communication between the app and server includes standard RESTful API endpoints (via Retrofit) and WebSocket/SignalR based interactions for real-time updates.

##### Main Components
- Mobile Client (Android App):
◦ UI Layer: Activities and layouts (evident from the “ui/activities” and “res/layout” folders).
◦ Networking/API Layer: API service classes (located under “api” packages using Retrofit).
◦ Real-Time Communication: WebSocket and SignalR client components (in “WebSocket” package).
◦ Models & Config: Data models (in “models”), and configuration classes (e.g., “ServerConfig.java”).
◦ Utility and Test Packages: Utility classes (such as “ScreenUtils.java”) and test files under “src/test”.

- Backend Server (API7D):
◦ API/Controllers: HTTP endpoints for game sessions, image management, and difference checking (see Controllers folder).
◦ Business Logic/Services: Core game logic and helper classes (in “Metier” and “Services”), including SignalR Hub implementation (e.g., GameSessionHub.cs).
◦ Data Layer: Data access objects/interfaces and SQL scripts (inside “DATA” and “Database”) managing persistence and schema.
◦ Objects/Domain Models: Domain object definitions (in “objet”).
◦ Configuration & Settings: app settings (json configuration files) and certificates.
◦ Testing: Separate unit testing projects (TestsUnitaires) covering controllers, business logic, etc.

##### Relationships & Interactions
- The mobile client interacts with the server using:
◦ RESTful calls via Retrofit for typical API operations (e.g., joining a game, image retrieval).
◦ WebSocket/SignalR connections for real-time event notifications, game updates, and ensuring synchronization among players.
- On the backend, the controllers receive client calls, pass the requests onto service layers/business logic, and interact with the data layer (either through SQL databases or file-based storage, as suggested by the Database folder).
- Data flows from the Android UI to the API layer, then to backend controllers, and back to the client using both request/response and push-notification patterns.

##### Important Architectural Patterns & Technologies
- Separation of Concerns – the project clearly divides responsibilities between UI, API communication, and backend logic.
- MVC/MVVM (on the Android client, the activities and util classes can be viewed through the lens of user-driven events while the backend strictly separates controllers, business logic, and data access).
- Real-Time Communication via SignalR (WebSocket integration on the client and server).
- Dependency Injections and interface-based designs are visible (look at interfaces in the “models” and “api” folders).
- Use of Gradle for build automation and Visual Studio for backend development.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Mobile Client Subsystem
    subgraph "Mobile Client"
        UI_Activities("Android UI Activities"):::frontend
        UI_Layouts("Android UI Layouts"):::frontend
        Retrofit("Retrofit API Service"):::frontend
        SignalRClient("SignalR/WebSocket Client"):::communication
        DataModels("Data Models"):::frontend
        ServerConfig("Server Config"):::frontend
        ScreenUtils("Screen Utils"):::frontend
        MobileTests("Mobile Tests"):::frontend
    end

    %% Backend Server Subsystem
    subgraph "Backend Server"
        Controllers("Controllers"):::backend
        GameSessionHub("GameSessionHub"):::backend
        SessionsService("Sessions Service"):::backend
        DataAccess("DATA Access"):::backend
        Database("Database"):::backend
        DomainModels("Domain Models"):::backend
        AppSettings("App Settings"):::backend
        DevSettings("Development Settings"):::backend
        Certificates("Certificates"):::backend
        BackendTests("Backend Tests"):::backend
    end

    %% Mobile Client Interactions
    UI_Activities -->|"triggers"| Retrofit
    Retrofit -->|"HTTP_API"| Controllers
    Retrofit -->|"config"| ServerConfig
    Retrofit -->|"serializes"| DataModels
    SignalRClient <-->|"real-time"| GameSessionHub
    MobileTests -.-> Retrofit
    MobileTests -.-> SignalRClient

    %% Backend Server Interactions
    Controllers -->|"delegates"| SessionsService
    Controllers -->|"delegates"| GameSessionHub
    Controllers -->|"uses"| DomainModels
    Controllers -->|"config"| AppSettings
    Controllers -->|"config"| Certificates
    SessionsService -->|"queries"| DataAccess
    SessionsService -->|"queries"| Database
    GameSessionHub -->|"notifies"| DomainModels
    BackendTests -.-> Controllers
    BackendTests -.-> GameSessionHub
    BackendTests -.-> SessionsService

    %% Click Events for Mobile Client
    click UI_Activities "https://github.com/matissavadogo/spotthedifference/tree/main/app/src/main/java/com/example/spotthedifference/ui/activities"
    click UI_Layouts "https://github.com/matissavadogo/spotthedifference/tree/main/app/src/main/res/layout"
    click Retrofit "https://github.com/matissavadogo/spotthedifference/tree/main/app/src/main/java/com/example/spotthedifference/api"
    click SignalRClient "https://github.com/matissavadogo/spotthedifference/tree/main/app/src/main/java/com/example/spotthedifference/WebSocket"
    click DataModels "https://github.com/matissavadogo/spotthedifference/tree/main/app/src/main/java/com/example/spotthedifference/models"
    click ServerConfig "https://github.com/matissavadogo/spotthedifference/blob/main/app/src/main/java/com/example/spotthedifference/config/ServerConfig.java"
    click ScreenUtils "https://github.com/matissavadogo/spotthedifference/blob/main/app/src/main/java/com/example/spotthedifference/ui/utils/ScreenUtils.java"
    click MobileTests "https://github.com/matissavadogo/spotthedifference/tree/main/app/src/test"

    %% Click Events for Backend Server
    click Controllers "https://github.com/matissavadogo/spotthedifference/tree/main/server/API7D/Controllers"
    click GameSessionHub "https://github.com/matissavadogo/spotthedifference/tree/main/server/API7D/Metier"
    click SessionsService "https://github.com/matissavadogo/spotthedifference/blob/main/server/API7D/Services/SessionsService.cs"
    click DataAccess "https://github.com/matissavadogo/spotthedifference/tree/main/server/API7D/DATA"
    click Database "https://github.com/matissavadogo/spotthedifference/tree/main/server/API7D/Database"
    click DomainModels "https://github.com/matissavadogo/spotthedifference/tree/main/server/API7D/objet"
    click AppSettings "https://github.com/matissavadogo/spotthedifference/blob/main/server/API7D/appsettings.json"
    click DevSettings "https://github.com/matissavadogo/spotthedifference/blob/main/server/API7D/appsettings.Development.json"
    click Certificates "https://github.com/matissavadogo/spotthedifference/blob/main/server/API7D/Certificat_SAE5.pfx"
    click BackendTests "https://github.com/matissavadogo/spotthedifference/tree/main/server/TestsUnitaires"

    %% Style Definitions
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef communication fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
```
