# hir-247-30/splatoon-weapon-randomization architecture

> Architecture diagram of the GitHub repository hir-247-30/splatoon-weapon-randomization, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hir-247-30/splatoon-weapon-randomization
- Repository: https://github.com/hir-247-30/splatoon-weapon-randomization

## Overview

##### Main Components
- Environment/Configuration: The .env file (derived from .env.example) holds the players’ names and the Discord webhook URL.
- Main Application Entry Point: src/main.ts is the starting point that orchestrates the process.
- Services:
- Player Service (src/services/playerService.ts): Likely responsible for handling player-specific logic, such as reading player names from the environment.
- Report Service (src/services/reportService.ts): Manages the logic around generating and sending notifications to the specified Discord channel.
- Business Logic / Utility Functions:
- Choice Logic (src/lib/choice.ts): Contains the logic for randomly picking a weapon based on the number of players and the selection rules outlined in the README.
- Shared Components:
- Common Functions and Types (src/common/functions.ts and src/common/types.ts): These provide utility functions and type definitions that are potentially used throughout the application.
- Constants:
- Weapons Constants (src/const/weapons.ts): This file likely contains the data defining different Splatoon weapons, their categories (e.g., short, medium, long range) and roles (e.g., ink, balance, kill).

##### Relationships and Interactions
- The Main entry point (src/main.ts) initializes the application by loading configurations from the environment.
- It then calls into the services (playerService and reportService) which in turn use the choice logic from src/lib/choice.ts to process the appropriate weapon selection based on the player count.
- The services may also reference the constants (from src/const/weapons.ts) and any shared types/functions (from src/common) to maintain consistency.
- After processing, the reportService sends a notification via the configured Discord webhook URL.

##### Architectural Patterns and Design Principles
- Modularity: The code is separated by concerns into distinct directories (common, lib, const, and services), which promotes a clear separation of responsibilities.
- Environment-based Configuration: Using .env for configuration ensures that sensitive data (e.g., Discord webhook) and player information are not hard-coded.
- Entrypoint Delegation: The main file (src/main.ts) delegates specialized tasks to separate, easily testable service modules.
- Clear Dependency Flow: Core business logic (in choice.ts and services) depends on shared constants and types, following a predictable and maintainable flow.

##### Relevant Technologies and Frameworks
- Node.js and TypeScript as the base runtime environment and language.
- npm for dependency management (as indicated by package.json, package-lock.json, and npm commands in the README).
- ESLint for code quality assurance (eslint.config.js).

##### Essential Elements
- Clear labels for each component: Environment (config), Main (Orchestrator), Services (Player & Report), Business Logic (Choice Logic), Shared Utilities (Common Types/Functions), and Constants (Weapons).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Configuration and Entry"
        config["Environment (.env)"]:::config
        main["Main Application (src/main.ts)"]:::core
    end

    subgraph "Services"
        playerService["Player Service (src/services/playerService.ts)"]:::service
        reportService["Report Service (src/services/reportService.ts)"]:::service
    end

    subgraph "Business Logic"
        choiceLogic["Weapon Selection Logic (src/lib/choice.ts)"]:::logic
    end

    subgraph "Shared Components"
        commonFunctions["Common Functions (src/common/functions.ts)"]:::shared
        commonTypes["Common Types (src/common/types.ts)"]:::shared
        weaponsConst["Weapons Constants (src/const/weapons.ts)"]:::constant
    end

    discord["Discord Webhook"]:::external

    config -->|"loads"| main
    main -->|"invokes"| playerService
    main -->|"invokes"| reportService
    playerService -->|"uses"| choiceLogic
    reportService -->|"uses"| choiceLogic
    playerService -->|"references"| weaponsConst
    reportService -->|"references"| weaponsConst
    playerService -->|"calls"| commonFunctions
    reportService -->|"calls"| commonFunctions
    playerService -->|"calls"| commonTypes
    reportService -->|"calls"| commonTypes
    reportService -->|"notifies"| discord

    click config "https://github.com/hir-247-30/splatoon-weapon-randomization/blob/main/.env.example"
    click main "https://github.com/hir-247-30/splatoon-weapon-randomization/blob/main/src/main.ts"
    click playerService "https://github.com/hir-247-30/splatoon-weapon-randomization/blob/main/src/services/playerService.ts"
    click reportService "https://github.com/hir-247-30/splatoon-weapon-randomization/blob/main/src/services/reportService.ts"
    click choiceLogic "https://github.com/hir-247-30/splatoon-weapon-randomization/blob/main/src/lib/choice.ts"
    click commonFunctions "https://github.com/hir-247-30/splatoon-weapon-randomization/blob/main/src/common/functions.ts"
    click commonTypes "https://github.com/hir-247-30/splatoon-weapon-randomization/blob/main/src/common/types.ts"
    click weaponsConst "https://github.com/hir-247-30/splatoon-weapon-randomization/blob/main/src/const/weapons.ts"

    classDef config fill:#f9c,stroke:#333,stroke-width:2px;
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef service fill:#cfc,stroke:#333,stroke-width:2px;
    classDef logic fill:#ffc,stroke:#333,stroke-width:2px;
    classDef shared fill:#e0e0e0,stroke:#333,stroke-width:2px;
    classDef constant fill:#fc9,stroke:#333,stroke-width:2px;
    classDef external fill:#fcc,stroke:#333,stroke-width:2px;
```
