# arturovaine/company-risk-radar_web-extension architecture

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

- Interactive diagram: https://gitdiagram.com/arturovaine/company-risk-radar_web-extension
- Repository: https://github.com/arturovaine/company-risk-radar_web-extension

## Overview

##### Project type and purpose
- This is a Chrome browser extension (Proof of Concept) that provides a popup UI to run “due diligence” company investigations by calling the OpenAI GPT‑4 API, structuring the results into JSON, and allowing the user to download that JSON.

##### File structure
- manifest.json: Chrome extension manifest (defines the popup, permissions, storage usage).
- .gitignore / README.md: Project metadata (not part of runtime).

##### README for additional insights
- It describes how the extension stores the OpenAI key in chrome.storage, builds a prompt based on the user’s requested company, sends that prompt to GPT‑4, parses the JSON response, and displays or downloads it.
- The tech stack is plain HTML/CSS/JS and Chrome Extension APIs (storage, action) plus the external OpenAI API.

##### Main components & their interactions
a. Browser & Chrome Extension Host
b. Popup UI (popup.html + popup.js)
- Retrieves the stored API key from chrome.storage.
- Renders an input for the company name.
- On submit, constructs the GPT‑4 prompt and sends an HTTPS request to the OpenAI API.
- Receives JSON results, displays them in the popup, and offers a “Download JSON” button.
c. Chrome Storage
- Holds the user’s OpenAI API key and (in future) custom prompts or history.
d. OpenAI GPT‑4 External Service
- Receives the assembled prompt, returns a structured JSON report with risk fields and score.
e. User
- Interacts with the popup UI, initiates analyses, and downloads or reviews results.

##### Architectural patterns & design principles
- Single‑page popup architecture—no background or content scripts here.
- Use of browser‑provided storage for secrets.
- External service integration via REST.

- Popup UI → Chrome Storage: fetch API key.
- Popup UI → OpenAI API: POST prompt, await JSON.
- OpenAI API → Popup UI: returns JSON report.
- Popup UI → User: renders data, downloads JSON.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Actors and External Services
    User["User"]:::actor
    API["OpenAI GPT-4 API"]:::external

    %% Browser Container
    subgraph "Browser (Chrome)"
        direction TB
        Host["Chrome Extension Host"]:::host

        subgraph "Extension Components"
            direction TB
            UI["Popup UI\n(popup.html)"]:::ui
            Logic["Business Logic\n(popup.js)"]:::logic
            Storage["Chrome Storage\n(API Key)"]:::storage
            Assets["Static Assets\n(icons/)"]:::assets
        end
    end

    %% Data Flows
    User -->|"opens popup & enters company"| UI
    UI -->|"fetch API key"| Storage
    UI -->|"send prompt"| API
    API -->|"returns JSON report"| UI
    UI -->|"display & download JSON"| User

    %% Click Events
    click Host "https://github.com/arturovaine/company-risk-radar_web-extension/blob/main/manifest.json"
    click UI "https://github.com/arturovaine/company-risk-radar_web-extension/blob/main/popup.html"
    click Logic "https://github.com/arturovaine/company-risk-radar_web-extension/blob/main/popup.js"
    click Storage "https://github.com/arturovaine/company-risk-radar_web-extension/blob/main/popup.js"
    click Assets "https://github.com/arturovaine/company-risk-radar_web-extension/tree/main/icons/"

    %% Styling
    classDef actor fill:#E0E0E0,stroke:#333,stroke-width:1px
    classDef ui fill:#D0E6FF,stroke:#0366d6,stroke-width:1px
    classDef logic fill:#DFFFD0,stroke:#28a745,stroke-width:1px
    classDef storage fill:#FFE5B4,stroke:#e36109,stroke-width:1px
    classDef external fill:#FFCCCC,stroke:#d73a49,stroke-width:1px
    classDef host fill:#EEEEEE,stroke:#666,stroke-width:1px
    classDef assets fill:#F0F0F0,stroke:#555,stroke-width:1px
```
