# Project Knowledge Base

## Project Overview
This project, `analytics_admin_panel`, appears to be a Symfony-based PHP application. It serves as an admin panel and API backend for an online gaming or gambling platform. It handles game launches, player transactions (deposits, withdrawals), promo codes, and integrations with various game providers and aggregators.

## Key Technologies
*   **Framework:** Symfony (PHP)
*   **Database:** Doctrine ORM (likely MySQL/MariaDB based on typical Symfony setups)
*   **Frontend:** Twig templates, likely Webpack Encore for asset management.
*   **API:** FOSRestBundle seems to be used for API endpoints (based on annotations like `@Rest\Get`).
*   **HTTP Client:** Symfony HttpClient.
*   **Caching:** Symfony Cache.
*   **Logging:** Monolog (PSR-3 LoggerInterface).

## Directory Structure
*   `src/`: Application source code.
    *   `Controller/`: Contains controllers for handling HTTP requests.
        *   `API/`: API endpoints for game launchers, transactions, etc. (`LauncherApi.php`).
        *   `Launcher/`: Controllers for the game launcher UI (`LauncherController.php`).
    *   `Entity/`: Doctrine entities representing database tables (e.g., `Game`, `Member`, `Transaction`, `Provider`).
    *   `Repository/`: Doctrine repositories for database queries.
    *   `Services/`: Business logic services (refactored from controllers).
        *   `TransactionService.php`: Handles deposits, withdrawals.
        *   `PromoService.php`: Handles promo codes and free spins.
        *   `PlayerService.php`: Handles player info retrieval.
        *   `JackpotService.php`: Handles jackpot info and history.
        *   `GameService.php`: Handles game presets.
        *   `NotificationService.php`: Handles popups and notifications.
    *   `Parser/`: Helper classes for parsing request data (e.g., `LauncherDataParser.php`).
*   `config/`: Symfony configuration files.
*   `templates/`: Twig templates.
*   `public/`: Web root.

## Key Components & Logic

### Game Launcher (`LauncherApi`, `LauncherController`)
*   **Purpose:** Handles the initialization and launching of games for players.
*   **Flow:**
    1.  Receives a request with parameters like `token`, `gameId`, `provider`, `currency`, etc.
    2.  `LauncherDataParser` parses these parameters, handling different API versions (1, 2, default).
    3.  Validates the session/token with the aggregator/provider via `ApiSender`.
    4.  Retrieves or creates the `Member` (player) in the local database.
    5.  Determines the correct game URL and parameters (real play vs demo).
    6.  Generates a launch URL for the frontend.
*   **Refactoring:** The monolithic `LauncherApi` controller has been refactored into smaller services (`TransactionService`, `PromoService`, etc.) to improve maintainability.

### Transactions (`TransactionService`)
*   **Types:** Withdraw (bet), Deposit (win), Promo Withdraw, Promo Deposit.
*   **Logic:**
    *   Validates the request (signature, parameters).
    *   Checks for duplicate transactions using `TransactionRepository`.
    *   Sends the transaction to the game provider/aggregator via `ApiSender`.
    *   Updates the local `Transaction` table.
    *   Handles rollbacks/follow-backs in case of errors.
    *   Sends Telegram notifications for large wins/bets.

### Promotions (`PromoService`)
*   **Functionality:** Creates "Golden Tickets" (free spins/rounds) for players.
*   **Logic:**
    *   Can create promos for single or multiple players.
    *   Validates operator codes.
    *   Creates `PromoGoldenTicket` records.

### Jackpots (`JackpotService`)
*   **Functionality:** Provides information about jackpots, their current values (odometers), and history.
*   **Caching:** Heavily uses caching (`CACHE_STORAGE_TIME = 129600`) to reduce database load for jackpot history.

### Integrations
*   **Providers/Aggregators:** The system integrates with multiple providers like `dlv`, `parimatch`, `1xbet`, `everymatrix`, `slotegrator`, etc.
*   **ApiSender:** A helper class to send HTTP requests to these external providers.

## Recent Changes
*   **Refactoring `LauncherApi`:** Extracted business logic into `TransactionService`, `PromoService`, `PlayerService`, `JackpotService`, `GameService`, and `NotificationService`.
*   **Fixing `LauncherDataParser`:** Corrected language parsing logic to handle both lowercase (e.g., 'es') and uppercase (e.g., 'SPA') language codes, fixing an issue where 'SPA' was defaulting to 'ENG'.
*   **Fixing `LauncherApi`:** Added missing `melbet.com` operator code.
*   **Gitignore:** Added IDE specific files (`.idea/`, `*.iml`, etc.) to `.gitignore`.

## Important Constants & Configuration
*   `OPERATOR_CODE`: Maps internal operator IDs to provider names (now in `PromoService`).
*   `LANGUAGE_MAP`: Maps language codes (e.g., 'ru') to internal codes (e.g., 'RUS') in `LauncherDataParser`.
*   `CACHE_STORAGE_TIME`: Default cache TTL (129600 seconds).

## To-Do / Future Improvements
*   Continue monitoring for any regressions from the `LauncherApi` refactoring.
*   Ensure all new services are properly covered by unit tests (if applicable/requested).
