How ismaelpatrana/analisis-complex-power works
Purpose and Entry Points
This is a Vite-served React/TypeScript single-page application for AC circuit simulation and complex-power education. It has two user workflows: a graphical circuit simulator and a standalone theoretical calculator. Browser startup flows from index.html through src/main.tsx into src/App.tsx; application styling is rooted in src/index.css and src/App.css.
Application Shell and Modes
src/App.tsx is the top-level mode coordinator, switching between Circuit Mode and Individual Mode. Circuit-facing composition is centralized in src/components/CircuitMode/CircuitLayout.tsx; the calculation-oriented experience is assembled from src/components/IndividualMode/InputPanel.tsx, src/components/IndividualMode/ResultsPanel.tsx, and src/components/IndividualMode/IndividualWavePanel.tsx.
Circuit Editing and Persistent UI State
The circuit workspace renders and edits components, wires, selection, and properties through src/components/CircuitMode/CircuitBoard.tsx, src/components/CircuitMode/Toolbox.tsx, and src/components/CircuitMode/PropertiesPanel.tsx. Global circuit topology and editing state cross this UI boundary through Zustand in src/store/useCircuitStore.ts. This store is the principal handoff from user graph edits to electrical analysis and back to rendered annotations.
Electrical Analysis Pipeline
Circuit topology and component parameters are transformed into solved AC quantities by src/lib/circuit/analyzer.ts, supported by complex-number operations in src/lib/math/Phasor.ts. The analyzer is the core computation boundary: it produces node/element voltages, currents, and powers for visual consumers such as src/components/CircuitMode/CircuitBoard.tsx and src/components/CircuitMode/PowerTrianglePanel.tsx. Series-component grouping is handled separately in src/components/CircuitMode/seriesGroups.ts.
Power, Compensation, and Derived Views
Reactive-power correction is modeled in src/lib/circuit/compensation.ts and surfaced through src/components/CircuitMode/FPCorrection.tsx. Educational views consume calculated phasor/power data: src/components/CircuitMode/FasorDiagram.tsx, src/components/CircuitMode/Oscilloscope.tsx, and src/components/CircuitMode/ElementTrianglesModal.tsx. Frequency-domain calculations use src/lib/math/fft.ts, shared charting is in src/components/shared/WaveformChart.tsx, and mathematical notation is rendered by src/components/shared/TeX.tsx.
Inference and Input Normalization
The standalone calculator’s derived electrical values are governed by src/lib/engine/InferenceEngine.ts and typed contracts in src/lib/engine/types.ts. Its independent Zustand state boundary is src/store/useEngineStore.ts. This separates partially specified user inputs from deterministic inference, allowing UI panels to display calculated voltage/current/power/factor relationships without coupling to circuit topology.
Runtime and Dependencies
The application runs entirely in the browser under Vite (vite.config.ts) with Node/npm for development. Its stated UI/runtime stack is React, TypeScript, React Flow for the circuit canvas and free-form connections, Zustand state stores, Framer Motion, and Tailwind-oriented styling. No backend, database, authentication service, or remote electrical-analysis API is represented in the repository tree.
Main entry points: analyzer.ts AC circuit analyzer · useCircuitStore.ts Circuit state · CircuitLayout.tsx Circuit layout · useEngineStore.ts Calculator state
Components 20
Application Shell
- Vite browser runtime
vite.config.ts - Browser entry
src/main.tsx - Mode coordinator · Switches between Circuit and Individual modes.
src/App.tsx
Circuit Simulator
- Circuit layout
src/components/CircuitMode/CircuitLayout.tsx - Circuit board · Edits and renders circuit topology and solved annotations.
src/components/CircuitMode/CircuitBoard.tsx - Toolbox
src/components/CircuitMode/Toolbox.tsx - Properties panel
src/components/CircuitMode/PropertiesPanel.tsx - Circuit state · Principal handoff between graph editing, analysis, and annotations.
src/store/useCircuitStore.ts - Series grouping
src/components/CircuitMode/seriesGroups.ts - Power and phasor views · Includes power triangle, correction, and phasor diagram views.
src/components/CircuitMode/PowerTrianglePanel.tsx - Waveform views · Oscilloscope and element-triangle educational views.
src/components/CircuitMode/Oscilloscope.tsx
Electrical Analysis
- AC circuit analyzer · Solves node and element voltage, current, and power quantities.
src/lib/circuit/analyzer.ts - Phasor math
src/lib/math/Phasor.ts - Power compensation
src/lib/circuit/compensation.ts - FFT
src/lib/math/fft.ts
Individual Calculator
- Calculator input panel
src/components/IndividualMode/InputPanel.tsx - Calculator state · Keeps partially specified inputs separate from circuit topology.
src/store/useEngineStore.ts - Inference engine · Derives deterministic electrical relationships from partial inputs.
src/lib/engine/InferenceEngine.ts - Engine contracts
src/lib/engine/types.ts - Calculator results · Results and individual waveform panels.
src/components/IndividualMode/ResultsPanel.tsx
Connections 24
- Vite browser runtime → Browser entry: serves
- Browser entry → Mode coordinator: mounts
- Mode coordinator → Circuit layout: Circuit Mode
- Mode coordinator → Calculator input panel: Individual Mode
- Circuit layout → Circuit board: composes
- Circuit layout → Toolbox: composes
- Circuit layout → Properties panel: composes
- Toolbox → Circuit state: adds components
- Properties panel → Circuit state: edits parameters
- Circuit board → Circuit state: reads and updates topology
- Circuit state → Series grouping: topology
- Circuit state → AC circuit analyzer: circuit graph and parameters
- Series grouping → AC circuit analyzer: series relationships
- Phasor math → AC circuit analyzer: complex operations
- AC circuit analyzer → Circuit state: solved quantities
- AC circuit analyzer → Power and phasor views: power data
- AC circuit analyzer → Waveform views: phasor data
- FFT → Waveform views: frequency analysis
- Power compensation → Power and phasor views: correction results
- Calculator input panel → Calculator state: partial inputs
- Calculator state → Inference engine: input state
- Engine contracts → Inference engine: contracts
- Inference engine → Calculator state: derived values
- Calculator state → Calculator results: calculated state