How dazl-dev/engine works
Project Type and Purpose
• This is an open-source, monorepo-style TypeScript toolkit (“Engine”) for building and running “features” across different environments.
• It provides three main npm packages:
• engine-core: the in-memory runtime and communication framework
• engine-cli: command-line interface for scaffolding, building, and launching
• runtime-node: a Node.js–specific host layer for engine-core
• The repo also contains guides, API documentation configs, example projects, and test-fixture apps.
File Structure Analysis
• Top-level: configuration files (.eslintrc, tsconfig.*, lerna.json), GitHub workflows, README, LICENSE.
• docs-conf & guides: documentation setup for publication.
• examples & test-fixtures: sample apps showing various engine use cases (iframe, React, Node, multi-feature, etc.).
• packages: three sub-packages with their own source (src), tests, build configs, and package.json.
a. Main Components
• Developer & CLI (engine-cli)
• Core Runtime (engine-core)
• Host implementations (runtime-node, iframe, webworker, WS server, socket)
• Feature modules (user code discovered at runtime)
• Build pipeline (esbuild, entrypoint generators)
• Dashboard server (dev-mode UI)
b. Relationships & Data Flow
1. Developer invokes CLI (npx dazl-engine or yarn engine …).
2. CLI loads user config and discovers feature files via engine-core APIs.
3. CLI generates entrypoints for each environment (web, node, iframe) using esbuild plugins.
4. On “run” or “start,” CLI spawns host processes or in-browser contexts (runtime-node, iframe, webworker) and wires them via engine-core communication.
5. engine-core orchestrates message passing between feature instances across hosts (via WS, RPC, postMessage).
6. Dashboard server displays live feature graph and logs by subscribing to engine-core events.
c. Architectural Patterns & Principles
• Modular monorepo with Lerna/yarn workspaces
• Plugin-style host initializers and communication adapters
• Single-entrypoint feature model (feature + multiple env configs)
• Separation of build (static generation) vs. runtime (dynamic wiring)
d. Key Technologies & Frameworks
• TypeScript & ts-configs per package
• esbuild (via CLI plugins) for bundling
• Node.js child processes, worker_threads, iframes, WebSockets
• API Extractor for docs generation
• Mocha/Jest for tests