Ecopages0.10.3

Architecture Overview

Ecopages is designed to be modular, with thin runtime hosts, app-owned core services, and multiple rendering engines. This guide provides a brief overview of how things connect under the hood.

Ownership Model

Ecopages is structured around four main ownership layers:

  1. Core owns orchestration: config finalization, build manifest assembly, server loading, browser bundling coordination, and development invalidation policy.
  2. Integrations own framework semantics: rendering, hydration behavior, framework-specific HMR, and cross-integration ownership policy.
  3. Processors own asset semantics: asset transformation, emitted files, asset-specific caching, and processor-specific watch behavior.
  4. Adapters own transport: the Node HTTP host receives requests, wires server details, and delegates into the shared core pipeline. Each finalized app config has a separate AppRuntime for its build, render, and development state.

Packages declare contributions. Core decides lifecycle ordering and assembles the app-owned runtime/build state.

Request Lifecycle

When a request hits your Ecopages application, it follows this simplified flow:

  1. Runtime Host: the Node HTTP host receives the request and passes it into the shared core request pipeline.
  2. Router: The router matching logic identifies if the path corresponds to a static file, an API route, or a page file in src/pages.
  3. Route Resolver: If it's a page, Ecopages determines which integration handles the file extension (e.g., KitaJS for .kita.tsx).
  4. Integration Renderer: The specific renderer (React, Lit, etc.) is invoked with the page component and props.
  5. Template Composition: The page content is wrapped in the specified HtmlTemplate, Head, and Seo includes.
  6. Response: The final HTML (or JSON for APIs) is sent back to the client.

Plugin Lifecycle

The integration and processor lifecycle is split into stable framework-owned phases.

  1. Config finalization: createApp() loads the defineConfig object from eco.config.ts and finalizes it. This validates registrations, reads each processor's and integration's plugins(app) once, and seals the app-owned build manifest. Processor context initialization and runtime preparation happen after finalization.
  2. Runtime preparation: development, build, and regular preview call Processor setup() before activating Integrations. Production ecopages start restores Processor state from the emitted server-module map and skips setup(). In watch mode, the DevSession attaches the HMR manager and starts the watcher before the app reports readiness.
  3. Request-time rendering: core selects the route and owning integration, then the integration renderer produces the response body.
  4. Development invalidation and HMR: core classifies file changes, processors handle owned watch paths, and integrations participate through HMR strategies.

See the dedicated Plugin Lifecycle guide for the exact ordering and boundaries.

Build and bundling

Core uses Rolldown as the bundled backend. Browser and server artifacts are produced through the build adapter. See Build and Host.

Core Modules

For those wishing to dive deeper, we recommend exploring the source code:

  • createApp: Recommended runtime entrypoint. It always uses the Node HTTP host.
  • EcopagesApp: Owns app-level routes and lifecycle, with one concrete Node server.
  • NodeServerAdapter: Owns the Node HTTP host and composes the request pipeline.
  • DevSession: Owns watch-only resources, including HMR, the Project Watcher, and background Page prewarm.
  • ServerRequestPipeline: Owns request routing, response matching, and page caching.
  • IntegrationPlugin: The base class for all templating integrations.
  • Processor: The asset-processing boundary for file capabilities, transformation, and watch behavior.
  • defineConfig / loadEcoPagesConfig: Ergonomic configuration authoring and asynchronous config loading.

Server Loading Boundary

Server startup and server-side module execution are owned by core through the ServerLoader boundary, not by individual integrations or runtime hosts. Runtime hosts stay transport-oriented: they hand off startup, while core owns config loading, app loading, and invalidation behavior behind the server loader implementation.

Design Philosophy

  • Minimal Configuration: Sensible defaults for structure and asset loading, with a simple config file to override them.
  • Explicit Dependencies: Components declare their own scripts and styles, preventing global bloat.
  • Hybrid by Choice: Optimization for static builds while maintaining full server capabilities.