How n-ziermann-youtube/electron-course works
Project Type and Purpose
• This is a desktop full-stack application built with Electron.
• Purpose: display system resource usage (CPU, RAM, FS) in a React/TypeScript UI, with IPC, tray/hide functionality, and custom menus.
File Structure
• src/electron: Electron “main” process code
• main.ts – app lifecycle, window creation
• preload.cts – contextBridge setup for IPC
• menu.ts – custom menu bar definitions
• tray.ts / tray.test.ts – system tray behavior and tests
• resourceManager.ts – system metrics retrieval
• pathResolver.ts, util.ts – file paths, utility functions
• src/ui: Renderer process (React)
• main.tsx – UI entry point
• App.tsx, Chart.tsx, BaseChart.tsx – React components displaying metrics
• useStatistics.ts – custom hook fetching data via IPC
• assets/, CSS files – styling and static resources
• Config & Build
• vite.config.ts – renderer build pipeline
• electron-builder.json – packaging settings
• tsconfig*.json – TypeScript configuration
• Testing
• e2e/example.spec.ts + playwright.config.ts – end-to-end tests
• Vitest (implicitly via package.json) for unit tests
Extract Architectural Insights from README
• Emphasizes typesafe IPC, hide-to-tray, custom menu, custom window frame.
• Testing via Playwright and Vitest.
Main Components
a. Electron Main Process
• Window Manager (main.ts)
• Tray & Menu Controller (tray.ts, menu.ts)
• Resource Manager Service (resourceManager.ts)
• Preload Script (preload.cts) exposing IPC channels
b. Renderer Process (React App)
• UI Components (App, Chart, BaseChart)
• Data-fetching Hook (useStatistics)
• Static Assets & Styles
c. IPC Channel (Type-safe communication)
d. OS APIs / System Libraries
• Node os/fs modules invoked by resourceManager
e. Build & Packaging
• Vite bundler for renderer
• electron-builder for packaging
f. Testing Frameworks
• Playwright (E2E)
• Vitest (Unit)
Relationships and Interactions
• Window Manager → Launches BrowserWindow → Loads React bundle
• Renderer ↔ Main via IPC channels (e.g., “get-stats” request, “stats-response”)
• Resource Manager polls OS APIs → returns data to Main → forwards to Renderer
• Tray & Menu emit events (click/hide) → Main adjusts window visibility
• Preload script registers secure IPC handlers for use by useStatistics
• Build tools: Vite compiles src/ui → dist; electron-builder packages main & dist into installer
Architectural Patterns
• Separation of Concerns: Main vs. Renderer
• Publisher/Subscriber or Request/Response via IPC
• MVC-style: ResourceManager (Model), IPC (Controller), React UI (View)
• Module encapsulation: utilities, pathResolver, menu definitions separated