How os-fpga/rapid_power_estimator works
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: submodule Estimation core · api API layer · App.js React UI · package.json CI & build
Components 21
Desktop app
Electron shell and React renderer for the local power-estimation UI.
- Electron shell · Main process and preload bridge for the desktop app.
main.js - React UI · Entry point for the React-based presentation layer.
src/App.js - UI state · Shared providers that coordinate selections and totals across views.
src/GlobalStateProvider.js - Design panels · Subsystem-specific input and summary screens for FPGA and SoC power modeling.
src/components - Tables & modals · Reusable table and modal components that present and edit power parameters.
src/components/Tables - API bridge · 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 · Local backend server entry point for API requests.
backend/restapi_server.py - API layer · Resource-oriented request handlers grouped by subsystem and shared concerns.
backend/api - Project API · Endpoint surface for project-level configuration and orchestration.
backend/api/project.py - Device API · Endpoint surface for device lookup and resource access.
backend/api/device.py - Estimation core · Central project, device, config, logging, and messaging model used by calculations.
backend/submodule - Subsystem calculators · Domain calculators for BRAM, clock, DSP, IO, peripherals, and fabric logic.
backend/submodule/bram.py - Device model · Device representations, managers, and resource catalogs.
backend/submodule/rs_device.py - Project model · Project and power-configuration state used by the estimator.
backend/submodule/rs_project.py - Device XML · XML parsing and device resource definition loading.
backend/device/device_xml_parser.py - Common utils · Shared backend utility functions.
backend/utilities/common_utils.py
Support
Tests, documentation, and build tooling.
- Python tests · Unit, API, and server tests covering backend behavior.
tests - UI tests · React component and provider tests for renderer behavior.
src/tests - E2E tests · End-to-end tests that verify the Electron-to-backend flow.
tests/e2e - Docs · Sphinx documentation and user guide content.
docs/source - CI & build · Webpack, Jest, Playwright, and GitHub Actions build/test automation.
package.json
Connections 24
- 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.