# grassehh/pso-matchmaker architecture

> Architecture diagram of the GitHub repository grassehh/pso-matchmaker, 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/grassehh/pso-matchmaker
- Repository: https://github.com/grassehh/pso-matchmaker

## Overview

##### Main Components

a) Discord Interface Layer
- Discord.js integration
- Command handling system
- Event handling system
- Interaction handling (buttons, select menus, commands)

b) Core Services Layer
- AuthorizationService
- MatchmakingService
- RegionService
- StatsService
- TeamService
- UserService

c) Data Layer
- MongoDB connection
- Schema definitions

##### Component Relationships

**[Discord API] <-> [Bot Events Layer] -> [Event Handlers]**
- > [Command Handlers]
- > [Button Handlers]
- > [Select Menu Handlers]

**[Handlers] <-> [Service Layer] <-> [MongoDB]**

##### Specific Implementation Details

a) Event System (from /bot/src/events):
- How events like channelDelete, guildCreate, interactionCreate are handled
- To relevant services

b) Interaction Handling:
- Commands into categories (account, team, lineup, match)
- Button interactions flow
- Select menu processing

c) Game Modes:
- Team Mode
- Mix Mode
- Mix Captains Mode

##### Important Flows to Highlight

a) Matchmaking Flow:
**[User Command] -> [Command Handler] -> [MatchmakingService]**
- > [TeamService]
- > [RegionService]
- > [MongoDB]

b) Team Management Flow:
**[Team Command] -> [Command Handler] -> [TeamService]**
- > [AuthorizationService]
- > [MongoDB]

##### Additional Elements

- A region management system showing the 5 supported regions
- Elo ranking system integration
- Auto-matchmaking system flow
- Migration system structure

##### Technical Details

- Node.js runtime environment
- MongoDB database connection
- Discord.js integration
- TypeScript compilation flow

Remember to indicate the asynchronous nature of Discord bot operations and how the different services interact with each other while maintaining separation of concerns.

This system design should clearly show how the bot handles everything from receiving Discord events to managing complex matchmaking scenarios and maintaining persistent data in MongoDB.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Discord
        DiscordAPI["Discord API"]
        Bot["Discord Bot Interface"]:::interface
    end

    subgraph "Event System"
        EventHandler["Event Handler"]:::handler
        CommandHandler["Command Handler"]:::handler
        ButtonHandler["Button Handler"]:::handler
        SelectHandler["Select Menu Handler"]:::handler
        ComponentHandler["Component Handler"]:::handler
    end

    subgraph "Core Services"
        AuthService["Authorization Service"]:::service
        MatchService["Matchmaking Service"]:::service
        RegionService["Region Service"]:::service
        StatsService["Stats Service"]:::service
        TeamService["Team Service"]:::service
        UserService["User Service"]:::service
    end

    subgraph "Game Modes"
        TeamMode["Team Mode"]:::gamemode
        MixMode["Mix Mode"]:::gamemode
        CaptainsMode["Mix Captains Mode"]:::gamemode
    end

    subgraph "Team Management"
        TeamCreate["Team Creation"]:::team
        TeamManage["Team Management"]:::team
        TeamStats["Team Stats"]:::team
    end

    subgraph "Matchmaking"
        Search["Search"]:::match
        Challenge["Challenge System"]:::match
        MatchManage["Match Management"]:::match
    end

    subgraph "Stats System"
        PlayerStats["Player Stats"]:::stats
        Leaderboard["Leaderboard"]:::stats
    end

    subgraph "Data Layer"
        MongoDB[(MongoDB)]:::database
        Schema["Schema Definitions"]:::database
    end

    DiscordAPI <--> Bot
    Bot --> EventHandler
    Bot --> CommandHandler
    Bot --> ButtonHandler
    Bot --> SelectHandler
    Bot --> ComponentHandler

    EventHandler --> AuthService
    CommandHandler --> AuthService
    ButtonHandler --> AuthService
    SelectHandler --> AuthService
    ComponentHandler --> AuthService

    AuthService --> MongoDB
    MatchService --> MongoDB
    RegionService --> MongoDB
    StatsService --> MongoDB
    TeamService --> MongoDB
    UserService --> MongoDB

    TeamMode & MixMode & CaptainsMode --> MatchService
    TeamCreate & TeamManage & TeamStats --> TeamService
    Search & Challenge & MatchManage --> MatchService
    PlayerStats & Leaderboard --> StatsService

    Schema --> MongoDB

    %% Click Events
    click Bot "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/bot.ts"
    click EventHandler "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/handlers/eventHandler.ts"
    click CommandHandler "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/handlers/commandHandler.ts"
    click ButtonHandler "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/handlers/buttonHandler.ts"
    click SelectHandler "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/handlers/selectMenuHandler.ts"
    click ComponentHandler "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/handlers/componentHandler.ts"
    click AuthService "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/services/authorizationService.ts"
    click MatchService "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/services/matchmakingService.ts"
    click RegionService "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/services/regionService.ts"
    click StatsService "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/services/statsService.ts"
    click TeamService "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/services/teamService.ts"
    click UserService "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/services/userService.ts"
    click Schema "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/mongoSchema.ts"
    click TeamMode "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/interactions/commands/lineup_create.ts"
    click MixMode "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/interactions/commands/lineup_create_mix.ts"
    click CaptainsMode "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/interactions/commands/lineup_create_captains.ts"
    click TeamCreate "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/interactions/commands/team_create.ts"
    click TeamManage "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/interactions/commands/team_manage.ts"
    click TeamStats "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/interactions/commands/team_stats.ts"
    click Search "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/interactions/commands/search.ts"
    click Challenge "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/interactions/buttons/challenge.ts"
    click MatchManage "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/interactions/commands/match_manage.ts"
    click PlayerStats "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/interactions/commands/player_stats.ts"
    click Leaderboard "https://github.com/grassehh/pso-matchmaker/blob/main/bot/src/interactions/commands/leaderboard.ts"

    %% Styling
    classDef interface fill:#3498db
    classDef handler fill:#f1c40f
    classDef service fill:#2ecc71
    classDef gamemode fill:#9b59b6
    classDef team fill:#e67e22
    classDef match fill:#e74c3c
    classDef stats fill:#1abc9c
    classDef database fill:#34495e
```
