# imkennyyip/candy-crush architecture

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

- Interactive diagram: https://gitdiagram.com/imkennyyip/candy-crush
- Repository: https://github.com/imkennyyip/candy-crush

## Overview

##### Main Components
- Frontend Structure: Since this is a web-based game, start by highlighting the frontend components:
a. HTML (index.html): Serves as the main entry point that organizes the layout and markup.
b. CSS (candy.css): Styles the game elements to achieve the Candy Crush look and feel.
c. JavaScript (candy.js): Contains the core game logic for candy swapping, matching, and generating new candy pieces.
d. Assets (images folder): Includes all graphical assets such as candy images used in the game.

##### Out Component Relationships and Interactions
- The JavaScript module should be shown interacting with the Document Object Model (DOM) defined in the HTML, responding to user interactions (like swapping candies) and updating the user interface based on game logic.
- That the CSS file styles the elements rendered by both HTML and dynamically by JavaScript.
- Assets (images) as being used by both CSS for background images and by JavaScript when dynamically inserting game elements.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly separate layout (HTML), presentation (CSS), and behavior (JavaScript). This modular design ensures that changes in game logic or aesthetics do not affect the overall structure.
- Event-Driven Programming: The game logic in candy.js likely relies on event listeners and callbacks to handle user interactions (e.g., clicking or dragging candies).
- Dynamic UI Updates: Highlight how JavaScript manipulates the DOM in response to game events such as candy swaps or crushes, leading to updates in the canvas/interface.

##### Relevant Technologies and Frameworks
- HTML5, CSS3, and vanilla JavaScript are the core technologies used.
- Although not a “backend” project, you could optionally add "Web Browser" as an external component that runs the game.

##### Final Recommendations for the Principal Software Engineer
- Components are clearly labeled with their file names and roles.
- Incorporate annotations that describe the game loop and interaction flows such as candy swapping and match detection.

## Diagram (Mermaid)

```mermaid
graph TD
    Browser["Web Browser"]:::external

    subgraph "Frontend Layer"
        HTML["index.html<br/>View/Markup"]:::frontend
        CSS["candy.css<br/>Styling/Presentation"]:::css
        JS["candy.js<br/>Game Logic"]:::js
    end

    Assets["images<br/>Assets"]:::assets

    Browser -->|"Loads"| HTML
    HTML -->|"Applies"| CSS
    HTML -->|"Loads"| JS
    CSS -->|"Uses"| Assets
    JS -->|"Uses"| Assets
    JS -->|"UpdatesDOM"| HTML

    subgraph "Game Processes"
        Swap["CandySwap"]:::process
        Detect["CrushDetection"]:::process
        Regenerate["BoardRegeneration"]:::process
    end

    JS -->|"Triggers"| Swap
    Swap -->|"LeadsTo"| Detect
    Detect -->|"Triggers"| Regenerate
    Regenerate -->|"Refreshes"| JS

    click HTML "https://github.com/imkennyyip/candy-crush/blob/master/index.html"
    click CSS "https://github.com/imkennyyip/candy-crush/blob/master/candy.css"
    click JS "https://github.com/imkennyyip/candy-crush/blob/master/candy.js"
    click Assets "https://github.com/imkennyyip/candy-crush/tree/master/images"

    classDef frontend fill:#f9e3b4,stroke:#333,stroke-width:2px;
    classDef css fill:#d0e9ff,stroke:#333,stroke-width:2px;
    classDef js fill:#d0ffd6,stroke:#333,stroke-width:2px;
    classDef assets fill:#f0f0f0,stroke:#333,stroke-width:2px;
    classDef process fill:#ffefd5,stroke:#333,stroke-width:2px;
    classDef external fill:#e2e2e2,stroke:#333,stroke-width:2px;
```
