# alampros/react-confetti architecture

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

- Interactive diagram: https://gitdiagram.com/alampros/react-confetti
- Repository: https://github.com/alampros/react-confetti

## Overview

##### Main Components Identification

a. Core Components:
- ReactConfetti (Main Component)
- ParticleGenerator
- Particle System (Particle.ts)
- Utility Layer (utils.ts)

**┌─ Application Layer ─────────────────────┐**

- React Application                  │
- (Consumer of the Component)        │

- ┤

- ReactConfetti Component            │
- (Main Interface)                   │

- ┤
- Particle Management Layer          │
- ┌─────────────┐    ┌──────────────┐  │
- Particle   │    │   Particle    │  │
- Generator   │───▶│   Instance   │  │
- ┘    └──────────────┘  │

- ┤
- ┌─────────┐ ┌───────┐ ┌──────────┐   │
- Circle  │ │ Rect  │ │  Point   │   │
- ┘ └───────┘ └──────────┘   │

- ┤
- Canvas Rendering Context           │
- ┘

##### Important Elements

a. Props Flow:
- How configuration props flow from the consumer application to the ReactConfetti component
- Props like width, height, numberOfPieces, etc.

b. Rendering Pipeline:
- Canvas rendering loop
- How particles are generated and updated
- Demonstrate the relationship between ParticleGenerator and individual particles

c. State Management:
- How the animation state is managed
- How the confetti source and physics parameters affect the system

##### Technical Details to Highlight
- Canvas-based rendering system
- Physics simulation parameters (friction, wind, gravity)
- Particle lifecycle management
- Animation frame management

##### Interactions
- How the component interfaces with the window size
- Demonstrate event handling for animation frames
- Particle recycling mechanism

**Creation → Initial Position → Physics Application → Rendering → Recycling/Cleanup**

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Application
        ReactApp[React Application]
    end

    subgraph MainComponent
        RC[ReactConfetti Component]:::react
        click RC "https://github.com/alampros/react-confetti/blob/develop/src/ReactConfetti.tsx"
        CL[Confetti Logic]:::core
        click CL "https://github.com/alampros/react-confetti/blob/develop/src/Confetti.ts"
        EP[Entry Point]:::core
        click EP "https://github.com/alampros/react-confetti/blob/develop/src/index.ts"
    end

    subgraph ParticleManagement
        PG[Particle Generator]:::particle
        click PG "https://github.com/alampros/react-confetti/blob/develop/src/ParticleGenerator.ts"
        PS[Particle System]:::particle
        click PS "https://github.com/alampros/react-confetti/blob/develop/src/Particle.ts"
    end

    subgraph ShapeRendering
        Circle[Circle]:::shape
        click Circle "https://github.com/alampros/react-confetti/blob/develop/src/Circle.ts"
        Rect[Rectangle]:::shape
        click Rect "https://github.com/alampros/react-confetti/blob/develop/src/Rect.ts"
        Point[Point]:::shape
        click Point "https://github.com/alampros/react-confetti/blob/develop/src/Point.ts"
    end

    subgraph Examples
        MR[Mouse Rain Example]:::example
        click MR "https://github.com/alampros/react-confetti/blob/develop/src/stories/MouseRain.tsx"
        PM[Party Mode Example]:::example
        click PM "https://github.com/alampros/react-confetti/blob/develop/src/stories/PartyMode.tsx"
        SC[Sized Confetti Example]:::example
        click SC "https://github.com/alampros/react-confetti/blob/develop/src/stories/SizedConfetti.tsx"
    end

    subgraph Utilities
        Utils[Utility Functions]:::util
        click Utils "https://github.com/alampros/react-confetti/blob/develop/src/utils.ts"
    end

    %% Relationships
    ReactApp --> RC
    RC --> CL
    EP --> RC
    CL --> PG
    PG --> PS
    PS --> Circle
    PS --> Rect
    PS --> Point
    PS --> Utils
    RC --> Examples
    Examples --> MR
    Examples --> PM
    Examples --> SC

    %% Styles
    classDef react fill:#61dafb,stroke:#000,stroke-width:2px
    classDef core fill:#ff9900,stroke:#000,stroke-width:2px
    classDef particle fill:#00ff00,stroke:#000,stroke-width:2px
    classDef shape fill:#ff6b6b,stroke:#000,stroke-width:2px
    classDef util fill:#gray,stroke:#000,stroke-width:2px
    classDef example fill:#purple,stroke:#000,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[React Components]:::react
        L2[Core Logic]:::core
        L3[Particle System]:::particle
        L4[Shape Components]:::shape
        L5[Utilities]:::util
        L6[Examples]:::example
    end
```
