# satriotsubasa/powerplatform-leak architecture

> Architecture diagram of the GitHub repository satriotsubasa/powerplatform-leak, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/satriotsubasa/powerplatform-leak
- Repository: https://github.com/satriotsubasa/powerplatform-leak

## Overview

1. This is a Chromium Manifest V3 browser extension for Microsoft Dynamics 365 / Power Apps. The architecture is split into five runtime surfaces: background service worker, content script, injected page runtime, popup UI, and side panel UI. The key design choice is that anything needing `Xrm` or Dataverse page APIs runs in the page context, not in the extension context.

2. `src/manifest.json` is the root integration point. It declares the service worker, popup, side panel, web-accessible assets, icons, and the permissions needed to inspect/act on Dynamics tabs. The manifest is what ties the otherwise separate extension entry points together.

3. The background layer (`src/background/background.ts`) is the central coordinator. It detects Dynamics tabs, manages side-panel behavior, registers handlers, and brokers extension-level messages. It is also where cross-tab and browser-level concerns live, such as context menu setup and side-panel tab scope behavior.

4. The content script layer (`src/content/content.ts`) is the bridge from extension land into the page. It injects the page runtime, forwards messages, handles responses, and shows page overlays during long-running requests. This layer is the boundary that separates generic browser-extension logic from Dynamics-specific in-page execution.

5. The injected page runtime (`src/content/levelup.extension.ts` plus `src/content/modules/*.ts`) is where the actual Dynamics actions run. Modules are organized by concern: form actions, navigation, debugging, diagnostics, admin actions, “more features,” UI framework helpers, dialogs, Web API access, and request overlays. This runtime is the only place that directly relies on page objects like `Xrm`.

6. Action routing is layered rather than direct. `src/services/ActionHandlerRegistry.ts` maps action IDs to behaviors, `src/services/MessageService.ts` carries extension messages, and the content script relays those into the injected runtime. This creates a clear pipeline: UI event → extension service/message → active tab/content script → page runtime → Dynamics API call/result.

7. The sidebar is the primary workspace UI (`src/sidebar/sidebar.tsx` and `src/sidebar/components/*`). It contains the full action catalog, favorites, recently used items, custom commands, diagnostics, impersonation, theme switching, and status/alert surfaces. The sidebar also owns the richer interaction model, including dialogs and persistent preferences.

8. The popup is a compact quick-action surface (`src/popup/popup.tsx` and `src/popup/components/*`). It reuses the same underlying action model but presents a smaller, faster UI for common tasks and mode switching. Architecturally, it is a second UI entry point into the same action/message infrastructure, not a separate feature set.

9. Diagnostics is a major subsystem with its own shared UI package. The sidebar and popup both consume diagnostics configuration and shared components from `src/ui/diagnostics/*`, while the page runtime executes the diagnostics-specific data gathering logic. This split keeps the UI for diagnostic tables/dialogs separate from the data collection and page-context discovery logic.

10. Impersonation is a cross-cutting feature spanning service, hook, and UI layers. `src/services/ImpersonationService.ts` manages the feature’s state/behavior, sidebar hooks and components expose it to users, and the runtime flow likely impacts which user context is used when actions are executed. It is not isolated to a single screen; it affects the action execution model.

11. Custom commands, community sharing, and GitHub integration form a smaller ecosystem around user-defined actions. `CustomCommandsService` and the code editor/dialog components manage local command definitions, while `GitHubApiService` supports sharing/collection workflows. This is separate from built-in Dynamics actions and is mainly a sidebar capability.

12. Shared design and presentation concerns are centralized. Material 3 tokens/themes live in `src/ui/material3/*`, theme preferences are stored in sidebar contexts, and utility helpers such as icon maps, debounce, focus management, and Dynamics detection are shared across surfaces. This keeps UI consistency and tab detection logic from being duplicated across popup, sidebar, and content code.

13. Build and packaging are Vite- and TypeScript-based. `vite.config.ts` builds multiple entry points for background, sidebar, content, injected runtime, and popup, while helper scripts handle version bumps, release notes, and ZIP packaging. The build output is the unpacked extension in `build/`, with release artifacts created under `release/`.

14. Tests are organized by runtime boundary, which mirrors the architecture: background tests, content tests, popup tests, service tests, and sidebar tests. That structure reflects the major seams in the codebase and is useful for drawing a diagram that shows how the extension is partitioned by responsibility rather than by feature alone.

Main entry points: [`src/sidebar/sidebar.tsx`](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/sidebar/sidebar.tsx) (Sidebar), [`src/popup/popup.tsx`](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/popup/popup.tsx) (Popup), [`vite.config.ts`](https://github.com/satriotsubasa/powerplatform-leak/blob/main/vite.config.ts) (Build pipeline), [`src/background/background.ts`](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/background/background.ts) (Background)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Extension runtime"]
  node_n1["Manifest<br/>[manifest.json]"]
  node_n2["Background<br/>service worker<br/>[background.ts]"]
  node_n3["Tab detection<br/>browser integration"]
  node_n4["Content bridge<br/>tab bridge<br/>[content.ts]"]
  node_n5["Page runtime"]
  node_n6["Action modules<br/>page modules<br/>[form-actions.ts]"]
  node_n7["Page bridge<br/>context bridge"]
end

subgraph group_g2["UI surfaces"]
  node_n8["Sidebar<br/>main panel UI<br/>[sidebar.tsx]"]
  node_n9["Sidebar components<br/>panel components<br/>[ActionSection.tsx]"]
  node_n10["Popup<br/>quick action UI<br/>[popup.tsx]"]
  node_n11["Popup components"]
end

subgraph group_g3["Shared core"]
  node_n12["Action registry<br/>routing service"]
  node_n13["Message service<br/>messaging service<br/>[MessageService.ts]"]
  node_n14["Custom commands<br/>command service"]
  node_n15["Impersonation<br/>identity service"]
  node_n16["Diagnostics UI"]
  node_n17["Theme system<br/>ui tokens<br/>[material3Theme.ts]"]
  node_n18["Core utils<br/>shared utilities"]
end

subgraph group_g4["Build & packaging"]
  node_n19["Build pipeline<br/>vite build<br/>[vite.config.ts]"]
  node_n20["Release scripts<br/>packaging scripts<br/>[package.js]"]
end

node_n1 -->|"declares"| node_n2
node_n1 -->|"declares"| node_n10
node_n1 -->|"declares"| node_n8
node_n1 -->|"loads"| node_n4
node_n2 -->|"uses"| node_n3
node_n2 -->|"routes"| node_n13
node_n2 -.->|"orchestrated by"| node_n1
node_n4 -->|"injects"| node_n5
node_n4 -->|"bridges"| node_n7
node_n4 -->|"forwards"| node_n13
node_n5 -->|"hosts"| node_n6
node_n5 -->|"executes"| node_n12
node_n5 -.->|"shares"| node_n18
node_n8 -->|"composes"| node_n9
node_n8 -->|"dispatches"| node_n12
node_n8 -->|"manages"| node_n14
node_n8 -->|"exposes"| node_n15
node_n8 -->|"uses"| node_n16
node_n10 -->|"composes"| node_n11
node_n10 -->|"dispatches"| node_n12
node_n10 -->|"uses"| node_n16
node_n16 -.->|"gathers from"| node_n5
node_n16 -.->|"shared by"| node_n8
node_n16 -.->|"shared by"| node_n10
node_n17 -.->|"themes"| node_n8
node_n17 -.->|"themes"| node_n10
node_n18 -.->|"supports"| node_n2
node_n18 -.->|"supports"| node_n4
node_n19 -.->|"builds"| node_n2
node_n19 -.->|"builds"| node_n4
node_n19 -.->|"builds"| node_n5
node_n19 -.->|"builds"| node_n8
node_n19 -.->|"builds"| node_n10
node_n20 -.->|"packages"| node_n19

click node_n1 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/manifest.json"
click node_n2 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/background/background.ts"
click node_n3 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/background/dynamics-detection.ts"
click node_n4 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/content/content.ts"
click node_n5 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/content/levelup.extension.ts"
click node_n6 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/content/modules/form-actions.ts"
click node_n7 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/content/page-context-bridge.ts"
click node_n8 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/sidebar/sidebar.tsx"
click node_n9 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/sidebar/components/ActionSection.tsx"
click node_n10 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/popup/popup.tsx"
click node_n11 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/popup/components/PopupActionSection.tsx"
click node_n12 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/services/ActionHandlerRegistry.ts"
click node_n13 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/services/MessageService.ts"
click node_n14 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/services/CustomCommandsService.ts"
click node_n15 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/services/ImpersonationService.ts"
click node_n16 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/ui/diagnostics/DiagnosticsDialog.tsx"
click node_n17 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/ui/material3/material3Theme.ts"
click node_n18 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/utils/dynamicsDetection.ts"
click node_n19 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/vite.config.ts"
click node_n20 "https://github.com/satriotsubasa/powerplatform-leak/blob/main/scripts/package.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n1,node_n2,node_n3,node_n4,node_n5,node_n6,node_n7 toneBlue
class node_n8,node_n9,node_n10,node_n11 toneAmber
class node_n12,node_n13,node_n14,node_n15,node_n16,node_n17,node_n18 toneMint
class node_n19,node_n20 toneRose
```

## Components

### Extension runtime

Manifest, background, content, and injected page execution boundaries.

- [Manifest](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/manifest.json): extension manifest · Root integration point that wires together the service worker, popup, side panel, permissions, and web-accessible assets. · `src/manifest.json`
- [Background](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/background/background.ts): service worker · Coordinates tab detection, side panel behavior, context menus, and extension-level message handling. · `src/background/background.ts`
- [Tab detection](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/background/dynamics-detection.ts): browser integration · Identifies Dynamics/Power Apps tabs and supports background-level routing decisions. · `src/background/dynamics-detection.ts`
- [Content bridge](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/content/content.ts): tab bridge · Injects the page runtime, forwards messages, and mediates long-running request overlays. · `src/content/content.ts`
- [Page runtime](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/content/levelup.extension.ts): in-page runtime · Injected Dynamics execution environment that runs actions against Xrm and page APIs. · `src/content/levelup.extension.ts`
- [Action modules](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/content/modules/form-actions.ts): page modules · Concern-based action implementations for forms, navigation, debugging, diagnostics, admin tasks, and web API access. · `src/content/modules/form-actions.ts`
- [Page bridge](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/content/page-context-bridge.ts): context bridge · Shared bridge utilities that connect extension messages to the page context. · `src/content/page-context-bridge.ts`

### UI surfaces

Sidebar and popup entry points plus shared UI components.

- [Sidebar](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/sidebar/sidebar.tsx): main panel UI · Primary workspace UI for action catalog, favorites, recent items, custom commands, diagnostics, impersonation, and preferences. · `src/sidebar/sidebar.tsx`
- [Sidebar components](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/sidebar/components/ActionSection.tsx): panel components · Reusable sidebar UI pieces such as action sections, dialogs, status, alerts, and command editing. · `src/sidebar/components/ActionSection.tsx`
- [Popup](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/popup/popup.tsx): quick action UI · Compact surface for common actions and mode switching using the same action model as the sidebar. · `src/popup/popup.tsx`
- [Popup components](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/popup/components/PopupActionSection.tsx): popup components · Popup-specific layout and controls for action sections, headers, and sidebar mode selection. · `src/popup/components/PopupActionSection.tsx`

### Shared core

Message routing, services, utilities, and types reused across surfaces.

- [Action registry](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/services/ActionHandlerRegistry.ts): routing service · Maps action IDs to executable behaviors and centralizes action dispatch rules. · `src/services/ActionHandlerRegistry.ts`
- [Message service](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/services/MessageService.ts): messaging service · Carries extension messages across UI, background, and content boundaries. · `src/services/MessageService.ts`
- [Custom commands](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/services/CustomCommandsService.ts): command service · Stores and manages user-defined actions and community command workflows. · `src/services/CustomCommandsService.ts`
- [Impersonation](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/services/ImpersonationService.ts): identity service · Manages impersonation state and behavior that affects action execution context. · `src/services/ImpersonationService.ts`
- [Diagnostics UI](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/ui/diagnostics/DiagnosticsDialog.tsx): shared diagnostics ui · Shared diagnostics dialog, state, table, and launcher components consumed by multiple surfaces. · `src/ui/diagnostics/DiagnosticsDialog.tsx`
- [Theme system](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/ui/material3/material3Theme.ts): ui tokens · Material 3 tokens and theme primitives used to keep presentation consistent across surfaces. · `src/ui/material3/material3Theme.ts`
- [Core utils](https://github.com/satriotsubasa/powerplatform-leak/blob/main/src/utils/dynamicsDetection.ts): shared utilities · Shared helpers for Dynamics detection, icons, debounce, overlay focus, and active page context. · `src/utils/dynamicsDetection.ts`

### Build & packaging

Vite build entry points and release scripts.

- [Build pipeline](https://github.com/satriotsubasa/powerplatform-leak/blob/main/vite.config.ts): vite build · Multi-entry build configuration that produces the extension bundles for background, content, injected runtime, sidebar, and popup. · `vite.config.ts`
- [Release scripts](https://github.com/satriotsubasa/powerplatform-leak/blob/main/scripts/package.js): packaging scripts · Version bumping, release notes generation, and ZIP packaging for distribution artifacts. · `scripts/package.js`

## Connections

- Manifest → Background: declares · Manifest registers the background service worker.
- Manifest → Popup: declares · Manifest registers the popup entry point.
- Manifest → Sidebar: declares · Manifest registers the side panel entry point.
- Manifest → Content bridge: loads · Manifest exposes content assets and wiring for tab injection.
- Background → Tab detection: uses · Background relies on tab detection to scope Dynamics behavior.
- Background → Message service: routes · Background handles extension message brokering.
- Background → Manifest: orchestrated by · Background responsibilities are rooted in manifest wiring.
- Content bridge → Page runtime: injects · Content script injects the page runtime into the active tab.
- Content bridge → Page bridge: bridges · Content script uses the page bridge to cross the extension/page boundary.
- Content bridge → Message service: forwards · Content script relays messages between page and extension layers.
- Page runtime → Action modules: hosts · Injected runtime loads module-based action implementations.
- Page runtime → Action registry: executes · Action routing resolves into page-context behaviors.
- Page runtime → Core utils: shares · Runtime reuses shared helpers and page detection utilities.
- Sidebar → Sidebar components: composes · Sidebar is built from many reusable sidebar components.
- Sidebar → Action registry: dispatches · Sidebar action selections flow into the registry.
- Sidebar → Custom commands: manages · Sidebar surfaces custom command creation and usage.
- Sidebar → Impersonation: exposes · Sidebar presents impersonation controls and state.
- Sidebar → Diagnostics UI: uses · Sidebar consumes the shared diagnostics UI package.
- Popup → Popup components: composes · Popup is assembled from popup-specific components.
- Popup → Action registry: dispatches · Popup reuses the same action routing model as the sidebar.
- Popup → Diagnostics UI: uses · Popup also consumes the shared diagnostics UI.
- Diagnostics UI → Page runtime: gathers from · Diagnostics UI depends on page-context diagnostics collection.
- Diagnostics UI → Sidebar: shared by · Used from the sidebar diagnostics section.
- Diagnostics UI → Popup: shared by · Used from the popup diagnostics section.
- Theme system → Sidebar: themes · Theme tokens drive sidebar presentation.
- Theme system → Popup: themes · Theme tokens also influence popup presentation.
- Core utils → Background: supports · Shared utilities feed browser-level detection and UI behavior.
- Core utils → Content bridge: supports · Utilities are reused by the content bridge.
- Build pipeline → Background: builds · Vite bundles the background entry.
- Build pipeline → Content bridge: builds · Vite bundles the content entry.
- Build pipeline → Page runtime: builds · Vite bundles the injected page runtime.
- Build pipeline → Sidebar: builds · Vite bundles the sidebar entry.
- Build pipeline → Popup: builds · Vite bundles the popup entry.
- Release scripts → Build pipeline: packages · Release scripts consume build output and assemble distributable artifacts.
