# os-fpga/rapid_power_estimator architecture

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

- Interactive diagram: https://gitdiagram.com/os-fpga/rapid_power_estimator
- Repository: https://github.com/os-fpga/rapid_power_estimator

## Overview

1. **What this repository is**
   Rapid Power Estimator is a **desktop Electron application** for estimating FPGA/SoC power. The product is split into a **JavaScript/React renderer** and a **Python backend** that exposes a local REST API. The README and file layout strongly indicate a single-user, local-tool architecture rather than a hosted web app.

2. **Top-level runtime boundary**
   The Electron shell is driven by `main.js` and `preload.js`, with the UI rendered from `src/`. The Python service lives under `backend/` and is started separately as a local server (`backend/restapi_server.py`). This creates a clear boundary between:
   - the **desktop UI/runtime**
   - the **backend analysis/service layer**

3. **Frontend presentation layer**
   The `src/components/` tree is organized around design domains: CPU, memory, peripherals, clocks, DMA, IO, DSP, and fabric logic elements. Most UI is built from reusable tables, modal dialogs, summary cards, and selection panes. This is the primary user-facing layer for entering design parameters and reviewing power estimates.

4. **Frontend state and interaction model**
   Global application state is managed through React context providers such as `GlobalStateProvider`, `SelectionProvider`, `ClockSelectionProvider`, and `SOCTotalPowerProvider`. These providers coordinate the active device/design selections and computed totals across multiple views. The architecture is state-driven: user input in one component updates shared state, which then feeds summary and table components elsewhere.

5. **Frontend-to-backend data flow**
   Frontend utilities under `src/utils/`, especially `serverAPI.js`, are the likely bridge to the backend REST endpoints. The UI does not appear to compute the full power model itself; instead it gathers parameters, sends them to the backend, and renders returned estimates and summaries. This separation keeps the browser/Electron layer focused on interaction and visualization.

6. **Backend REST API layer**
   `backend/api/` contains endpoint modules for each major domain: `bram`, `clock`, `device`, `dsp`, `fabric_le`, `io`, `peripherals`, `project`, plus `utils` and `errors`. This suggests a resource-oriented API where each design subsystem has its own request/response contract. The API layer is the formal boundary between the UI and the internal power-estimation logic.

7. **Backend domain/model layer**
   `backend/submodule/` holds the core estimation model and supporting services:
   - `rs_device`, `rs_device_manager`, `rs_device_resources`
   - `rs_project`
   - `rs_power_config`
   - domain calculators for `bram`, `clock`, `dsp`, `io`, `peripherals`, `fabric_logic_element`
   - `rs_message` and `rs_logger`
   
   These files imply the real business logic lives here, not in the API handlers. The API layer likely delegates to these modules for validation, normalization, device lookup, and power computation.

8. **Device and project inputs**
   `backend/device/` includes XML parsing and resource definitions, which indicates the tool can ingest or interpret device descriptions from structured device files. `backend/api/project.py` and `backend/submodule/rs_project.py` suggest project-level configuration is also a first-class object, likely carrying the current design setup, selected device, and subsystem settings.

9. **Power-estimation workflow**
   The implied flow is:
   - user selects a device/project and fills in subsystem parameters in the UI
   - frontend sends those parameters to the local backend API
   - backend validates inputs, resolves device/resources, and runs per-subsystem calculations
   - results are returned as structured power numbers and summary data
   - frontend renders tables, summaries, and modal drill-downs for worst/typical cases

10. **Error handling and validation**
   `backend/api/errors.py`, plus tests around invalid JSON/schema power configs, show that input validation is a major concern. The backend appears to guard against malformed configuration data before estimation occurs. This is important architecturally because the UI accepts many subsystem-specific forms, and the backend must normalize them into a consistent model.

11. **Testing strategy**
   The repository has layered tests:
   - **Python unit/API tests** under `tests/`
   - **React component tests** under `src/tests/`
   - **end-to-end browser tests** under `tests/e2e/`
   
   This mirrors the architecture: model/service logic is tested separately from UI components, and a smaller set of E2E tests verifies the complete Electron-to-backend user flow.

12. **Tooling, packaging, and docs**
   The project uses modern frontend tooling (`webpack`, `babel`, `jest`, `playwright`) and Python packaging via `requirements.txt`. Documentation is built with **Sphinx** under `docs/` and published to ReadTheDocs. GitHub Actions workflows indicate CI also builds a CentOS image and runs the project test suite, which matters because the backend/native toolchain likely has environment-sensitive dependencies.

13. **How to draw the architecture**
   A good diagram would show:
   - **Electron shell / React UI** on the left
   - **local REST API server (Python)** in the middle
   - **domain calculators + device/project model** behind the API
   - **device XML/config inputs** feeding the backend model
   - **test and docs toolchain** as supporting subsystems around the core app

14. **Key boundary summary**
   The most important separation is between **presentation/state management in React** and **estimation logic/device modeling in Python**. Everything in the UI is organized around collecting design inputs and presenting results; everything in the backend is organized around device data, configuration validation, and subsystem-specific power calculation.

Main entry points: [`backend/submodule`](https://github.com/os-fpga/rapid_power_estimator/tree/main/backend/submodule) (Estimation core), [`backend/api`](https://github.com/os-fpga/rapid_power_estimator/tree/main/backend/api) (API layer), [`src/App.js`](https://github.com/os-fpga/rapid_power_estimator/blob/main/src/App.js) (React UI), [`package.json`](https://github.com/os-fpga/rapid_power_estimator/blob/main/package.json) (CI & build)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop app"]
  node_main_shell["Electron shell<br/>desktop runtime<br/>[main.js]"]
  node_renderer_app["React UI<br/>renderer<br/>[App.js]"]
  node_ui_state(("UI state<br/>react context"))
  node_domain_panels["Design panels<br/>ui components"]
  node_tables_modals["Tables & modals<br/>ui widgets"]
  node_api_bridge["API bridge<br/>frontend utils<br/>[serverAPI.js]"]
end

subgraph group_backend["Python backend"]
  node_rest_server["REST server<br/>python service<br/>[restapi_server.py]"]
  node_api_layer["API layer<br/>endpoint modules"]
  node_project_api["Project API<br/>project endpoint<br/>[project.py]"]
  node_device_api["Device API<br/>device endpoint<br/>[device.py]"]
  node_submodule_core["Estimation core<br/>domain model"]
  node_calculator_domains["Subsystem calculators<br/>power models<br/>[bram.py]"]
  node_device_model["Device model<br/>device resources<br/>[rs_device.py]"]
  node_project_model["Project model<br/>project state<br/>[rs_project.py]"]
  node_device_xml["Device XML<br/>parser"]
  node_backend_utils["Common utils<br/>python helpers<br/>[common_utils.py]"]
end

subgraph group_support["Support"]
  node_python_tests["Python tests<br/>test suite"]
  node_ui_tests["UI tests<br/>component tests"]
  node_e2e_tests["E2E tests<br/>browser tests"]
  node_docs["Docs"]
  node_ci_tooling["CI & build<br/>tooling<br/>[package.json]"]
end

node_main_shell -->|"launches"| node_renderer_app
node_renderer_app -->|"uses"| node_ui_state
node_renderer_app -->|"renders"| node_domain_panels
node_domain_panels -->|"uses"| node_tables_modals
node_domain_panels -->|"requests"| node_api_bridge
node_api_bridge -->|"calls"| node_rest_server
node_rest_server -->|"routes"| node_api_layer
node_api_layer -->|"includes"| node_project_api
node_api_layer -->|"includes"| node_device_api
node_api_layer -->|"delegates"| node_submodule_core
node_submodule_core -->|"contains"| node_project_model
node_submodule_core -->|"contains"| node_device_model
node_submodule_core -->|"contains"| node_calculator_domains
node_device_model -->|"loads"| node_device_xml
node_submodule_core -.->|"shares"| node_backend_utils
node_python_tests -.->|"covers"| node_api_layer
node_python_tests -.->|"covers"| node_submodule_core
node_ui_tests -.->|"covers"| node_renderer_app
node_e2e_tests -.->|"covers"| node_main_shell
node_e2e_tests -.->|"covers"| node_rest_server
node_docs -.->|"documents"| node_submodule_core
node_ci_tooling -.->|"runs"| node_python_tests
node_ci_tooling -.->|"runs"| node_ui_tests
node_ci_tooling -.->|"runs"| node_e2e_tests

click node_main_shell "https://github.com/os-fpga/rapid_power_estimator/blob/main/main.js"
click node_renderer_app "https://github.com/os-fpga/rapid_power_estimator/blob/main/src/App.js"
click node_ui_state "https://github.com/os-fpga/rapid_power_estimator/blob/main/src/GlobalStateProvider.js"
click node_domain_panels "https://github.com/os-fpga/rapid_power_estimator/tree/main/src/components"
click node_tables_modals "https://github.com/os-fpga/rapid_power_estimator/tree/main/src/components/Tables"
click node_api_bridge "https://github.com/os-fpga/rapid_power_estimator/blob/main/src/utils/serverAPI.js"
click node_rest_server "https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/restapi_server.py"
click node_api_layer "https://github.com/os-fpga/rapid_power_estimator/tree/main/backend/api"
click node_project_api "https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/api/project.py"
click node_device_api "https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/api/device.py"
click node_submodule_core "https://github.com/os-fpga/rapid_power_estimator/tree/main/backend/submodule"
click node_calculator_domains "https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/submodule/bram.py"
click node_device_model "https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/submodule/rs_device.py"
click node_project_model "https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/submodule/rs_project.py"
click node_device_xml "https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/device/device_xml_parser.py"
click node_backend_utils "https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/utilities/common_utils.py"
click node_python_tests "https://github.com/os-fpga/rapid_power_estimator/tree/main/tests"
click node_ui_tests "https://github.com/os-fpga/rapid_power_estimator/tree/main/src/tests"
click node_e2e_tests "https://github.com/os-fpga/rapid_power_estimator/tree/main/tests/e2e"
click node_docs "https://github.com/os-fpga/rapid_power_estimator/tree/main/docs/source"
click node_ci_tooling "https://github.com/os-fpga/rapid_power_estimator/blob/main/package.json"

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_main_shell,node_renderer_app,node_ui_state,node_domain_panels,node_tables_modals,node_api_bridge toneBlue
class node_rest_server,node_api_layer,node_project_api,node_device_api,node_submodule_core,node_calculator_domains,node_device_model,node_project_model,node_device_xml,node_backend_utils toneAmber
class node_python_tests,node_ui_tests,node_e2e_tests,node_docs,node_ci_tooling toneMint
```

## Components

### Desktop app

Electron shell and React renderer for the local power-estimation UI.

- [Electron shell](https://github.com/os-fpga/rapid_power_estimator/blob/main/main.js): desktop runtime · Main process and preload bridge for the desktop app. · `main.js`
- [React UI](https://github.com/os-fpga/rapid_power_estimator/blob/main/src/App.js): renderer · Entry point for the React-based presentation layer. · `src/App.js`
- [UI state](https://github.com/os-fpga/rapid_power_estimator/blob/main/src/GlobalStateProvider.js): react context · Shared providers that coordinate selections and totals across views. · `src/GlobalStateProvider.js`
- [Design panels](https://github.com/os-fpga/rapid_power_estimator/tree/main/src/components): ui components · Subsystem-specific input and summary screens for FPGA and SoC power modeling. · `src/components`
- [Tables & modals](https://github.com/os-fpga/rapid_power_estimator/tree/main/src/components/Tables): ui widgets · Reusable table and modal components that present and edit power parameters. · `src/components/Tables`
- [API bridge](https://github.com/os-fpga/rapid_power_estimator/blob/main/src/utils/serverAPI.js): frontend utils · Client-side helper layer used to call the local backend REST API. · `src/utils/serverAPI.js`

### Python backend

Local REST service plus device and estimation model.

- [REST server](https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/restapi_server.py): python service · Local backend server entry point for API requests. · `backend/restapi_server.py`
- [API layer](https://github.com/os-fpga/rapid_power_estimator/tree/main/backend/api): endpoint modules · Resource-oriented request handlers grouped by subsystem and shared concerns. · `backend/api`
- [Project API](https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/api/project.py): project endpoint · Endpoint surface for project-level configuration and orchestration. · `backend/api/project.py`
- [Device API](https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/api/device.py): device endpoint · Endpoint surface for device lookup and resource access. · `backend/api/device.py`
- [Estimation core](https://github.com/os-fpga/rapid_power_estimator/tree/main/backend/submodule): domain model · Central project, device, config, logging, and messaging model used by calculations. · `backend/submodule`
- [Subsystem calculators](https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/submodule/bram.py): power models · Domain calculators for BRAM, clock, DSP, IO, peripherals, and fabric logic. · `backend/submodule/bram.py`
- [Device model](https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/submodule/rs_device.py): device resources · Device representations, managers, and resource catalogs. · `backend/submodule/rs_device.py`
- [Project model](https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/submodule/rs_project.py): project state · Project and power-configuration state used by the estimator. · `backend/submodule/rs_project.py`
- [Device XML](https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/device/device_xml_parser.py): parser · XML parsing and device resource definition loading. · `backend/device/device_xml_parser.py`
- [Common utils](https://github.com/os-fpga/rapid_power_estimator/blob/main/backend/utilities/common_utils.py): python helpers · Shared backend utility functions. · `backend/utilities/common_utils.py`

### Support

Tests, documentation, and build tooling.

- [Python tests](https://github.com/os-fpga/rapid_power_estimator/tree/main/tests): test suite · Unit, API, and server tests covering backend behavior. · `tests`
- [UI tests](https://github.com/os-fpga/rapid_power_estimator/tree/main/src/tests): component tests · React component and provider tests for renderer behavior. · `src/tests`
- [E2E tests](https://github.com/os-fpga/rapid_power_estimator/tree/main/tests/e2e): browser tests · End-to-end tests that verify the Electron-to-backend flow. · `tests/e2e`
- [Docs](https://github.com/os-fpga/rapid_power_estimator/tree/main/docs/source): sphinx docs · Sphinx documentation and user guide content. · `docs/source`
- [CI & build](https://github.com/os-fpga/rapid_power_estimator/blob/main/package.json): tooling · Webpack, Jest, Playwright, and GitHub Actions build/test automation. · `package.json`

## Connections

- Electron shell → React UI: launches · Electron starts the React renderer.
- React UI → UI state: uses · The UI reads and updates shared application state.
- React UI → Design panels: renders · Main app composes the subsystem screens.
- Design panels → Tables & modals: uses · Subsystem panels rely on shared tables and modal dialogs.
- Design panels → API bridge: requests · User input is sent through the frontend API client.
- API bridge → REST server: calls · Frontend utilities communicate with the local Python service.
- REST server → API layer: routes · The server delegates requests to endpoint modules.
- API layer → Project API: includes · Project-related endpoints are one major API surface.
- API layer → Device API: includes · Device-related endpoints are one major API surface.
- API layer → Estimation core: delegates · Handlers delegate validation and computation to core model modules.
- Estimation core → Project model: contains · Project and power configuration state are part of the core model.
- Estimation core → Device model: contains · Device management and resource lookup live in the core model.
- Estimation core → Subsystem calculators: contains · Subsystem power estimators are implemented in the core model layer.
- Device model → Device XML: loads · Device resources are parsed from structured XML definitions.
- Estimation core → Common utils: shares · Core modules use common helper utilities.
- Python tests → API layer: covers · Python tests exercise endpoint behavior.
- Python tests → Estimation core: covers · Python tests validate the estimation model and device logic.
- UI tests → React UI: covers · Component tests exercise the React app and providers.
- E2E tests → Electron shell: covers · End-to-end tests run through the desktop shell.
- E2E tests → REST server: covers · E2E flows verify the backend service integration.
- Docs → Estimation core: documents · User guide and API docs describe the estimator behavior.
- CI & build → Python tests: runs · CI executes backend tests and checks.
- CI & build → UI tests: runs · CI executes renderer tests and checks.
- CI & build → E2E tests: runs · CI executes browser-level end-to-end tests.
