# jordwest/news-feed-eradicator architecture

> Architecture diagram of the GitHub repository jordwest/news-feed-eradicator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jordwest/news-feed-eradicator
- Repository: https://github.com/jordwest/news-feed-eradicator

## Overview

##### Project Type & Purpose
- Recognize that this is a browser extension developed as a WebExtension (compatible with both Chrome and Firefox).
- Its primary function is to remove the Facebook news feed (and possibly similar content from other websites) and replace it with a custom quote display.
- It uses a modular architecture with clearly defined functional areas to manage background processing, UI components, site-specific logic, messaging, and options configuration.

##### Main Components
a. WebExtension Shell:
- Manifest Files (src/manifest.json, src/manifest-chrome.json): These define what scripts run, permissions, and other configuration details.
- Build & Packaging: While not a runtime component, note the Makefile and build/dist folders (for production and development flows).

b. Background Component:
- Background Scripts: Represent the background page and service worker (src/background/service-worker.ts) that manage extension-wide tasks.
- Background Store: There is a dedicated state management area (src/background/store) implementing a Redux-like pattern with actions, reducers, effects, and selectors.

c. UI & Components:
- Components Directory (src/components): Contains various UI modules (alert, info-panel, quote-display, quote-editor, etc.) for rendering content or notifications.
- Options Screen: (src/options) where users can configure the extension’s behavior via options.html, options.css, and options.ts.
- Content Script Elements: Although not explicitly under a “content” folder, the injection of UI (via src/lib/inject-ui.ts) and interception logic (src/intercept.ts) plays a key role in modifying the page.

d. Site-Specific Logic:
- Sites Directory (src/sites): Contains modules targeting specific sites (Facebook variations, Hacker News, LinkedIn, Twitter, etc.) with tailored functions to remove news feeds and possibly adjust styles (notice “*.str.css” files).

e. Shared Libraries & Utilities:
- Lib Directory (src/lib): Aggregates helper functions (e.g., generate-id, handle-error, parse-csv, route-change) that provide core functionalities.
- Messaging: (src/messaging) which defines types and possibly utility functions for inter-module communication between the background and content scripts.

##### Relationships & Interactions
- The Manifest defines which background scripts and option pages are loaded.
- The background service worker (and its state management system) initiates and orchestrates actions, listening to events (both browser events and messages) and maintaining state.
- The UI components are injected into web pages using functions (inject-ui) triggered either by the background or content scripts.
- Site-specific modules are consulted to determine how to interact (e.g., remove or adjust DOM elements) for each supported website.
- Communication is facilitated by a messaging system connecting content scripts, background scripts, and option pages (using types defined in src/messaging/types.ts).

##### Architectural Patterns & Key Technologies
- Modular Structure: Clear separation of concerns between background processing, UI rendering, state management, site-specific logic, and utilities.
- Redux-like State Management: With actions, reducers, selectors, and effects found in multiple “store” folders (both in src/store and src/background/store).
- Service Worker: Serving as the background script providing persistent processing even when no UI is visible.
- Build Tools: Using TypeScript (tsconfig.json), Rollup (rollup.config.js), and a Makefile to manage builds and development workflow.
- WebExtension Standards: The overall design conforms to modern browser extension APIs as dictated by the manifest files.

##### Detailing and Labeling
- Clearly label every component with its file/directory name or a descriptive name (e.g., “Service Worker & Background Store”, “UI – Quote Display Module”, “Site Modules (Facebook, Twitter, …)”).
- Notes or legends if required to explain symbols, especially the Redux-like component flow (actions → effects → reducer → state updates).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% WebExtension Shell
    subgraph "WebExtension Shell"
        W1["Manifest (Main)"]
        W2["Manifest (Chrome)"]
        W3["Makefile"]
        W4["Rollup Config"]
    end

    %% Background Process
    subgraph "Background Process"
        B1["Service Worker"]
        B2["Background Store"]
        B3["Site-specific Store"]
    end

    %% UI Components
    subgraph "UI Components"
        U1["UI Components"]
        U2a["Inject UI"]
        U2b["Intercept Script"]
        U3["Options Screen"]
    end

    %% Site-Specific Modules
    subgraph "Site-Specific Modules"
        S1["Site Modules"]
    end

    %% Shared Libraries & Utilities
    subgraph "Shared Libraries & Utilities"
        L1["Helper Functions"]
        L2["Messaging"]
    end

    %% Relationships
    W1 -->|"loads"| B1
    W2 -->|"loads"| B1
    W1 -->|"loads"| U3
    W2 -->|"loads"| U3

    B1 -->|"initiates"| B2
    B2 -->|"updates"| B3
    B2 -->|"sends"| L2
    B2 -->|"notifies"| U1

    U1 -->|"integrates"| U2a
    U1 -->|"integrates"| U2b

    U2a -->|"calls"| S1
    U2b -->|"calls"| S1

    U3 -->|"updates"| B2

    L1 -->|"supports"| U1
    L1 -->|"supports"| U2a
    L1 -->|"supports"| B2
    L1 -->|"supports"| S1

    U1 -->|"communicates"| L2
    B2 -->|"communicates"| L2

    %% Click Events
    click W1 "https://github.com/jordwest/news-feed-eradicator/blob/master/src/manifest.json"
    click W2 "https://github.com/jordwest/news-feed-eradicator/blob/master/src/manifest-chrome.json"
    click W3 "https://github.com/jordwest/news-feed-eradicator/tree/master/Makefile"
    click W4 "https://github.com/jordwest/news-feed-eradicator/blob/master/rollup.config.js"
    click B1 "https://github.com/jordwest/news-feed-eradicator/blob/master/src/background/service-worker.ts"
    click B2 "https://github.com/jordwest/news-feed-eradicator/tree/master/src/background/store"
    click B3 "https://github.com/jordwest/news-feed-eradicator/tree/master/src/background/store/sites"
    click U1 "https://github.com/jordwest/news-feed-eradicator/tree/master/src/components"
    click U2a "https://github.com/jordwest/news-feed-eradicator/blob/master/src/lib/inject-ui.ts"
    click U2b "https://github.com/jordwest/news-feed-eradicator/blob/master/src/intercept.ts"
    click U3 "https://github.com/jordwest/news-feed-eradicator/tree/master/src/options"
    click S1 "https://github.com/jordwest/news-feed-eradicator/tree/master/src/sites"
    click L1 "https://github.com/jordwest/news-feed-eradicator/tree/master/src/lib"
    click L2 "https://github.com/jordwest/news-feed-eradicator/tree/master/src/messaging"

    %% Styles
    classDef extensionShell fill:#f9c,stroke:#333,stroke-width:2px;
    classDef background fill:#acf,stroke:#333,stroke-width:2px;
    classDef ui fill:#cfc,stroke:#333,stroke-width:2px;
    classDef sites fill:#ffc,stroke:#333,stroke-width:2px;
    classDef shared fill:#eef,stroke:#333,stroke-width:2px;

    class W1,W2,W3,W4 extensionShell
    class B1,B2,B3 background
    class U1,U2a,U2b,U3 ui
    class S1 sites
    class L1,L2 shared
```
