Backend & API - IzzatFirdaus/uma_musume_race_planner GitHub Wiki
The application's backend is built with PHP and serves as a JSON API for the frontend. It handles database interactions, data processing, file uploads, and logging.
Core Components
includes/db.php
: A centralized PDO connector that establishes a secure connection to the database. It also handles loading environment variables from the.env
file.includes/logger.php
: Sets up a Monolog logger instance for consistent, file-based logging across the application.components/trainee_image_handler.php
: Contains the server-sidehandleTraineeImageUpload
function, which processesmultipart/form-data
, validates and saves uploaded image files, and handles the deletion of old images.
Main API Endpoint
handle_plan_crud.php
: This is the primary endpoint for all Create, Update, and Delete (CRUD) operations. It processesPOST
requests from the frontend forms, includingmultipart/form-data
for image uploads. It manages data for theplans
table and all its related child tables (attributes, skills, goals, etc.) and uses a generichandleChildDataUpsert
function to efficiently manage these related records.
GET
)
Data Retrieval Endpoints (These scripts fetch specific pieces of data and return them as JSON. They are called by the JavaScript in index.php
to populate the UI.
get_plans.php
: Fetches the main list of all non-deleted plans, including their core stats and trainee image path, sorted by a custom status order.fetch_plan_details.php
: Retrieves the main data for a single plan from theplans
table.get_plan_attributes.php
: Fetches all attributes for a given plan ID.get_plan_skills.php
: Fetches all skills for a given plan ID.get_plan_predictions.php
: Fetches all race predictions for a given plan ID.get_plan_goals.php
: Fetches all career goals for a given plan ID.get_plan_terrain_grades.php
: Fetches terrain aptitude grades for a plan.get_plan_distance_grades.php
: Fetches distance aptitude grades for a plan.get_plan_style_grades.php
: Fetches style aptitude grades for a plan.get_plan_turns.php
: Fetches turn-by-turn stat progression for a plan.get_progress_chart_data.php
: Fetches and formats stat progression data specifically for the Chart.js integration.
Utility Endpoints
get_stats.php
: Calculates and returns statistics for the dashboard, such as total plans and counts by status.get_activities.php
: Fetches the most recent entries from theactivity_log
table.export_plan_data.php
: Aggregates all data for a single plan and returns it as a single JSON object.