# sharpie7/circuitjs1 architecture

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

- Interactive diagram: https://gitdiagram.com/sharpie7/circuitjs1
- Repository: https://github.com/sharpie7/circuitjs1

## Overview

##### Project Overview and Main Components
- Recognize that CircuitJS1 is primarily a browser-based simulation application. Its purpose is to simulate electronic circuits by providing a rich, interactive user interface and a simulation engine written in Java (compiled via GWT to JavaScript).
- Following main components:
- User Interface (UI) Layer: Consisting of the HTML pages (e.g., circuitjs1.html, iframe.html in the “war” directory) and associated assets.
- Simulation Engine: Encompassing the Java source code under “src/com/lushprojects/circuitjs1/client” (which includes all the circuit element classes, simulation logic, UI widgets, and dialogs).
- Example Circuits and Test Data: Found in “src/com/lushprojects/circuitjs1/public/circuits” and “tests” directories.
- Build and Deployment Artifacts: The “war” folder for web deployment, and the “app” directory for Electron integration.
- Optional External Services: Includes integration with Dropbox (for circuit import/export), a URL shortening service (via shortrelay.php), and adjustments for circuit style (US vs. Euro) based on query parameters.

##### Analyzing the File Structure for Architecture
- The “src” folder is the heart of the simulation engine. It shows a layered structure with numerous Java classes that deal with individual circuit elements (resistor, capacitor, various logic gates, and more) as well as UI dialogs and simulation control.
- The “war” directory holds the compiled GWT output and web resources. This is the deployable version of the application.
- The “app” directory contains files for building an Electron desktop version. This layer wraps the web application in a native executable container.
- Configuration and project metadata files (.project, .settings, .gitignore, etc.) provide development environment setup information.

##### Relationships and Interaction Flow
- User interacts with the browser-based UI provided in the “war” directory. The UI loads HTML, JavaScript (compiled from GWT), and CSS.
- User actions (e.g., loading a circuit file, starting the simulation, or toggling parameters) trigger events within the simulation engine.
- The simulation engine (from the “src” Java package) processes these events. It manages circuit drawing, performing mathematical simulation of electronic components, and rendering simulation outputs.
- In cases where external integrations (Dropbox, URL shortening) are enabled, the UI components communicate with these services via server-side scripts (shortrelay.php) or API calls embedded within the GWT-compiled JavaScript.
- For the Electron version, the “app” directory files wrap the web application and leverage Electron’s runtime to form a desktop executable. The Electron-specific build uses the same core application (compiled output in “war”).

##### Key Architectural Patterns and Design Principles
- Modularization: The simulation engine’s classes (each circuit element, dialog, and simulation control) should be shown as modular components within a “Simulation Engine” block.
– Presentation Layer (HTML, CSS, JavaScript UI in “war”)
– Business Logic Layer (simulation algorithms and circuit component classes)
– Integration Layer (external services and Electron wrapper)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    U("User"):::ui

    %% Presentation Layer (UI)
    subgraph "Presentation Layer (UI)"
        UI1("circuitjs1.html"):::ui
        UI2("iframe.html"):::ui
        UI3("about.html"):::ui
    end

    %% Business Logic Layer (Simulation Engine)
    subgraph "Business Logic Layer (Simulation Engine)"
        SE("Simulation Engine"):::engine
    end

    %% Test & Examples Layer
    subgraph "Test & Examples"
        EC1("Example Circuits"):::engine
        EC2("Test Data"):::engine
    end

    %% Build & Deployment Layer
    subgraph "Build & Deployment"
        BC1("GWT Compile Process"):::build
        BC2("Web Deployment (war)"):::build
        BC3("Electron App"):::build
    end

    %% External Services Integration Layer
    subgraph "External Services Integration"
        EX1("ImportFromDropbox"):::external
        EX2("ImportFromDropboxDialog"):::external
        EX3("URL Shortening Service"):::external
    end

    %% Connections
    U -->|"initiates"| UI1
    UI1 -->|"triggers simulation"| SE
    UI2 -->|"supports UI actions"| SE
    UI3 -->|"provides info"| SE

    UI1 -->|"loads examples"| EC1
    UI1 -->|"loads tests"| EC2

    SE -->|"uses"| EX1
    SE -->|"uses"| EX2
    SE -->|"calls"| EX3

    SE -->|"GWT compile"| BC1
    BC1 -->|"builds"| BC2
    BC2 -->|"wraps via Electron"| BC3

    %% Click Events
    click UI1 "https://github.com/sharpie7/circuitjs1/blob/master/war/circuitjs.html"
    click UI2 "https://github.com/sharpie7/circuitjs1/blob/master/war/iframe.html"
    click UI3 "https://github.com/sharpie7/circuitjs1/blob/master/war/about.html"
    click SE "https://github.com/sharpie7/circuitjs1/tree/master/src/com/lushprojects/circuitjs1/client"
    click EC1 "https://github.com/sharpie7/circuitjs1/tree/master/src/com/lushprojects/circuitjs1/public/circuits"
    click EC2 "https://github.com/sharpie7/circuitjs1/tree/master/tests"
    click BC2 "https://github.com/sharpie7/circuitjs1/tree/master/war"
    click BC3 "https://github.com/sharpie7/circuitjs1/tree/master/app"
    click EX1 "https://github.com/sharpie7/circuitjs1/blob/master/src/com/lushprojects/circuitjs1/client/ImportFromDropbox.java"
    click EX2 "https://github.com/sharpie7/circuitjs1/blob/master/src/com/lushprojects/circuitjs1/client/ImportFromDropboxDialog.java"
    click EX3 "https://github.com/sharpie7/circuitjs1/blob/master/war/shortrelay.php"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef engine fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef build fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef external fill:#DDA0DD,stroke:#000,stroke-width:2px;
```
