Skip to content
This repository was archived by the owner on Oct 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# GC-Stats — API
#
# Cargo configuration: points cargo run/build at the local Swagger UI
# overrides folder used to theme the embedded docs.
#
# Copyright (c) 2026 Alice Alleman — GC-Stats-API
# License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
# Repository: https://github.com/GC-Stats/API

[env]
SWAGGER_UI_OVERWRITE_FOLDER = { value = "swagger-ui-overrides", relative = true }
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# GC-Stats — API
#
# Cargo package manifest: crate metadata and dependencies for the GC-Stats
# API service.
#
# Copyright (c) 2026 Alice Alleman — GC-Stats-API
# License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
# Repository: https://github.com/GC-Stats/API

[package]
name = "GC-Stats-API"
version = "1.0.0"
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# GC-Stats — API
#
# Multi-stage Docker build: compiles the Rust binary and Tailwind CSS
# assets, then copies them into a slim runtime image.
#
# Copyright (c) 2026 Alice Alleman — GC-Stats-API
# License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
# Repository: https://github.com/GC-Stats/API

FROM rust:1.95-slim-bookworm AS builder

RUN apt-get update && apt-get install -y \
Expand Down
11 changes: 11 additions & 0 deletions assets/input.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
GC-Stats — API

Tailwind entry stylesheet: theme tokens (colors, fonts) and base styles
for the dashboard pages.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

@import "tailwindcss";

@source "../templates";
Expand Down
9 changes: 9 additions & 0 deletions audit.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# GC-Stats — API
#
# cargo-audit configuration: advisories intentionally ignored, with
# justification.
#
# Copyright (c) 2026 Alice Alleman — GC-Stats-API
# License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
# Repository: https://github.com/GC-Stats/API

[ignore]
RUSTSEC-2023-0071 = { reason = "Used only for MySQL auth in sqlx, not for sensitive crypto operations. No fix available upstream." }
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# GC-Stats — API
#
# Docker Compose services for the production and pre-production API
# containers, including their networks and Loki logging driver
# configuration.
#
# Copyright (c) 2026 Alice Alleman — GC-Stats-API
# License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
# Repository: https://github.com/GC-Stats/API

services:
gc_prod_api:
build:
Expand Down
9 changes: 9 additions & 0 deletions import.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
-- GC-Stats — API
--
-- Database schema/data dump used to (re)create the gc_prod database
-- structure.
--
-- Copyright (c) 2026 Alice Alleman — GC-Stats-API
-- License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
-- Repository: https://github.com/GC-Stats/API

-- phpMyAdmin SQL Dump
-- version 5.2.3
-- https://www.phpmyadmin.net/
Expand Down
8 changes: 8 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# GC-Stats — API
#
# Pins the Rust toolchain version used to build this project.
#
# Copyright (c) 2026 Alice Alleman — GC-Stats-API
# License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
# Repository: https://github.com/GC-Stats/API

[toolchain]
channel = "1.95"
12 changes: 12 additions & 0 deletions src/doc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
GC-Stats — API

OpenAPI documentation for the public API. Declares the documented paths,
response schemas and tags, and registers the `x-api-key` header security
scheme shown in Swagger UI.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use utoipa::openapi::security::{ApiKey, ApiKeyValue, SecurityScheme};
use utoipa::{Modify, OpenApi};
use crate::routes::{matches, players, tournaments, map};
Expand Down
13 changes: 13 additions & 0 deletions src/logging/flusher.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
GC-Stats — API

Background task that periodically drains buffered request-log entries
from local Redis into the `api_request_log` MariaDB table. Uses an
inflight key so a crash mid-flush is recovered and retried on the next
cycle without losing entries.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use std::sync::Arc;
use std::time::Duration;
use redis::{AsyncCommands, Script};
Expand Down
11 changes: 11 additions & 0 deletions src/logging/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
/*
GC-Stats — API

Declares the logging module and re-exports the request-log flusher
submodule.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

pub mod flusher;
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
GC-Stats — API

Application entrypoint. Loads configuration, connects to MariaDB and
Redis, builds the Axum router (health check, dashboard, versioned `/v1`
API, Swagger UI) and starts the HTTP server.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

mod models;
mod routes;
mod middleware;
Expand Down
12 changes: 12 additions & 0 deletions src/middleware/auth.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
GC-Stats — API

Authentication and rate-limiting middleware for the `/v1` API. Validates
the `x-api-key` header against MariaDB (cached in Redis) and enforces a
sliding-window rate limit per key.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use axum::{
extract::{State, Request},
http::StatusCode,
Expand Down
12 changes: 12 additions & 0 deletions src/middleware/logging.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
GC-Stats — API

Middleware that records method, matched route, status code, duration and
user agent for each request, then pushes the entry onto the local Redis
buffer for later flushing to MariaDB.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use axum::{
extract::{State, Request},
middleware::Next,
Expand Down
11 changes: 11 additions & 0 deletions src/middleware/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
/*
GC-Stats — API

Declares the middleware module and re-exports the auth and logging
submodules.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

pub mod auth;
pub mod logging;
11 changes: 11 additions & 0 deletions src/models/auth.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
GC-Stats — API

API key model and the SHA-256 hashing helper used to store and look up
keys without persisting them in plaintext.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use serde::{Serialize, Deserialize};
use sha2::{Digest, Sha256};
use sqlx::FromRow;
Expand Down
12 changes: 12 additions & 0 deletions src/models/entity.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
GC-Stats — API

Shared response models and helpers for players and teams: logo/photo URL
building, logo history partitioning, batched current-logo lookups, and
the `Player`/`Team` DB row types.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use sqlx::FromRow;
Expand Down
11 changes: 11 additions & 0 deletions src/models/game.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
GC-Stats — API

Response models for maps and rounds: per-map player stats, map metadata,
and per-round player stats.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use serde::{Serialize, Deserialize};
use sqlx::FromRow;
use utoipa::ToSchema;
Expand Down
11 changes: 11 additions & 0 deletions src/models/matchs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
GC-Stats — API

Response models for matches: the match record itself and its map
vetoes.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use serde::{Serialize, Deserialize};
use sqlx::FromRow;
use chrono::{ NaiveDateTime };
Expand Down
11 changes: 11 additions & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
GC-Stats — API

Declares the models module and re-exports the game, match, tournament,
entity and auth submodules.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

pub mod game;
pub mod matchs;
pub mod tournament;
Expand Down
10 changes: 10 additions & 0 deletions src/models/tournament.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
GC-Stats — API

Response models for tournaments: the tournament record and its phases.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use serde::{Serialize, Deserialize};
use sqlx::FromRow;
use chrono::NaiveDate;
Expand Down
13 changes: 13 additions & 0 deletions src/routes/dashboard.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
GC-Stats — API

Routes for the client-facing usage dashboard: login/logout via API key,
request statistics (summary, status breakdown, top endpoints,
time-bucketed chart), recent logs, and the paginated request history
page.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use std::net::SocketAddr;
use std::sync::Arc;
use askama::Template;
Expand Down
10 changes: 10 additions & 0 deletions src/routes/health.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
GC-Stats — API

Health check endpoint used for uptime monitoring.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use axum::{Json};
use serde_json::{json, Value};

Expand Down
11 changes: 11 additions & 0 deletions src/routes/map.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
GC-Stats — API

`/v1/map` endpoints: fetch a map's full details (teams, player stats)
and its per-round breakdown.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use std::collections::{BTreeMap, HashSet};
use axum::{extract::{Path, State}, Json, http::StatusCode, Router};
use std::sync::Arc;
Expand Down
11 changes: 11 additions & 0 deletions src/routes/matches.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
GC-Stats — API

`/v1/matches` endpoint: fetch a match's full details (teams, maps,
vetoes).

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use axum::{extract::{Path, State}, Json, http::StatusCode, Router};
use std::sync::Arc;
use axum::routing::get;
Expand Down
11 changes: 11 additions & 0 deletions src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
GC-Stats — API

Declares the routes module and assembles the versioned `/v1` API router
from the teams, players, tournaments, matches and map routers.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use std::sync::Arc;
use axum::Router;
use crate::AppState;
Expand Down
11 changes: 11 additions & 0 deletions src/routes/players.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
GC-Stats — API

`/v1/players` endpoints: search players by name, fetch a player's full
profile, their team history, and their photo history.

Copyright (c) 2026 Alice Alleman — GC-Stats-API
License: https://github.com/GC-Stats/API/blob/main/LICENSE.md (GC-Stats License v1.0)
Repository: https://github.com/GC-Stats/API
*/

use axum::{extract::{Path, State}, Json, http::StatusCode, Router};
use std::sync::Arc;
use axum::routing::get;
Expand Down
Loading
Loading