# boscop-fr/orejime architecture

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

- Interactive diagram: https://gitdiagram.com/boscop-fr/orejime
- Repository: https://github.com/boscop-fr/orejime

## Overview

##### Main Components
- Browser/Client Environment – the website where Orejime is embedded.
- Configuration Module – the mechanism (via a global variable or programmatic initialization) that passes the consent options (including privacyPolicyUrl, list of purposes, cookie settings, and theme options).
- Consent Manager (Core) – implemented in the “src/core” folder. This module handles consent logic, state (via Manager.ts and associated EventEmitter), and cookie deletion.
- UI Components – React-based view-layer (in “src/ui” and its subdirectories) that renders the banner, modal, dialogs, and theming variations (e.g., standard, DSFR). They include components (like ContextualNotice, GlobalConsent, PurposeList, etc.) and are triggered based on the manager’s state.
- Themes and Internationalization – The “src/ui/themes” and “src/translations” directories hold styling assets and locale-specific text.
- Migrations – Located in “src/migrations”, these modules handle transitions among configuration versions.
- Build and Testing Infrastructure – Although not part of runtime architecture, directories such as “build”, “e2e”, and configuration files (jest.config.js, rspack.config.js, playwright.config.ts) indicate automated test flows and CI/CD pipelines. They help ensure that changes in the main consent configuration or UI do not break expected behavior.

##### Relationships and Interactions
- When the web page loads, the browser environment uses the provided configuration (either as window.orejimeConfig or via an explicit Orejime.init() call).
- The configuration is passed to the Consent Manager, which sets the initial cookie toast state.
- The Consent Manager, in turn, uses event listeners to manage user events (accept, decline, clear, update) and to notify the UI components about state changes.
- UI components react to these events to display banners, modals, or to update their layout (and to apply theming based on the loaded CSS and theme-specific React components).
- The consent manager is also responsible for “unwrapping” third-party scripts that are wrapped in <template> elements with data-purpose attributes, enabling lazy-loading based on consent.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Core logic (consent management) is separated from UI rendering and theming.
- Modularity: The project offers separate modules for different themes and languages, making the system easily extendable.
- Event-Driven Design: The manager emits events (update, clear, dirty) to decouple state changes from UI responses.
- Reusability: Components and utilities (in “src/core/utils” and “src/ui/utils”) are built to be reused across different parts of the application.

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Browser / Client Environment"
    A1["HTML Page with orejimeConfig and Templates"]:::client
  end

  subgraph "Consent Manager (Core)"
    B1["Configuration Module (window.orejimeConfig/init)"]:::core
    B2["Consent Manager Logic (Manager.ts, EventEmitter)"]:::core
    B3["Cookie & Purposes Processing (utils)"]:::core
  end

  subgraph "UI Components"
    C1["Banner & Modal (React Components)"]:::ui
    C2["Theme Components (Standard & DSFR)"]:::ui
    C3["Contextual Consent (Component Wrappers)"]:::ui
  end

  subgraph "Supporting Modules"
    D1["Internationalization (translations)"]:::support
    D2["Migration Tools (migrations)"]:::support
  end

  subgraph "Build & Test Infrastructure"
    E1["Build Scripts (entries.js, site.js, rspack.config.js)"]:::infra
    E2["Testing Suites (e2e, jest, playwright)"]:::infra
    E3["CI/CD Pipelines (GitHub workflows)"]:::infra
  end

  %% Data Flow Connections
  A1 -->|"initializes"| B1
  B1 -->|"initializes"| B2
  B2 -->|"processes"| B3

  B2 -->|"emits"| C1
  B2 -->|"notifies"| C3
  C1 -->|"appliesTheme"| C2

  B2 -->|"uses"| D1
  B2 -->|"migrates"| D2

  A1 ---|"relatedTo"| E1
  E1 ---|"triggers"| E2
  E2 ---|"integratesWith"| E3

  class A1 client
  class B1,B2,B3 core
  class C1,C2,C3 ui
  class D1,D2 support
  class E1,E2,E3 infra

click A1 "https://github.com/boscop-fr/orejime/tree/main/site"
click B1 "https://github.com/boscop-fr/orejime/blob/main/src/core/setup.ts"
click B2 "https://github.com/boscop-fr/orejime/tree/main/src/core"
click C1 "https://github.com/boscop-fr/orejime/tree/main/src/ui"
click C2 "https://github.com/boscop-fr/orejime/tree/main/src/ui/themes"
click D1 "https://github.com/boscop-fr/orejime/tree/main/src/translations"
click D2 "https://github.com/boscop-fr/orejime/tree/main/src/migrations"
click E1 "https://github.com/boscop-fr/orejime/tree/main/build/"
click E2 "https://github.com/boscop-fr/orejime/tree/main/e2e/"
click E3 "https://github.com/boscop-fr/orejime/tree/main/.github/workflows"
```
