# hammad123454321/gta-game-kill-detect architecture

> Architecture diagram of the GitHub repository hammad123454321/gta-game-kill-detect, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hammad123454321/gta-game-kill-detect
- Repository: https://github.com/hammad123454321/gta-game-kill-detect

## Overview

1. **Overall shape**
   This is a two-tier MVP: a **Next.js frontend** for upload/configuration/results, and a **FastAPI backend** that handles video ingestion, asynchronous clip generation, storage, and download delivery.

2. **User-facing flow**
   The main workflow is: upload a gameplay recording, choose clip padding and detection mode, start processing, wait for job completion, then download either individual clips or a ZIP archive. The frontend is the orchestration UI; the backend owns all heavy video work.

3. **Frontend boundary**
   `frontend/app/page.js` is the main UI surface. It likely talks to backend endpoints for upload, job start, status polling, and result retrieval. The frontend is intentionally thin: it does not process media locally, and only presents progress/results.

4. **API layer**
   The backend exposes separate route modules under `backend/app/routes/`:
   - `upload.py` for accepting source videos
   - `process.py` for starting clip generation
   - `status.py` for job progress
   - `results.py` for listing/downloading generated artifacts  
   This separation makes the API boundary clear: upload, start, monitor, fetch.

5. **Async job processing**
   Heavy work is offloaded from the HTTP request path into a background pipeline under `backend/app/jobs/`. `worker.py` is the queue worker entrypoint, and `processor.py` coordinates the end-to-end pipeline. The readme indicates **Redis + RQ** is used so video processing runs asynchronously instead of blocking the web server.

6. **Core processing pipeline**
   The main media pipeline is split into focused services under `backend/app/services/`:
   - `detector.py` finds kill timestamps
   - `cutter.py` extracts clips with FFmpeg
   - `compressor.py` shrinks clips to the 9.9 MB target
   - `zipper.py` bundles outputs for download
   - `cleanup.py` removes temporary artifacts  
   This is the key backend boundary: detect → cut → compress → package → cleanup.

7. **Detection modes and signal sources**
   The repo supports multiple detection strategies, reflected in the README and `detector.py`:
   - manual timestamp entry for exact verified kills
   - OpenCV-based hitmarker / flash detection
   - OCR-based kill-feed detection
   - OCR-validated top-center kill counter detection  
   Architecturally, this means the detection layer is pluggable, while the downstream clip pipeline stays the same regardless of how timestamps were produced.

8. **Storage model**
   The backend uses **SQLite** via SQLAlchemy (`database.py`, `models.py`) for persistent metadata such as jobs, uploads, detected events, and processing state. Generated media lives in a Docker-managed storage volume (`backend_storage` in the README), not in the database. That keeps metadata and large binary artifacts separated.

9. **Media and filesystem utilities**
   Utility modules under `backend/app/utils/` wrap low-level concerns:
   - `ffmpeg_utils.py` for FFmpeg interaction
   - `file_utils.py` for path/file management and validation  
   These utilities form the boundary between application logic and system-level media tooling.

10. **Configuration and tuning**
   `backend/app/config.py` and `backend/.env.example` expose a lot of detector and pipeline tuning, especially for GTA RP HUD variability: ROI bounds, score thresholds, OCR sampling, cooldowns, and clip spacing. That configuration layer is important because detection accuracy is environment-dependent and changes the behavior of the same processing pipeline.

11. **Deployment and runtime**
   The repo is container-first: `docker-compose.yml` runs the frontend, backend, Redis, and supporting storage; `docker-compose.prod.yml` and `backend/Dockerfile`/`frontend/Dockerfile` support production packaging; `.github/workflows/deploy.yml` indicates CI/CD deployment automation. This means the architecture is designed to run as a small distributed system rather than a single monolith.

12. **Artifact lifecycle**
   The output of a successful run is a set of compressed MP4 clips plus an optional ZIP archive. Temporary frames, raw cuts, and intermediate encodes are transient and cleaned up by the backend. That lifecycle is important for diagramming: source video enters once, processing stages fan out internally, and final artifacts exit through download endpoints.

Main entry points: [`backend/app/jobs/processor.py`](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/jobs/processor.py) (Processor), [`backend/app/main.py`](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/main.py) (API App), [`docker-compose.yml`](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/docker-compose.yml) (Compose Stack), [`backend/app/services/detector.py`](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/services/detector.py) (Detector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_page["Main UI<br/>Next.js page<br/>[page.js]"]
  node_frontend_shell["App Shell<br/>Next.js layout<br/>[layout.js]"]
end

subgraph group_backend_api["API Layer"]
  node_backend_main["API App<br/>[main.py]"]
  node_route_upload["Upload API<br/>route module<br/>[upload.py]"]
  node_route_process["Process API<br/>route module<br/>[process.py]"]
  node_route_status["Status API<br/>route module<br/>[status.py]"]
  node_route_results["Results API<br/>route module<br/>[results.py]"]
end

subgraph group_backend_core["Processing Core"]
  node_job_worker{{"Worker<br/>[worker.py]"}}
  node_job_processor{{"Processor<br/>job orchestration<br/>[processor.py]"}}
  node_detector["Detector<br/>media analysis<br/>[detector.py]"]
  node_cutter["Cutter<br/>FFmpeg clipper<br/>[cutter.py]"]
  node_compressor["Compressor<br/>media encoder<br/>[compressor.py]"]
  node_zipper["Zipper<br/>archive packager<br/>[zipper.py]"]
  node_cleanup["Cleanup<br/>[cleanup.py]"]
  node_database[("SQLite DB<br/>metadata store<br/>[database.py]")]
  node_models["Data Models<br/>SQLAlchemy models<br/>[models.py]"]
  node_config["Config<br/>pipeline tuning<br/>[config.py]"]
  node_ffmpeg_utils["FFmpeg Utils<br/>media utility<br/>[ffmpeg_utils.py]"]
  node_file_utils["File Utils<br/>filesystem utility<br/>[file_utils.py]"]
end

subgraph group_infra["Infrastructure"]
  node_redis["Redis Queue<br/>job broker"]
  node_storage[("Storage Volume<br/>artifact store")]
  node_compose{{"Compose Stack<br/>deployment<br/>[docker-compose.yml]"}}
end

node_frontend_page -->|"API calls"| node_backend_main
node_frontend_shell -->|"wraps"| node_frontend_page
node_backend_main -->|"mounts"| node_route_upload
node_backend_main -->|"mounts"| node_route_process
node_backend_main -->|"mounts"| node_route_status
node_backend_main -->|"mounts"| node_route_results
node_route_upload -->|"writes"| node_storage
node_route_process -->|"enqueues"| node_redis
node_route_status -->|"reads"| node_database
node_route_results -->|"serves"| node_storage
node_redis -->|"dequeues"| node_job_worker
node_job_worker -->|"executes"| node_job_processor
node_job_processor -->|"detects"| node_detector
node_job_processor -->|"cuts"| node_cutter
node_job_processor -->|"compresses"| node_compressor
node_job_processor -->|"packages"| node_zipper
node_job_processor -->|"cleans"| node_cleanup
node_detector -->|"uses"| node_config
node_detector -->|"analyzes"| node_ffmpeg_utils
node_cutter -->|"encodes"| node_ffmpeg_utils
node_compressor -->|"transcodes"| node_ffmpeg_utils
node_job_processor -->|"updates"| node_database
node_database -->|"maps"| node_models
node_job_processor -->|"manages files"| node_file_utils
node_compose -->|"runs"| node_frontend_page
node_compose -->|"runs"| node_backend_main
node_compose -->|"runs"| node_redis
node_compose -->|"mounts"| node_storage

click node_frontend_page "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/frontend/app/page.js"
click node_frontend_shell "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/frontend/app/layout.js"
click node_backend_main "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/main.py"
click node_route_upload "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/routes/upload.py"
click node_route_process "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/routes/process.py"
click node_route_status "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/routes/status.py"
click node_route_results "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/routes/results.py"
click node_job_worker "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/jobs/worker.py"
click node_job_processor "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/jobs/processor.py"
click node_detector "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/services/detector.py"
click node_cutter "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/services/cutter.py"
click node_compressor "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/services/compressor.py"
click node_zipper "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/services/zipper.py"
click node_cleanup "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/services/cleanup.py"
click node_database "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/database.py"
click node_models "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/models.py"
click node_config "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/config.py"
click node_ffmpeg_utils "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/utils/ffmpeg_utils.py"
click node_file_utils "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/utils/file_utils.py"
click node_compose "https://github.com/hammad123454321/gta-game-kill-detect/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_page,node_frontend_shell toneBlue
class node_backend_main,node_route_upload,node_route_process,node_route_status,node_route_results toneAmber
class node_job_worker,node_job_processor,node_detector,node_cutter,node_compressor,node_zipper,node_cleanup,node_database,node_models,node_config,node_ffmpeg_utils,node_file_utils toneMint
class node_redis,node_storage,node_compose toneRose
```

## Components

### Frontend

Next.js user interface for upload, processing, and results

- [Main UI](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/frontend/app/page.js): Next.js page · Upload, configure, monitor, and download workflow surface · `frontend/app/page.js`
- [App Shell](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/frontend/app/layout.js): Next.js layout · Global app structure and styling wrapper · `frontend/app/layout.js`

### API Layer

FastAPI app entrypoint and route modules

- [API App](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/main.py): FastAPI app · Backend application entrypoint and router wiring · `backend/app/main.py`
- [Upload API](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/routes/upload.py): route module · Accepts source video uploads · `backend/app/routes/upload.py`
- [Process API](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/routes/process.py): route module · Starts clip generation jobs · `backend/app/routes/process.py`
- [Status API](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/routes/status.py): route module · Reports job progress and state · `backend/app/routes/status.py`
- [Results API](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/routes/results.py): route module · Lists and serves generated clips and archives · `backend/app/routes/results.py`

### Processing Core

Async jobs, media pipeline, storage, and config

- [Worker](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/jobs/worker.py): RQ worker · Background queue worker entrypoint · `backend/app/jobs/worker.py`
- [Processor](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/jobs/processor.py): job orchestration · Coordinates the end-to-end async pipeline · `backend/app/jobs/processor.py`
- [Detector](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/services/detector.py): media analysis · Finds kill timestamps using manual and vision/OCR modes · `backend/app/services/detector.py`
- [Cutter](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/services/cutter.py): FFmpeg clipper · Extracts clips from the source recording · `backend/app/services/cutter.py`
- [Compressor](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/services/compressor.py): media encoder · Shrinks clips toward the target size limit · `backend/app/services/compressor.py`
- [Zipper](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/services/zipper.py): archive packager · Bundles clips into downloadable ZIP archives · `backend/app/services/zipper.py`
- [Cleanup](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/services/cleanup.py): artifact cleanup · Removes temporary frames, cuts, and intermediates · `backend/app/services/cleanup.py`
- [SQLite DB](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/database.py): metadata store · Persists jobs, uploads, detected events, and processing state · `backend/app/database.py`
- [Data Models](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/models.py): SQLAlchemy models · Database schema and ORM entities · `backend/app/models.py`
- [Config](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/config.py): pipeline tuning · Environment-driven thresholds and detector settings · `backend/app/config.py`
- [FFmpeg Utils](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/utils/ffmpeg_utils.py): media utility · Low-level FFmpeg integration helpers · `backend/app/utils/ffmpeg_utils.py`
- [File Utils](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/backend/app/utils/file_utils.py): filesystem utility · Path, validation, and file management helpers · `backend/app/utils/file_utils.py`

### Infrastructure

Runtime services and deployment packaging

- **Redis Queue**: job broker · Backs asynchronous RQ processing
- **Storage Volume**: artifact store · Docker-managed volume for source videos and outputs
- [Compose Stack](https://github.com/hammad123454321/gta-game-kill-detect/blob/main/docker-compose.yml): deployment · Container orchestration for frontend, backend, Redis, and storage · `docker-compose.yml`

## Connections

- Main UI → API App: API calls · UI talks to backend endpoints for upload, processing, status, and downloads
- App Shell → Main UI: wraps · App shell provides the page framework and styling
- API App → Upload API: mounts · Main app registers upload routes
- API App → Process API: mounts · Main app registers process routes
- API App → Status API: mounts · Main app registers status routes
- API App → Results API: mounts · Main app registers results routes
- Upload API → Storage Volume: writes · Uploaded source media is stored on disk volume
- Process API → Redis Queue: enqueues · Processing requests are queued for async execution
- Status API → SQLite DB: reads · Status endpoint reads persisted job state
- Results API → Storage Volume: serves · Results endpoint exposes generated artifacts
- Redis Queue → Worker: dequeues · Worker consumes queued processing jobs
- Worker → Processor: executes · Worker hands off to pipeline orchestration
- Processor → Detector: detects · Pipeline first identifies kill timestamps
- Processor → Cutter: cuts · Pipeline extracts clips after detection
- Processor → Compressor: compresses · Pipeline reduces clip sizes before delivery
- Processor → Zipper: packages · Pipeline optionally bundles outputs into ZIPs
- Processor → Cleanup: cleans · Pipeline removes temporary artifacts at the end
- Detector → Config: uses · Detection behavior is tuned by environment settings
- Detector → FFmpeg Utils: analyzes · Media analysis relies on low-level video tooling
- Cutter → FFmpeg Utils: encodes · Clip extraction uses FFmpeg helpers
- Compressor → FFmpeg Utils: transcodes · Compression is implemented through FFmpeg wrappers
- Processor → SQLite DB: updates · Processing state is persisted through ORM-backed metadata
- SQLite DB → Data Models: maps · ORM models define persisted entities
- Processor → File Utils: manages files · Pipeline uses filesystem helpers for paths and validation
- Compose Stack → Main UI: runs · Compose stack deploys the frontend service
- Compose Stack → API App: runs · Compose stack deploys the backend service
- Compose Stack → Redis Queue: runs · Compose stack provides the queue broker
- Compose Stack → Storage Volume: mounts · Compose stack provisions persistent artifact storage
