# sebsowter/phaser-simple-soccer architecture

> Architecture diagram of the GitHub repository sebsowter/phaser-simple-soccer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sebsowter/phaser-simple-soccer
- Repository: https://github.com/sebsowter/phaser-simple-soccer

## Overview

##### Project Type & Purpose
- This is a single‐page browser game built with Phaser (a JavaScript/TypeScript game framework).
- It implements Chapter 4 of “Programming Game AI by Example” (a simple soccer simulation).
- It has no server side; it is a static web application bundled via Webpack and deployed (for example) to GitHub Pages.

##### High‐Level Components
a. Build Pipeline
- TypeScript source files (src/js/…)
- Webpack (webpack.config.js)
- tsconfig.json for compilation settings
→ Produces a bundled JavaScript file (bundle.js) and copies assets.
b. Static Hosting
- index.html loads the bundle & assets at runtime
- assets/images (sprites, textures)
c. Runtime Engine
- Phaser library (external dependency, included via package.json)
- LoaderScene (preloads images, audio)
- PitchScene (main game loop)
d. Game Modules
- constants (physics, players, teams)
- types (shared TypeScript types)
- utils (helper functions)
- gameObjects (FieldPlayer, Goal, Ball, Team, Score, SupportSpots, etc.)
- PlayerFactory (builds players on demand)
e. Data Flow & Interactions
- index.html → bundle.js → Phaser.Game initialization
- LoaderScene loads assets → transitions to PitchScene
- PitchScene instantiates gameObjects via PlayerFactory & uses constants/types/utils
- GameObjects update and render each frame

##### Architectural Patterns & Principles
- Modular code organization by feature: constants, types, utils, gameObjects, scenes
- Factory pattern for player creation (PlayerFactory)
- Scene graph pattern (Phaser Scenes manage lifecycle)
- Single‐page static application (no backend)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build Pipeline
    subgraph "Build Pipeline"
        direction TB
        TS["TypeScript Sources"]:::build
        TSConfig["tsconfig.json"]:::build
        PackageJSON["package.json"]:::build
        Webpack["webpack.config.js"]:::build
        Bundle["bundle.js"]:::build
        TS -->|"compile"| Webpack
        TSConfig --> Webpack
        PackageJSON --> Webpack
        Webpack -->|"bundle"| Bundle
    end

    %% Static Hosting
    subgraph "Static Hosting"
        direction TB
        HTML["index.html"]:::runtime
        Assets["assets/images"]:::runtime
    end

    %% Runtime Engine
    subgraph "Runtime Engine"
        direction TB
        Entry["src/js/index.ts"]:::runtime
        Phaser["Phaser 3.x"]:::engine
    end

    %% Scenes
    subgraph "Scenes"
        direction TB
        Loader["LoaderScene"]:::scene
        Pitch["PitchScene"]:::scene
    end

    %% Modules
    subgraph "Modules"
        direction TB
        Constants["constants"]:::module
        Types["types"]:::module
        Utils["utils"]:::module
    end

    %% GameObjects
    subgraph "GameObjects"
        direction TB
        Factory["PlayerFactory"]:::factory
        PlayerBase["PlayerBase"]:::gameobj
        FieldPlayer["FieldPlayer"]:::gameobj
        Goalkeeper["Goalkeeper"]:::gameobj
        SoccerBall["SoccerBall"]:::gameobj
        SoccerPitch["SoccerPitch"]:::gameobj
        GoalObj["Goal"]:::gameobj
        SoccerTeam["SoccerTeam"]:::gameobj
        Score["Score"]:::gameobj
        SupportSpot["SupportSpot"]:::gameobj
        SupportSpots["SupportSpots"]:::gameobj
        Info["Info"]:::gameobj
    end

    %% Data Flow
    Bundle -->|"served by"| HTML
    HTML -->|"boots"| Entry
    Entry -->|"init"| Phaser
    Phaser -->|"preload()/create()/update()"| Loader
    Loader -->|"transition"| Pitch
    Pitch -->|"uses"| Factory
    Factory -->|"creates"| PlayerBase
    PlayerBase -->|"extends"| FieldPlayer
    PlayerBase -->|"extends"| Goalkeeper
    Factory --> SoccerBall
    Factory --> SoccerPitch
    Factory --> GoalObj
    Factory --> SoccerTeam
    Factory --> Score
    Factory --> SupportSpot
    Factory --> SupportSpots
    Factory --> Info

    %% Shared Dependencies
    Constants -.-> Loader
    Types -.-> Loader
    Utils -.-> Loader
    Constants -.-> Pitch
    Types -.-> Pitch
    Utils -.-> Pitch
    Constants -.-> Factory
    Types -.-> Factory
    Utils -.-> Factory

    %% Asset Flow
    Loader -->|"preload assets"| Assets
    Assets -->|"used by"| GameObjects

    %% Styling
    classDef build fill:#BBDEFB,stroke:#1E88E5,color:#0D47A1
    classDef runtime fill:#C8E6C9,stroke:#2E7D32,color:#1B5E20
    classDef engine fill:#D1C4E9,stroke:#512DA8,color:#311B92
    classDef scene fill:#FFE0B2,stroke:#EF6C00,color:#E65100
    classDef module fill:#FFF9C4,stroke:#F9A825,color:#F57F17
    classDef gameobj fill:#F8BBD0,stroke:#C2185B,color:#880E4F
    classDef factory fill:#FFCDD2,stroke:#B71C1C,color:#4A148C

    class TS,TSConfig,PackageJSON,Webpack,Bundle build
    class HTML,Assets,Entry runtime
    class Phaser engine
    class Loader,Pitch scene
    class Constants,Types,Utils module
    class Factory,PlayerBase,FieldPlayer,Goalkeeper,SoccerBall,SoccerPitch,GoalObj,SoccerTeam,Score,SupportSpot,SupportSpots,Info gameobj
    class Factory factory

    %% Click Events
    click Webpack "https://github.com/sebsowter/phaser-simple-soccer/blob/master/webpack.config.js"
    click TSConfig "https://github.com/sebsowter/phaser-simple-soccer/blob/master/tsconfig.json"
    click PackageJSON "https://github.com/sebsowter/phaser-simple-soccer/blob/master/package.json"
    click HTML "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/index.html"
    click Assets "https://github.com/sebsowter/phaser-simple-soccer/tree/master/src/assets/images"
    click Entry "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/index.ts"
    click Loader "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/scenes/LoaderScene.ts"
    click Pitch "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/scenes/PitchScene.ts"
    click Constants "https://github.com/sebsowter/phaser-simple-soccer/tree/master/src/js/constants"
    click Types "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/types/index.ts"
    click Utils "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/utils/index.ts"
    click PlayerBase "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/gameObjects/PlayerBase.ts"
    click FieldPlayer "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/gameObjects/FieldPlayer.ts"
    click Goalkeeper "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/gameObjects/Goalkeeper.ts"
    click SoccerBall "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/gameObjects/SoccerBall.ts"
    click SoccerPitch "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/gameObjects/SoccerPitch.ts"
    click GoalObj "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/gameObjects/Goal.ts"
    click SoccerTeam "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/gameObjects/SoccerTeam.ts"
    click Score "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/gameObjects/Score.ts"
    click SupportSpot "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/gameObjects/SupportSpot.ts"
    click SupportSpots "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/gameObjects/SupportSpots.ts"
    click Info "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/gameObjects/Info.ts"
    click Factory "https://github.com/sebsowter/phaser-simple-soccer/blob/master/src/js/gameObjects/PlayerFactory.ts"
```
