# krikienoid/flagwaver architecture

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

- Interactive diagram: https://gitdiagram.com/krikienoid/flagwaver
- Repository: https://github.com/krikienoid/flagwaver

## Overview

##### Main Architecture Components

The system should be represented as a client-side single-page application (SPA) with the following main components:

a. Frontend Application Layer
- React/Preact Components
- Redux State Management
- UI/UX Components
- SCSS Styling System

b. Core Flag Simulation Layer
- Three.js 3D Rendering
- Physics Engine
- Flag Animation System

##### Detailed Component Breakdown

a. User Interface Layer (Top Level)
- App Components (/src/assets/js/app/components)
- Container Components (/src/assets/js/app/containers)
- Redux Store & Modules (/src/assets/js/app/redux)
- Context Providers (/src/assets/js/app/contexts)

b. FlagWaver Core (Middle Layer)
- Module System (/src/assets/js/flagwaver/app/core)
- Physics Engine (/src/assets/js/flagwaver/physics)
- Flag Subjects (/src/assets/js/flagwaver/subjects)
- WebGL Shaders (/src/assets/js/flagwaver/webgl)

c. Asset Management (Bottom Layer)
- Static Assets
- Fonts
- Images
- Styles (SCSS)

##### Data Flow and Interactions

a. User Input Flow:
→ UI Components
→ Redux Actions
→ State Updates
→ FlagWaver Core
→ Three.js Rendering

b. Physics Simulation Flow:
→ Wind Module
→ Physics Calculations
→ Cloth Simulation
→ Flag Animation
→ WebGL Rendering

##### Technical Stack Indicators

- Preact
- Redux
- Three.js
- WebGL
- SCSS
- Gulp/Rollup

##### Module Relationships

Relationships between:
- FlagWaver Core and UI Components
- Physics Engine and Flag Subjects
- Wind Module and Cloth Simulation
- State Management and Animation Control

Keep the abstraction level high enough to understand the overall architecture but detailed enough to show the unique aspects of the flag simulation system, particularly the physics engine and WebGL rendering pipeline.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI["UI Components"]
        CONT["Container Components"]
        REDUX["Redux State Management"]
        CONTEXT["Context Providers"]
        HASH["Hash State Management"]
        STYLE["Styling System"]
    end

    subgraph "Core Simulation"
        CORE["Core Module System"]
        ANIM["Animation Control"]
        PHYS["Physics Engine"]
        WIND["Wind Simulation"]
        FLAG["Flag Animation System"]
        WEBGL["WebGL Rendering"]
        POLE["Flagpole Types"]
        INTER["Physics Interactions"]
    end

    subgraph "Asset Layer"
        ASSETS["Asset Management"]
    end

    %% Frontend Relationships
    UI --> CONT
    CONT --> REDUX
    REDUX --> CONTEXT
    HASH --> REDUX
    STYLE --> UI

    %% Core Relationships
    CORE --> ANIM
    CORE --> PHYS
    PHYS --> WIND
    PHYS --> FLAG
    FLAG --> WEBGL
    WIND --> FLAG
    POLE --> FLAG
    INTER --> PHYS

    %% Cross-Layer Relationships
    CONT --> CORE
    REDUX --> ANIM
    ASSETS --> UI
    ASSETS --> WEBGL

    %% Styling
    classDef frontend fill:#4299e1,stroke:#2b6cb0,stroke-width:2px
    classDef core fill:#48bb78,stroke:#2f855a,stroke-width:2px
    classDef asset fill:#ed8936,stroke:#c05621,stroke-width:2px

    class UI,CONT,REDUX,CONTEXT,HASH,STYLE frontend
    class CORE,ANIM,PHYS,WIND,FLAG,WEBGL,POLE,INTER core
    class ASSETS asset

    %% Click Events
    click UI "https://github.com/krikienoid/flagwaver/tree/master/src/assets/js/app/components"
    click CONT "https://github.com/krikienoid/flagwaver/tree/master/src/assets/js/app/containers"
    click REDUX "https://github.com/krikienoid/flagwaver/tree/master/src/assets/js/app/redux"
    click CONTEXT "https://github.com/krikienoid/flagwaver/tree/master/src/assets/js/app/contexts"
    click HASH "https://github.com/krikienoid/flagwaver/tree/master/src/assets/js/hashstate"
    click STYLE "https://github.com/krikienoid/flagwaver/tree/master/src/assets/scss"
    click CORE "https://github.com/krikienoid/flagwaver/tree/master/src/assets/js/flagwaver/app/core"
    click ANIM "https://github.com/krikienoid/flagwaver/blob/master/src/assets/js/flagwaver/app/modules/AnimationControlModule.js"
    click PHYS "https://github.com/krikienoid/flagwaver/tree/master/src/assets/js/flagwaver/physics"
    click WIND "https://github.com/krikienoid/flagwaver/blob/master/src/assets/js/flagwaver/subjects/Wind.js"
    click FLAG "https://github.com/krikienoid/flagwaver/tree/master/src/assets/js/flagwaver/subjects"
    click WEBGL "https://github.com/krikienoid/flagwaver/tree/master/src/assets/js/flagwaver/webgl"
    click POLE "https://github.com/krikienoid/flagwaver/tree/master/src/assets/js/flagwaver/subjects/flagpoles"
    click INTER "https://github.com/krikienoid/flagwaver/tree/master/src/assets/js/flagwaver/interactions"
    click ASSETS "https://github.com/krikienoid/flagwaver/tree/master/src/assets"
```
