# emrecpp/cookify architecture

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

- Interactive diagram: https://gitdiagram.com/emrecpp/cookify
- Repository: https://github.com/emrecpp/cookify

## Overview

##### Project Type and Purpose
- Cookify is a **Chrome Extension** (not a web server or microservice).
- Purpose: Provide a popup UI for managing cookies, JWT tokens, and integrate those directly into Swagger API docs.

##### File Structure
- **manifest.json**: Entry point; defines extension capabilities (popup, content scripts, permissions).
- **Root index.html + src/**: The **popup UI** built with React & TypeScript, assembled by Vite.
- src/main.tsx → src/app/App.tsx → pages/components (cookie, swagger, settings)
- **content-script/**: A second React app that gets injected into matching web pages (Swagger UI).
- content-script/src/main.tsx → content-script/src/App.tsx
- **src/context**, **src/hooks**, **src/lib**, **runtime/helpers**: Internal logic, state management, utilities, schema validation (Zod).
- **build/config**: Vite, ESLint, Tailwind, TypeScript configs.

##### Main Components
A. **Browser (Chrome) Host**
- The runtime environment that loads the extension.
B. **Extension Manifest**
- Defines two entry points:
1. **Popup UI** (loaded in extension toolbar popup)
2. **Content Script** (injected into Swagger pages)
C. **Popup React App**
- Built from src/app; provides:
- Cookie management UI
- JWT token management UI
- Project grouping, import/export
- Interacts with Chrome APIs directly (chrome.cookies, chrome.storage, chrome.tabs, chrome.runtime).
D. **Content-Script React App**
- Injected into Swagger pages.
- Listens for messages (chrome.runtime.onMessage) to:
- Apply cookies to document via document.cookie or chrome.cookies
- Insert JWT into Swagger’s Authorization header input
E. **Chrome Extension APIs**
- **chrome.cookies**: read/write cookies on target domains
- **chrome.storage**: persist saved cookies/tokens and profiles
- **chrome.runtime.messaging**: communication between popup and content script
F. **External Swagger UI**
- The web page where content-script injects UI elements and updates auth fields

##### Relationships & Data Flow
1. **User Interaction** in Popup → triggers React state updates → calls Chrome APIs (cookies/storage)
2. **Popup** sends **message** to active tab’s **Content Script**:
- e.g. “Apply this cookie set” or “Set this JWT token”
3. **Content Script** acts on the **DOM/Swagger UI** or uses chrome.cookies API
4. **Data Persistence** flows to/from chrome.storage (for import/export profiles)

##### Architectural Patterns & Technologies
- **Component-Based UI** with React (Popup & Content Script)
- **Context + Custom Hooks** for global state and side-effects (useCookie, useSwagger)
- **Message-Passing** pattern between popup and content script
- **Schema Validation** via Zod (src/lib/schemas.ts)
- **Vite** build tooling for bundling two entry points

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Chrome Host and Manifest
    CH["Chrome Host (Extension Runtime)"]:::external
    MAN["Manifest.json"]:::config
    CH -->|loads| MAN
    click MAN "https://github.com/emrecpp/cookify/blob/main/manifest.json"

    %% Popup React App Subgraph
    subgraph "Popup React App" 
        direction TB
        PHTML["index.html"]:::frontend
        PMAIN["src/main.tsx"]:::frontend
        PAPP["src/app/App.tsx"]:::frontend

        subgraph "Components" 
            direction TB
            PCOOKIE["Cookie Components"]:::frontend
            PSWAGGER["Swagger Integration Components"]:::frontend
            PSHARED["Shared UI Components"]:::frontend
        end

        subgraph "Pages"
            direction TB
            PCOOKIES["CookiesMainPage.tsx"]:::frontend
            PSWAGPAGE["SwaggerMainPage.tsx"]:::frontend
            PSETTINGS["SettingsPage.tsx"]:::frontend
            PTABS["TabPages.tsx"]:::frontend
        end

        PHTML --> PMAIN --> PAPP
        PAPP --> PCOOKIE
        PAPP --> PSWAGGER
        PAPP --> PSHARED
        PAPP --> PCOOKIES
        PAPP --> PSWAGPAGE
        PAPP --> PSETTINGS
        PAPP --> PTABS
    end

    click PHTML "https://github.com/emrecpp/cookify/blob/main/index.html"
    click PMAIN "https://github.com/emrecpp/cookify/blob/main/src/main.tsx"
    click PAPP "https://github.com/emrecpp/cookify/blob/main/src/app/App.tsx"
    click PCOOKIE "https://github.com/emrecpp/cookify/tree/main/src/app/components/cookie/"
    click PSWAGGER "https://github.com/emrecpp/cookify/tree/main/src/app/components/swagger/"
    click PSHARED "https://github.com/emrecpp/cookify/tree/main/src/app/components/shared/"
    click PCOOKIES "https://github.com/emrecpp/cookify/blob/main/src/app/pages/CookiesMainPage.tsx"
    click PSWAGPAGE "https://github.com/emrecpp/cookify/blob/main/src/app/pages/SwaggerMainPage.tsx"
    click PSETTINGS "https://github.com/emrecpp/cookify/blob/main/src/app/pages/SettingsPage.tsx"
    click PTABS "https://github.com/emrecpp/cookify/blob/main/src/app/pages/TabPages.tsx"

    %% Helper Modules
    subgraph "Helper Modules & Lib" 
        direction TB
        GCTX["src/context/global-context.tsx"]:::config
        HC["src/hooks/useCookie.ts"]:::config
        HS["src/hooks/useSwagger.ts"]:::config
        HZ["src/hooks/useZodForm.ts"]:::config
        HE["src/hooks/useEffectAfterMount.ts"]:::config
        SCHEMA["src/lib/schemas.ts"]:::config
        UTILS["src/lib/utils.ts"]:::config
        RSWG["src/runtime/helpers/swagger.ts"]:::config
        RRT["src/runtime/router.ts"]:::config
    end

    click GCTX "https://github.com/emrecpp/cookify/blob/main/src/context/global-context.tsx"
    click HC "https://github.com/emrecpp/cookify/blob/main/src/hooks/useCookie.ts"
    click HS "https://github.com/emrecpp/cookify/blob/main/src/hooks/useSwagger.ts"
    click HZ "https://github.com/emrecpp/cookify/blob/main/src/hooks/useZodForm.ts"
    click HE "https://github.com/emrecpp/cookify/blob/main/src/hooks/useEffectAfterMount.ts"
    click SCHEMA "https://github.com/emrecpp/cookify/blob/main/src/lib/schemas.ts"
    click UTILS "https://github.com/emrecpp/cookify/blob/main/src/lib/utils.ts"
    click RSWG "https://github.com/emrecpp/cookify/blob/main/src/runtime/helpers/swagger.ts"
    click RRT "https://github.com/emrecpp/cookify/blob/main/src/runtime/router.ts"

    %% Content Script React App Subgraph
    subgraph "Content Script React App" 
        direction TB
        CHTML["content-script/index.html"]:::frontend
        CMAIN["content-script/src/main.tsx"]:::frontend
        CAPP["content-script/src/App.tsx"]:::frontend
    end

    click CHTML "https://github.com/emrecpp/cookify/blob/main/content-script/index.html"
    click CMAIN "https://github.com/emrecpp/cookify/blob/main/content-script/src/main.tsx"
    click CAPP "https://github.com/emrecpp/cookify/blob/main/content-script/src/App.tsx"

    %% Static Assets
    subgraph "Static Assets" 
        direction TB
        COMPJSON["components.json"]:::config
        PUBLICICON["public/icon"]:::config
        SVGICONS["src/svg/swagger.tsx"]:::config
    end

    click COMPJSON "https://github.com/emrecpp/cookify/blob/main/components.json"
    click PUBLICICON "https://github.com/emrecpp/cookify/tree/main/public/icon"
    click SVGICONS "https://github.com/emrecpp/cookify/blob/main/src/svg/swagger.tsx"

    %% Build & Config
    subgraph "Build & Config" 
        direction TB
        VITE["vite.config.ts"]:::config
        TSC["tsconfig.json"]:::config
        TSCA["tsconfig.app.json"]:::config
        TSCN["tsconfig.node.json"]:::config
        ESLINT["eslint.config.js"]:::config
        TWC["tailwind.config.js"]:::config
        POSTCSS["postcss.config.js"]:::config
    end

    click VITE "https://github.com/emrecpp/cookify/blob/main/vite.config.ts"
    click TSC "https://github.com/emrecpp/cookify/blob/main/tsconfig.json"
    click TSCA "https://github.com/emrecpp/cookify/blob/main/tsconfig.app.json"
    click TSCN "https://github.com/emrecpp/cookify/blob/main/tsconfig.node.json"
    click ESLINT "https://github.com/emrecpp/cookify/blob/main/eslint.config.js"
    click TWC "https://github.com/emrecpp/cookify/blob/main/tailwind.config.js"
    click POSTCSS "https://github.com/emrecpp/cookify/blob/main/postcss.config.js"

    %% Chrome APIs and Storage
    subgraph "Chrome APIs" 
        direction TB
        CC["chrome.cookies"]:::api
        CS["chrome.storage"]:::api
        CR["chrome.runtime.messaging"]:::api
    end

    subgraph "Storage" 
        direction TB
        STORAGE["chrome.storage (Profiles)"]:::api
    end

    %% External System
    SWAGGER["External Swagger UI"]:::external

    %% Connections
    MAN -->|defines| PHTML
    MAN -->|defines| CHTML

    PAPP -->|calls chrome.cookies| CC
    PAPP -->|calls chrome.storage| CS
    PAPP -->|sends message| CR
    CR -->|delivers to| CAPP
    CAPP -->|uses chrome.cookies| CC
    CAPP -->|injects into| SWAGGER
    CAPP -->|manipulates DOM| SWAGGER
    CC -->|read/write| SWAGGER
    CS -->|persists| STORAGE
    PAPP -->|imports schemas| SCHEMA
    PAPP -->|uses hooks| HC
    PAPP -->|uses hooks| HS
    PAPP -->|uses hooks| HZ
    PAPP -->|uses hooks| HE
    PAPP -->|uses utils| UTILS
    CAPP -->|uses swagger helpers| RSWG
    CAPP -->|routes messages| RRT

    %% Styling
    classDef frontend fill:#e0f7ff,stroke:#333,stroke-width:1px
    classDef api fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef external fill:#e0ffe0,stroke:#333,stroke-width:1px
    classDef config fill:#f0f0f0,stroke:#333,stroke-width:1px
```
