# gautam2176/tower-defense architecture

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

- Interactive diagram: https://gitdiagram.com/gautam2176/tower-defense
- Repository: https://github.com/gautam2176/tower-defense

## Overview

#### Purpose and Entry Points
This is a browser-run, vanilla JavaScript tower-defense game. Opening `index.html` loads the game client; runtime orchestration is centered in `JavaScript/index.js`. No server, framework, package runtime, or external API is indicated.

#### Game Loop and Orchestration
`JavaScript/index.js` is the likely control boundary for canvas setup, frame updates, rendering, wave progression, player input, and coordination of entity collections. It connects static level data with live enemies, towers, placement tiles, and projectiles.

#### Static Level Definition
Map and route configuration are separated from entity behavior:
- `JavaScript/data/map.js` supplies map/layout data.
- `JavaScript/data/waypoints.js` defines the path enemies traverse.
- `JavaScript/data/building_placment.js` defines valid tower-placement locations.

This makes level geometry/data an input boundary to the gameplay loop rather than embedding it in entity classes.

#### Core Entity Model
Gameplay behavior is modeled as object-oriented entities:
- `JavaScript/entities/sprite.js` provides common visual/sprite behavior.
- `JavaScript/entities/enemy.js` represents moving wave units, likely consuming waypoint data and tracking health/progress.
- `JavaScript/entities/building.js` represents placed defensive towers and their targeting/attack behavior.
- `JavaScript/entities/projectile.js` represents attacks traveling from buildings toward enemies.
- `JavaScript/entities/placement_tile.js` represents interactive map cells where buildings can be placed.

#### Primary Combat Flow
Enemies are created by the main runtime and move along `JavaScript/data/waypoints.js`. Placement tiles derived from `JavaScript/data/building_placment.js` accept player tower placement. Buildings detect or select enemies in range, create projectiles, and projectiles resolve collisions/damage against enemies. Enemy removal, base-reaching behavior, wave escalation, and redraws return to the central loop in `JavaScript/index.js`.

#### Rendering and Assets Boundary
Visual resources live under `assets/`; entity classes use sprite-oriented rendering through `JavaScript/entities/sprite.js`. `JavaScript/data/map.js` and the placement/path datasets define where assets and entities are rendered, while `JavaScript/index.js` owns frame sequencing. The application is fully client-side HTML/JavaScript, with browser rendering and input as its material runtime dependencies.

Main entry points: [`JavaScript/index.js`](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/index.js) (Game Loop), [`JavaScript/entities/sprite.js`](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/sprite.js) (Sprite Base), [`JavaScript/entities/building.js`](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/building.js) (Building), [`JavaScript/entities/enemy.js`](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/enemy.js) (Enemy)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Browser Game Runtime"]
  node_html["Game Entry<br/>HTML entry<br/>[index.html]"]
  node_game["Game Loop<br/>runtime orchestrator<br/>[index.js]"]
  node_browser(("Browser Canvas &amp; Input<br/>browser runtime"))
end

subgraph group_level["Level Data"]
  node_map["Map Layout<br/>level data<br/>[map.js]"]
  node_waypoints["Enemy Route<br/>level data<br/>[waypoints.js]"]
  node_placement_data["Placement Locations<br/>level data"]
end

subgraph group_entities["Gameplay Entities"]
  node_sprite["Sprite Base<br/>visual entity base<br/>[sprite.js]"]
  node_enemy["Enemy<br/>moving wave unit<br/>[enemy.js]"]
  node_building["Building<br/>defensive tower<br/>[building.js]"]
  node_projectile["Projectile<br/>combat attack<br/>[projectile.js]"]
  node_placement_tile["Placement Tile<br/>interactive map cell<br/>[placement_tile.js]"]
end

node_assets["Visual Assets<br/>static assets"]

node_html -->|"loads"| node_game
node_browser -->|"input and canvas"| node_game
node_game -->|"loads layout"| node_map
node_game -->|"loads route"| node_waypoints
node_game -->|"loads build locations"| node_placement_data
node_game -->|"spawns and updates"| node_enemy
node_game -->|"manages towers"| node_building
node_game -->|"creates from locations"| node_placement_tile
node_waypoints -->|"movement path"| node_enemy
node_placement_tile -->|"places"| node_building
node_building -->|"fires"| node_projectile
node_projectile -->|"damages"| node_enemy
node_sprite -->|"renders"| node_enemy
node_sprite -->|"renders"| node_building
node_sprite -->|"renders"| node_projectile
node_sprite -->|"renders"| node_placement_tile
node_assets -->|"visual resources"| node_sprite
node_game -->|"renders frames"| node_browser

click node_html "https://github.com/gautam2176/tower-defense/blob/main/index.html"
click node_game "https://github.com/gautam2176/tower-defense/blob/main/JavaScript/index.js"
click node_map "https://github.com/gautam2176/tower-defense/blob/main/JavaScript/data/map.js"
click node_waypoints "https://github.com/gautam2176/tower-defense/blob/main/JavaScript/data/waypoints.js"
click node_placement_data "https://github.com/gautam2176/tower-defense/blob/main/JavaScript/data/building_placment.js"
click node_sprite "https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/sprite.js"
click node_enemy "https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/enemy.js"
click node_building "https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/building.js"
click node_projectile "https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/projectile.js"
click node_placement_tile "https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/placement_tile.js"

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_html,node_game,node_browser toneBlue
class node_map,node_waypoints,node_placement_data toneAmber
class node_sprite,node_enemy,node_building,node_projectile,node_placement_tile toneMint
class node_assets toneNeutral
```

## Components

### Browser Game Runtime

- [Game Entry](https://github.com/gautam2176/tower-defense/blob/main/index.html): HTML entry · Browser loads the client. · `index.html`
- [Game Loop](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/index.js): runtime orchestrator · Coordinates input, waves, updates, and rendering. · `JavaScript/index.js`
- **Browser Canvas & Input**: browser runtime

### Level Data

- [Map Layout](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/data/map.js): level data · `JavaScript/data/map.js`
- [Enemy Route](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/data/waypoints.js): level data · `JavaScript/data/waypoints.js`
- [Placement Locations](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/data/building_placment.js): level data · `JavaScript/data/building_placment.js`

### Gameplay Entities

- [Sprite Base](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/sprite.js): visual entity base · Shared sprite-oriented rendering behavior. · `JavaScript/entities/sprite.js`
- [Enemy](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/enemy.js): moving wave unit · `JavaScript/entities/enemy.js`
- [Building](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/building.js): defensive tower · Targets enemies and launches attacks. · `JavaScript/entities/building.js`
- [Projectile](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/projectile.js): combat attack · Resolves damage against enemies. · `JavaScript/entities/projectile.js`
- [Placement Tile](https://github.com/gautam2176/tower-defense/blob/main/JavaScript/entities/placement_tile.js): interactive map cell · `JavaScript/entities/placement_tile.js`

### Other components

- **Visual Assets**: static assets

## Connections

- Game Entry → Game Loop: loads
- Browser Canvas & Input → Game Loop: input and canvas
- Game Loop → Map Layout: loads layout
- Game Loop → Enemy Route: loads route
- Game Loop → Placement Locations: loads build locations
- Game Loop → Enemy: spawns and updates
- Game Loop → Building: manages towers
- Game Loop → Placement Tile: creates from locations
- Enemy Route → Enemy: movement path
- Placement Tile → Building: places
- Building → Projectile: fires
- Projectile → Enemy: damages
- Sprite Base → Enemy: renders
- Sprite Base → Building: renders
- Sprite Base → Projectile: renders
- Sprite Base → Placement Tile: renders
- Visual Assets → Sprite Base: visual resources
- Game Loop → Browser Canvas & Input: renders frames
