# mihaben/react-modular-feature-flags architecture

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

- Interactive diagram: https://gitdiagram.com/mihaben/react-modular-feature-flags
- Repository: https://github.com/mihaben/react-modular-feature-flags

## Overview

##### Project Type and Purpose
- This is a modular feature flags management library for React applications. Its goal is to provide a single source of truth for managing feature flags through multiple channels (e.g., cookies, query parameters, custom events, ConfigCat, and custom channels) and expose a hook (useFeatureFlag) for real-time access within React components.
- The project is structured as a library with example usage (in the “example” directory) and comprehensive test coverage (in the “test” directory).

##### Analyzing the File Structure
- Top-Level Directories and Files:
- “src/”: Contains the core code for the library including modules like channels (src/channels), helpers (helpers.ts), type definitions (types.ts), and the hook implementation (use-feature-flag.ts).
- “example/”: Provides an isolated sample React project with its own configuration files, TypeScript setups, and an App component illustrating library integration.
- “test/”: Contains test cases for the different channels (such as configcat-channel.spec.ts, cookies-channel.spec.ts, etc.), ensuring each channel behaves as expected.
- Configuration files (tsconfig, eslint, vite, tsup) indicate use of TypeScript and bundlers which are part of the build and development ecosystem.
- This layering indicates clear segmentation between the core library functionality, demo usage, and tests that validate the modules.

##### README Insights
- The README explains the library’s API, supported channels, and key methods:
- The core API (init, initChannel, getFlags, getFlag) represents a Singleton class maintaining the feature flag state.
- Multiple channels are explained in detail (Cookies, Query Params, Custom Event, ConfigCat, and how to build a custom channel), each being a separate component integrated into the core feature flags manager.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Core Library
    subgraph "Core Library"
        FF["FeatureFlags Manager"]:::core
        HM["Helper Modules"]:::auxiliary
        TD["Type Definitions"]:::auxiliary
    end

    %% Channels
    subgraph "Channels"
        FC["Feature Channels"]:::channel
        CC["Cookies Channel"]:::channel
        QPC["Query Params Channel"]:::channel
        CEC["Custom Event Channel"]:::channel
        CCat["ConfigCat Channel"]:::channel
        CustC["Custom Channel"]:::channel
    end

    %% React Integration
    subgraph "React Integration"
        UF["useFeatureFlag Hook"]:::integration
        RA["React App Example"]:::integration
    end

    %% Testing
    subgraph "Testing"
        TS["Test Suite"]:::testing
    end

    %% Relationships
    HM -->|"support"| FF
    TD -->|"support"| FF

    FC -->|"contains"| CC
    FC -->|"contains"| QPC
    FC -->|"contains"| CEC
    FC -->|"contains"| CCat
    FC -->|"contains"| CustC

    CC -->|"update"| FF
    QPC -->|"update"| FF
    CEC -->|"update"| FF
    CCat -->|"update"| FF
    CustC -->|"update"| FF

    UF <-->|"state"| FF
    RA -->|"consumes"| UF

    TS -->|"tests"| FF

    %% Click Events
    click FF "https://github.com/mihaben/react-modular-feature-flags/blob/master/src/index.ts"
    click FC "https://github.com/mihaben/react-modular-feature-flags/tree/master/src/channels"
    click CC "https://github.com/mihaben/react-modular-feature-flags/blob/master/test/cookies-channel.spec.ts"
    click QPC "https://github.com/mihaben/react-modular-feature-flags/blob/master/test/query-params-channel.spec.ts"
    click CEC "https://github.com/mihaben/react-modular-feature-flags/blob/master/test/custom-event-channel.spec.ts"
    click CCat "https://github.com/mihaben/react-modular-feature-flags/blob/master/test/configcat-channel.spec.ts"
    click CustC "https://github.com/mihaben/react-modular-feature-flags/tree/master/src/channels"
    click UF "https://github.com/mihaben/react-modular-feature-flags/blob/master/src/use-feature-flag.ts"
    click HM "https://github.com/mihaben/react-modular-feature-flags/blob/master/src/helpers.ts"
    click TD "https://github.com/mihaben/react-modular-feature-flags/blob/master/src/types.ts"
    click RA "https://github.com/mihaben/react-modular-feature-flags/blob/master/example/src/App.tsx"
    click TS "https://github.com/mihaben/react-modular-feature-flags/tree/master/test/"

    %% Styles
    classDef core fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef channel fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef integration fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef auxiliary fill:#fffacd,stroke:#333,stroke-width:2px;
    classDef testing fill:#e6e6fa,stroke:#333,stroke-width:2px;
```
