# abbiereid/hand-controlled-pong architecture

> Architecture diagram of the GitHub repository abbiereid/hand-controlled-pong, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abbiereid/hand-controlled-pong
- Repository: https://github.com/abbiereid/hand-controlled-pong

## Overview

##### Main Components
- FXGL Game Engine: This external library provides the underlying game loop, rendering, physics, asset management, input handling, etc.
- PongApp: This is the main entry point of the game (located in Pong/src/main/java/com/almasb/fxglgames/pong/PongApp.java). It initializes the application and starts the game loop.
- Game Entities and Components:
- BallComponent manages the ball’s behavior.
- BatComponent and EnemyBatComponent manage the batting mechanics.
- EntityType provides definitions for different types of entities.
- PongFactory is responsible for creating and assembling various game entities.
- UI and Configuration:
- MainUIController and the FXML file (assets/ui/main.fxml) handle the user interface elements.
- Assets (sounds and UI resources) in the resources directory provide multimedia feedback.
- Build & Deployment:
- The pom.xml file governs the build process using Maven, along with several CI/CD configuration files (.travis.yml, GitHub workflows) that aid in ensuring code quality and building for different environments like mobile with GraalVM.

##### File Structure for Architectural Choices
- The package structure (com.almasb.fxglgames.pong) shows component-based modularity, a common design in game development where entities and associated behaviors are separated.
- Resources are partitioned distinctly from source code ensuring asset management is clearly isolated.
- The inclusion of JavaFX FXML files hints at a clear separation of view (UI) from the core game logic.
- The directory also includes project configuration (pom.xml, .travis.yml) that reflects the automated build/test pipeline.

##### Determining Relationships and Interactions
- PongApp (the main application) initializes the FXGL game engine, registers the factories, and sets up the game scene.
- The PongFactory is invoked by the game engine to create game entities (ball, bats, etc.). Each game entity comprises various components (BallComponent, BatComponent, EnemyBatComponent) which define their behavior.
- The UI Controller (MainUIController) manages input and overlays tied to the game’s state.
- Assets (audio and UI elements) are loaded at runtime and connected to corresponding game events (ball hitting bat/wall triggers sounds).

##### Architectural Patterns and Design Principles
- Component-Based Design: Each game entity is modular, using small components for specific behaviors (e.g., dragging, collision) which can be reused.
- Separation of Concerns: The game engine logic (FXGL), the UI (FXML and its controller), and the game logic (in individual component classes) are well separated.
- Factory Pattern: The PongFactory encapsulates game entity creation, promoting loose coupling and scalability.
- Maven Build Lifecycle: The pom.xml encapsulates dependency resolution, build, and deployment configurations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Game Engine & Core"
        FXGL["FXGL Game Engine"]:::engine
        PongApp["PongApp (Main Application)"]:::core
        PongFactory["PongFactory (Entity Construction)"]:::core
        BallComponent["BallComponent"]:::core
        BatComponent["BatComponent"]:::core
        EnemyBatComponent["EnemyBatComponent"]:::core
        EntityType["EntityType"]:::core
    end

    subgraph "User Interface"
        MainUIController["MainUIController (UI Controller)"]:::ui
        FXML["FXML UI (User Interface Layout)"]:::ui
        Assets["Assets (Sounds and UI Resources)"]:::ui
    end

    subgraph "Build & Deployment"
        Build["Build & Deployment Tools"]:::build
    end

    PongApp -->|"initializes"| FXGL
    PongApp -->|"calls"| PongFactory
    PongFactory -->|"creates"| BallComponent
    PongFactory -->|"creates"| BatComponent
    PongFactory -->|"creates"| EnemyBatComponent
    PongFactory -->|"defines"| EntityType
    PongApp -->|"integrates"| MainUIController
    MainUIController -->|"loads"| FXML
    FXML -->|"loads"| Assets
    Build -->|"builds"| PongApp

    click PongApp "https://github.com/abbiereid/hand-controlled-pong/blob/master/Pong/src/main/java/com/almasb/fxglgames/pong/PongApp.java"
    click PongFactory "https://github.com/abbiereid/hand-controlled-pong/blob/master/Pong/src/main/java/com/almasb/fxglgames/pong/PongFactory.java"
    click BallComponent "https://github.com/abbiereid/hand-controlled-pong/blob/master/Pong/src/main/java/com/almasb/fxglgames/pong/BallComponent.java"
    click BatComponent "https://github.com/abbiereid/hand-controlled-pong/blob/master/Pong/src/main/java/com/almasb/fxglgames/pong/BatComponent.java"
    click EnemyBatComponent "https://github.com/abbiereid/hand-controlled-pong/blob/master/Pong/src/main/java/com/almasb/fxglgames/pong/EnemyBatComponent.java"
    click EntityType "https://github.com/abbiereid/hand-controlled-pong/blob/master/Pong/src/main/java/com/almasb/fxglgames/pong/EntityType.java"
    click MainUIController "https://github.com/abbiereid/hand-controlled-pong/blob/master/Pong/src/main/java/com/almasb/fxglgames/pong/MainUIController.java"
    click FXML "https://github.com/abbiereid/hand-controlled-pong/blob/master/Pong/src/main/resources/assets/ui/main.fxml"
    click Assets "https://github.com/abbiereid/hand-controlled-pong/tree/master/Pong/src/main/resources/assets"
    click Build "https://github.com/abbiereid/hand-controlled-pong/blob/master/Pong/pom.xml"

    classDef engine fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef core fill:#A9DFBF,stroke:#1D8348,stroke-width:2px;
    classDef ui fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef build fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
```
