Estructura

· Estructura

4 min read Original article ↗

Description

Estructura is a lightweight, dependency-free JavaScript framework that lets you assign functions to be automatically attached to custom or extended data types, based on one or more arguments.

Its goal is to provide a solid foundation for programming in JavaScript in the face of the language’s well-known type quirks.

Read more

It is a lightweight, dependency-free runtime solution that requires neither TypeScript nor compile-time type checking, although the npm package includes type declarations for those who work with TypeScript. It lets you identify any data type, create custom types, organize them, and use them knowing that the dispatcher will deterministically attach the registered functions to their corresponding types, whether custom or predefined. It prioritizes low dispatch cost and is compatible with ES3 (1999) and later.

Performance: each call to the dispatcher costs on the order of microseconds. The cost grows with the number of arguments, with the number of types detected per argument, and with subtype functions, which run on every call. Recommendations: reuse the result of _e(value) when calling its methods several times, keep _e.subtype() functions lightweight, and avoid unnecessarily deep subtype chains.

How to use

Import:

  • npm install estructura-js
    
    // ESM (the package includes type declarations for TypeScript)
    import _e from 'estructura-js';
    
    // CommonJS
    const _e = require('estructura-js');
  • <!-- UMD / CDN: Unpkg -->
    <script src="https://unpkg.com/estructura-js"></script>
  • <!-- ESM / CDN: Unpkg -->
    <script type="module">
        import _e from 'https://unpkg.com/estructura-js/dist/estructura.esm.mjs';
    </script>

Examples:

Documentation

  • Version: 1.23.0
  • What’s new in v1.23.0: a faster dispatcher (between 10% and 20% less time in the usual cases, and up to 89% less with many types registered in the root), handlers: 'hidden' by default (breaking change: handlers: 'exposed' restores the previous behavior), a private copy of every registered function, and functions added to Object.prototype no longer affect the registered modules. Release notes.
  • License: MIT
  • NPM: https://npmjs.com/estructura-js
  • GitHub: https://github.com/okzgn/estructura
  • Rationale: Why not build frontend frameworks on raw HTML, CSS or JS? (analytical article and ecosystem proposal).
  • Original prototypes: Emerald (JavaScript library, 2016-2024, website), Componentes (JavaScript frontend framework, 2025).
  • Extensions: the documentation for each extension is in the Extensions section (their repositories are not public yet).

Extensions

The extensions are a modular set of libraries for frontend development, built on the Estructura core. They are published as release candidates (RC) under the AGPL v3 license, with a commercial license available.

Read more

They include building blocks such as an HTTP client, SPA routing, reactivity, DOM control, events, logic orchestration, declarative or asynchronous components, and an in-browser SQLite database. Unified on top of the multiple-dispatch core, they form a lightweight stack with no external dependencies, except SQLite Frontend, which uses the official SQLite WASM build. There are only two dependencies between them: Components requires HTTP, and Handlers requires Events.

Available extensions:

  • HTTP requests over XMLHttpRequest, with callbacks or promises, JSON, and error handling.

    ES3/ES5+AGPL v3UMD

    <!-- EXTENSION: Estructura / HTTP -->
    <script src="https://estructura.okzgn.com/extensions/http/estructura.http.js"></script>
  • Reads and modifies DOM properties through selectors, nodes, or lists, with URL sanitization.

    ES5+AGPL v3UMD

    <!-- EXTENSION: Estructura / DOM -->
    <script src="https://estructura.okzgn.com/extensions/dom/estructura.dom.js"></script>
  • Events with namespaces, modes (once, capture, passive, signal), pausing, and manual triggering.

    ES5/ES6+AGPL v3UMD

    <!-- EXTENSION: Estructura / Events -->
    <script src="https://estructura.okzgn.com/extensions/events/estructura.events.js"></script>
  • Declarative loading of HTML, CSS, and JS components with orchestration, dependencies, and fallbacks.

    ES5/ES6+AGPL v3UMDDep.: HTTP

    <!-- DEPENDENCY: Estructura / HTTP -->
    <script src="https://estructura.okzgn.com/extensions/http/estructura.http.js"></script>
    
    <!-- EXTENSION: Estructura / Components -->
    <script src="https://estructura.okzgn.com/extensions/components/estructura.components.js"></script>
  • Declarative logic with data-e-handler attributes: middleware, success/error states, and lifecycle.

    ES5/ES6+AGPL v3UMDDep.: Events

    <!-- DEPENDENCY: Estructura / Events -->
    <script src="https://estructura.okzgn.com/extensions/events/estructura.events.js"></script>
    
    <!-- EXTENSION: Estructura / Handlers -->
    <script src="https://estructura.okzgn.com/extensions/handlers/estructura.handlers.js"></script>
  • {{ }} templates with two-way data binding between state and the DOM.

    ES6+AGPL v3UMD

    <!-- EXTENSION: Estructura / Reactive -->
    <script src="https://estructura.okzgn.com/extensions/reactive/estructura.reactive.js"></script>
  • SPA routing with parameters, chained middleware, and the History API.

    ES6+AGPL v3UMD

    <!-- EXTENSION: Estructura / Routing -->
    <script src="https://estructura.okzgn.com/extensions/routing/estructura.routing.js"></script>
  • SQLite in WebAssembly inside a Web Worker, with OPFS persistence.

    ES6+ / WebAssembly / Web Workers / OPFSAGPL v3UMDself-hosted

    <!-- EXTENSION: Estructura / SQLite Frontend (self-hosted): copy estructura.sqlite.frontend.js,
         estructura.sqlite.frontend.wasm.worker.js, and _dependencies/_sqlite/ into the same
         directory as this page. The Worker cannot be loaded from a CDN. -->
    <script src="estructura.sqlite.frontend.js"></script>

Requirement: load the Estructura core first as a UMD script (the extensions use the global variable _e, which does not exist when you use the ESM import):

  • <!-- CDN: Unpkg -->
    <script src="https://unpkg.com/estructura-js"></script>
  • <!-- CDN: JSDelivr -->
    <script src="https://cdn.jsdelivr.net/npm/estructura-js"></script>
  • <!-- CDN: Estructura -->
    <script src="https://estructura.okzgn.com/estructura.umd.js"></script>