# nano-a/towerdefense architecture

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

- Interactive diagram: https://gitdiagram.com/nano-a/towerdefense
- Repository: https://github.com/nano-a/towerdefense

## Overview

##### Project type and purpose
- Tower Defense is a standalone desktop game written in Java using Swing (UI) and Jackson (JSON parsing).
- It follows a modular, package-based architecture dividing responsibilities: UI, game state management, mechanics, utilities, resource loading, and input/event handling.

##### File structure
- Top-level organization:
- src/ – Java packages
– utilisateurinterface & compInterface: Swing UI classes and custom controls
– gestionnaire: core game loop, state machine (Deroulement, Etat, Evolueur)
– composants: domain model (Tour, Adversaire, ChampBataille, Munition)
– mecaniques, mouvement, cartographie, categories: pathfinding (A*), movement math, level maps, enums/types
– outils: resource loading (LecteurDeFichier, ChargImage), logging (Journalisateur), constants
– surveillant: global input hooks via JNativeHook (Gardien, Surveille)
– reglage: parameter management
- res/ – static resources (images, level JSON/CSV, external JARs)
- bin/ – compiled output and mirrored resource structure

##### README for technical insights
- MVC-style separation: UI packages vs. logic packages
- Uses multithreading for smooth updates
- Levels defined in JSON/CSV, parsed by Jackson libraries
- Entry point: utilisateurinterface.CadreJeu

##### Final advice
- Don’t omit cross-cutting services like logging and configuration.
- Explicitly show the entry point (utilisateurinterface.CadreJeu) and its initialization flow.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interface Layer
    subgraph "User Interface Layer"
        CadreJeu["CadreJeu (Entry Point)"]:::ui
        UI1["UI Package"]:::ui
        UI2["Custom Controls"]:::ui
    end

    %% Input Handling
    subgraph "Input Handling"
        SurveillantPkg["Input Hooks"]:::input
        Gardien["Gardien"]:::input
        Surveille["Surveille"]:::input
    end

    %% Controller / Game Manager
    subgraph "Controller / Game Manager"
        Deroulement["Deroulement\n(Game Loop)"]:::core
        Etat["Etat"]:::core
        Evolueur["Evolueur"]:::core
        GenerateurEnnemi["GenerateurEnnemi"]:::core
    end

    %% Domain Model
    subgraph "Domain Model"
        Tour["Tour"]:::domain
        Adversaire["Adversaire"]:::domain
        Munition["Munition"]:::domain
        ChampBataille["ChampBataille"]:::domain
        Fortresse["Fortresse"]:::domain
        ElementJeu["ElementJeu"]:::domain
        ElementMobile["ElementMobile"]:::domain
    end

    %% Mechanics & Pathfinding
    subgraph "Mechanics & Pathfinding"
        AnalyseurNiv["AnalyseurNiv"]:::mech
        AnalyseurNivJson["AnalyseurNivJson"]:::mech
        Cartographe["Cartographe"]:::mech
        Chemin["Chemin"]:::mech
        DeplacementAdv["DeplacementAdv"]:::mech
        Trajectoire["Trajectoire"]:::mech
        PlanDeJeu["PlanDeJeu"]:::mech
        EtatPartie["EtatPartie"]:::mech
        Geometrie["Geometrie"]:::mech
        Vecteur["Vecteur"]:::mech
    end

    %% Persistence & Resource Loading
    subgraph "Persistence & Resource Loading"
        LecteurDeFichier["LecteurDeFichier"]:::persist
        ChargImage["ChargImage"]:::persist
        ComposantUtil["Composant"]:::persist
    end

    %% Utilities & Configuration
    subgraph "Utilities & Configuration"
        Journalisateur["Journalisateur"]:::util
        Constantes["Constantes"]:::util
        NivJournal["NivJournal"]:::util
        GestionParam["GestionParam"]:::util
        Param["Param"]:::util
    end

    %% External Libraries
    subgraph "External Libraries"
        Jackson["Jackson JARs"]:::external
        JNativeHook["JNativeHook"]:::external
    end

    %% Static Resources
    subgraph "Static Resources"
        Levels["Level JSON/CSV"]:::resource
        TerrainMap["Terrain Maps"]:::resource
        Sprites["Sprites & Icons"]:::resource
    end

    %% Relationships
    CadreJeu -->|initializes| Deroulement
    CadreJeu -->|loads UI| UI1
    CadreJeu -->|loads UI| UI2
    UI1 -->|user actions| Deroulement
    UI2 -->|user actions| Deroulement
    SurveillantPkg -->|captures input| Deroulement
    Gardien -->|monitors| Surveille
    Surveille -->|notifies| Deroulement
    Deroulement -->|manages state| Etat
    Deroulement -->|transitions| Evolueur
    Deroulement -->|spawns enemies| GenerateurEnnemi
    Deroulement <-->|updates| Tour
    Deroulement <-->|reads/writes| Adversaire
    Deroulement <-->|updates| Munition
    Deroulement <-->|updates| ChampBataille
    Deroulement -->|requests path| AnalyseurNivJson
    AnalyseurNivJson -->|parses level| LecteurDeFichier
    AnalyseurNivJson -->|uses Jackson| Jackson
    LecteurDeFichier -->|loads levels| Levels
    LecteurDeFichier -->|loads maps| TerrainMap
    AnalyseurNiv -->|analyzes| Levels
    AnalyseurNivJson -->|builds map| PlanDeJeu
    PlanDeJeu -->|generates graph| Cartographe
    Cartographe -->|computes| Chemin
    Chemin -->|drives| DeplacementAdv
    DeplacementAdv -->|uses| Geometrie
    Geometrie -->|calculates| Vecteur
    Deroulement -->|logs| Journalisateur
    Deroulement -->|reads config| GestionParam
    GestionParam -->|uses| Param
    Deroulement -->|loads images| ChargImage
    ChargImage -->|provides| Sprites
    Jackson -.->|library| AnalyseurNivJson
    JNativeHook -.->|library| SurveillantPkg

    %% Click Events
    click CadreJeu "https://github.com/nano-a/towerdefense/blob/main/src/utilisateurinterface/CadreJeu.java"
    click UI1 "https://github.com/nano-a/towerdefense/tree/main/src/utilisateurinterface/"
    click UI2 "https://github.com/nano-a/towerdefense/tree/main/src/compInterface/"
    click SurveillantPkg "https://github.com/nano-a/towerdefense/tree/main/src/surveillant/"
    click Gardien "https://github.com/nano-a/towerdefense/blob/main/src/surveillant/Gardien.java"
    click Surveille "https://github.com/nano-a/towerdefense/blob/main/src/surveillant/Surveille.java"
    click Deroulement "https://github.com/nano-a/towerdefense/blob/main/src/gestionnaire/Deroulement.java"
    click Etat "https://github.com/nano-a/towerdefense/blob/main/src/gestionnaire/Etat.java"
    click Evolueur "https://github.com/nano-a/towerdefense/blob/main/src/gestionnaire/Evolueur.java"
    click GenerateurEnnemi "https://github.com/nano-a/towerdefense/blob/main/src/gestionnaire/GenerateurEnnemi.java"
    click Tour "https://github.com/nano-a/towerdefense/blob/main/src/composants/Tour.java"
    click Adversaire "https://github.com/nano-a/towerdefense/blob/main/src/composants/Adversaire.java"
    click Munition "https://github.com/nano-a/towerdefense/blob/main/src/composants/Munition.java"
    click ChampBataille "https://github.com/nano-a/towerdefense/blob/main/src/composants/ChampBataille.java"
    click Fortresse "https://github.com/nano-a/towerdefense/blob/main/src/composants/Fortresse.java"
    click ElementJeu "https://github.com/nano-a/towerdefense/blob/main/src/composants/ElementJeu.java"
    click ElementMobile "https://github.com/nano-a/towerdefense/blob/main/src/composants/ElementMobile.java"
    click AnalyseurNiv "https://github.com/nano-a/towerdefense/blob/main/src/mecaniques/AnalyseurNiv.java"
    click AnalyseurNivJson "https://github.com/nano-a/towerdefense/blob/main/src/mecaniques/AnalyseurNivJson.java"
    click Cartographe "https://github.com/nano-a/towerdefense/blob/main/src/mecaniques/Cartographe.java"
    click Chemin "https://github.com/nano-a/towerdefense/blob/main/src/mecaniques/Chemin.java"
    click DeplacementAdv "https://github.com/nano-a/towerdefense/blob/main/src/mecaniques/DeplacementAdv.java"
    click Trajectoire "https://github.com/nano-a/towerdefense/blob/main/src/mecaniques/Trajectoire.java"
    click PlanDeJeu "https://github.com/nano-a/towerdefense/blob/main/src/cartographie/PlanDeJeu.java"
    click EtatPartie "https://github.com/nano-a/towerdefense/blob/main/src/cartographie/EtatPartie.java"
    click Geometrie "https://github.com/nano-a/towerdefense/blob/main/src/mouvement/Geometrie.java"
    click Vecteur "https://github.com/nano-a/towerdefense/blob/main/src/mouvement/Vecteur.java"
    click LecteurDeFichier "https://github.com/nano-a/towerdefense/blob/main/src/outils/LecteurDeFichier.java"
    click ChargImage "https://github.com/nano-a/towerdefense/blob/main/src/outils/ChargImage.java"
    click ComposantUtil "https://github.com/nano-a/towerdefense/blob/main/src/outils/Composant.java"
    click Journalisateur "https://github.com/nano-a/towerdefense/blob/main/src/outils/Journalisateur.java"
    click Constantes "https://github.com/nano-a/towerdefense/blob/main/src/outils/Constantes.java"
    click NivJournal "https://github.com/nano-a/towerdefense/blob/main/src/outils/NivJournal.java"
    click GestionParam "https://github.com/nano-a/towerdefense/blob/main/src/reglage/GestionParam.java"
    click Param "https://github.com/nano-a/towerdefense/blob/main/src/reglage/Param.java"

    %% Styles
    classDef ui fill:#b2f2bb,stroke:#2f8f3f
    classDef input fill:#cff4fc,stroke:#0cc2e2
    classDef core fill:#cfe2ff,stroke:#1e65b3
    classDef domain fill:#ffe5b4,stroke:#d68a31
    classDef mech fill:#ffe5b4,stroke:#d68a31
    classDef persist fill:#e2e3e5,stroke:#6c757d
    classDef util fill:#e2e3e5,stroke:#6c757d
    classDef external fill:#f8d7da,stroke:#a71d2a
    classDef resource fill:#fff3cd,stroke:#d39e00
```
