How boscop-fr/orejime works
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.