ドキュメント
// システム設計

プロジェクトアーキテクチャ

Eidolonは、最大の互換性のために公式のWokwiリポジトリを使用する完全ローカルのArduinoエミュレータです。実際のAVR8 CPUエミュレーション、48以上のインタラクティブな電子コンポーネント、包括的なワイヤシステム、ビルド時のコンポーネント検出パイプラインを備えています。

高レベル概要

Browser (React + Vite)
  ├── Monaco Editor ──► useEditorStore (Zustand)
  ├── SimulatorCanvas ──► useSimulatorStore (Zustand)
  │     ├── AVRSimulator (avr8js)   16 MHz AVR8 CPU
  │     ├── RP2040Simulator (rp2040js)
  │     ├── PinManager              pin → component mapping
  │     ├── PartSimulationRegistry  16 interactive parts
  │     └── 48+ wokwi-elements      Lit Web Components
  └── HTTP (Axios) ──► eidolon-server (port 8001)
        └── eidolon-firmware ──► arduino-cli subprocess

データフロー

1. コンパイル

Click "Compile"
  → EditorToolbar reads all workspace files
  → POST /api/compile/  { files, board_fqbn }
  → eidolon-firmware writes the sketch to a build directory
  → arduino-cli compile --fqbn <board> --output-dir build/
  → Returns hex_content (Intel HEX string)
  → useSimulatorStore.setCompiledHex() → loadHex()

2. シミュレーションループ

Click "Run"
  → AVRSimulator.start()
  → requestAnimationFrame loop @ ~60 FPS
  → Each frame: Math.floor(267 000 × speed) cycles
    ├── avrInstruction(cpu)   — decode + execute one AVR instruction
    └── cpu.tick()            — advance Timer0/1/2, USART, ADC
  → PORTB/C/D write listeners fire
  → PinManager.updatePort() → per-pin callbacks
  → PartSimulationRegistry.onPinStateChange()
  → wokwi-elements update visually

3. 入力コンポーネント

User presses button on canvas
  → wokwi web component fires 'button-press' event
  → DynamicComponent catches event
  → PartSimulationRegistry.attachEvents() handler
  → AVRSimulator.setPinState(arduinoPin, LOW)
  → AVRIOPort.setPin() injects external pin state
  → CPU reads pin in next instruction

主要フロントエンドストア (Zustand)

ストア主要状態目的
useEditorStorefiles[]、activeFileIdマルチファイルMonacoワークスペース
useSimulatorStoresimulator、components、wires、runningシミュレーション+キャンバス状態
useProjectStoreprojectId、slug現在開いているプロジェクト

バックエンドルート

ルート説明
POST /api/compile/スケッチファイルのコンパイル - Intel HEX / UF2
GET /api/compile/boards利用可能なボードの一覧
GET /api/libraries/*Arduinoライブラリマネージャ統合
GET /healthヘルスチェックエンドポイント

ワイヤシステム

ワイヤは、コンポーネントのピン位置に結び付けられた開始/終了エンドポイントを持つオブジェクトとして保存されます:

1{
2  id: string
3  start: { componentId, pinName, x, y }
4  end:   { componentId, pinName, x, y }
5  color: string
6  signalType: 'digital' | 'analog' | 'power-vcc' | 'power-gnd'
7}
  • 直交配線、斜めセグメントなし
  • セグメントドラッグ、セグメントの向きに垂直にドラッグ
  • 自動更新、コンポーネント移動時にワイヤ位置を再計算
  • グリッドスナップ、すべてのワイヤエンドポイントに20 pxグリッド
詳細: リポジトリ内の docs/ARCHITECTURE.md を参照してください。