# ptlc8/pokeprof architecture

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

- Interactive diagram: https://gitdiagram.com/ptlc8/pokeprof
- Repository: https://github.com/ptlc8/pokeprof

## Overview

##### Main Components

a) Frontend Layer:
- Web Interface (PHP-based views)
- Static Assets (cards, sounds, boosters)
- Service Worker (for PWA functionality)
- Client-side JavaScript

b) Backend Layer:
- API Endpoints (organized by domain)
- Card Management System
- Match System
- User Management System
- Authentication System

c) Database Layer:
- MariaDB Database
- Initialization Scripts

d) External Services:
- Portal System (for authentication and user data)
- Webhook Integration (for card creation/editing notifications)

**[Client Layer]**
- ↕
**[Web Server Layer (Apache + PHP-FPM)]**
- ↕
**[API Layer]**
- ↕
**[Database Layer]**

##### Component Details

Frontend Components (Top Layer):
- Asset management system
- Service worker integration

API Layer (Middle Layer):
- API endpoints into logical modules:
- Card Management (/api/card/*)
- Match System (/api/match/*)
- User Management (/api/user/*)
- Deck Management (/api/user/deck/*)

Database Layer (Bottom Layer):
- MariaDB instance
- Initialization and configuration

External Services (Side Connections):
- Portal System integration
- Webhook notifications system

##### Important Flows to Highlight

- Authentication flow
- Card creation and moderation flow
- Match making and gameplay flow
- Deck management flow

##### Deployment Aspects

- Docker container separation if using Docker
- Jenkins pipeline integration
- How auto-deployment works

Remember to show both the development environment setup (with Docker and without) as alternative deployment paths.

This system design should emphasize the modular nature of the application while clearly showing the interaction between components, especially focusing on the game's core features: card management, matchmaking, and user interactions.

Notes about scalability considerations and the human moderation requirement for card approval, as mentioned in the README.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        WI["Web Interface"]:::frontend
        CSS["Styling"]:::frontend
        JS["Client JavaScript"]:::frontend
        SW["Service Worker"]:::frontend
        click WI "https://github.com/ptlc8/pokeprof/blob/master/src/*.php"
        click CSS "https://github.com/ptlc8/pokeprof/blob/master/src/*.css"
        click JS "https://github.com/ptlc8/pokeprof/blob/master/src/cards.js"
        click SW "https://github.com/ptlc8/pokeprof/blob/master/src/service-worker.js"

        subgraph Assets
            Cards["Cards"]:::static
            Sounds["Sound Effects"]:::static
            Boosters["Boosters"]:::static
            click Cards "https://github.com/ptlc8/pokeprof/tree/master/src/assets/cards/"
            click Sounds "https://github.com/ptlc8/pokeprof/tree/master/src/assets/sounds/"
            click Boosters "https://github.com/ptlc8/pokeprof/tree/master/src/assets/boosters/"
        end
    end

    subgraph "API Layer"
        subgraph "Card Management"
            CC["Create Card"]:::api
            EC["Edit Card"]:::api
            GC["Get Card"]:::api
            SC["Sell Card"]:::api
            UC["Use Card"]:::api
            click CC "https://github.com/ptlc8/pokeprof/blob/master/src/api/card/create.php"
            click EC "https://github.com/ptlc8/pokeprof/blob/master/src/api/card/edit.php"
            click GC "https://github.com/ptlc8/pokeprof/blob/master/src/api/card/get.php"
            click SC "https://github.com/ptlc8/pokeprof/blob/master/src/api/card/sell.php"
            click UC "https://github.com/ptlc8/pokeprof/blob/master/src/api/card/use.php"
        end

        subgraph "Match System"
            MM["Match"]:::api
            MP["Play"]:::api
            MS["Search"]:::api
            MSP["Spectate"]:::api
            click MM "https://github.com/ptlc8/pokeprof/blob/master/src/api/match/match.php"
            click MP "https://github.com/ptlc8/pokeprof/blob/master/src/api/match/play.php"
            click MS "https://github.com/ptlc8/pokeprof/blob/master/src/api/match/search.php"
            click MSP "https://github.com/ptlc8/pokeprof/blob/master/src/api/match/spectate.php"
        end

        subgraph "User Management"
            UG["Get User"]:::api
            UH["Get History"]:::api
            UP["Post Info"]:::api
            US["Get Shop"]:::api
            click UG "https://github.com/ptlc8/pokeprof/blob/master/src/api/user/get.php"
            click UH "https://github.com/ptlc8/pokeprof/blob/master/src/api/user/gethistory.php"
            click UP "https://github.com/ptlc8/pokeprof/blob/master/src/api/user/postinfo.php"
            click US "https://github.com/ptlc8/pokeprof/blob/master/src/api/user/getshop.php"
        end

        subgraph "Deck Management"
            DA["Add Slot"]:::api
            DC["Choose Deck"]:::api
            DG["Get Deck"]:::api
            click DA "https://github.com/ptlc8/pokeprof/blob/master/src/api/user/deck/addslot.php"
            click DC "https://github.com/ptlc8/pokeprof/blob/master/src/api/user/deck/choose.php"
            click DG "https://github.com/ptlc8/pokeprof/blob/master/src/api/user/deck/get.php"
        end

        DT["Daily Tasks"]:::api
        click DT "https://github.com/ptlc8/pokeprof/blob/master/src/api/onceaday.php"
    end

    subgraph "Database Layer"
        DB[(MariaDB)]:::database
        DBInit["Init Scripts"]:::database
        DBConf["Configuration"]:::database
        Cache["Cache System"]:::system
        click DBInit "https://github.com/ptlc8/pokeprof/blob/master/database/init.sql"
        click DBConf "https://github.com/ptlc8/pokeprof/blob/master/database/mariadb.cnf"
        click Cache "https://github.com/ptlc8/pokeprof/tree/master/src/cached/"
    end

    subgraph "External Services"
        Portal["Portal System"]:::external
        Webhook["Webhook Integration"]:::external
    end

    subgraph "Deployment"
        Docker["Docker Containers"]:::deployment
        Jenkins["Jenkins Pipeline"]:::deployment
        click Docker "https://github.com/ptlc8/pokeprof/blob/master/compose.yaml"
    end

    %% Connections
    WI --> CC & EC & GC & SC & UC
    WI --> MM & MP & MS & MSP
    WI --> UG & UH & UP & US
    WI --> DA & DC & DG
    WI --> DT

    CC & EC & GC & SC & UC --> DB
    MM & MP & MS & MSP --> DB
    UG & UH & UP & US --> DB
    DA & DC & DG --> DB

    DB --> Cache
    DT --> DB

    WI --> Portal
    Portal --> Webhook

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef static fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:white
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef system fill:#e74c3c,stroke:#c0392b,color:white
    classDef deployment fill:#1abc9c,stroke:#16a085,color:white
```
