Any documentation about Stimulus implementation


Here are some keynotes that I made during my exploration of the framework.

Are there any useful resources that can help understand why things are implemented that way? For example, the purpose of having nested observers, each of them map the scopes to a different data structure?

import { Application } from "@hotwired/stimulus"
const application = Application.start()

The start method will create an instance of the Application class which has two components Router and Dispatcher.


The Router has three main components:

  1. Scope Observer: This class monitors the DOM and is responsible for creating the Scopes instances.

  2. ScopeByIdentifier: maps the identifiers of controllers to the scopes.

  3. ModuleByIdentifier: maps the identifiers of the controllers to the Module structure

Identifier is the first argument of the function “Application.register”

Scope Observer:

It has 4 nested Observers:

  1. Value List Observer (first level).
  2. Token List Observer.
  3. Attribute Observer.
  4. Element Observer (last level).

The two first levels handle one-level or two-level hashes that map some keys to the Scopes instances created by the Scope Observer.

Element Observer interacts directly with the DOM using the built-in function mutationObserver.

Scope By Identifier

A map that associates every identifier to an instance of the Scope class.

Module By Identifier

A map that associates every identifier to an instance of the Module class.


The scope has a reference to the HTML element and a set of methods that refers to the relevant elements on it like targets and classes.


handle mapping between contexts and scopes, and maintain a list of connected contexts.


it has a reference to the Controller instance and the binding Observer.
the binding Observer creates bindings which connects Action to Context. Action refers to the method from the controller that will be called when an event is detected.

1 Like

I don’t know of any resources like that, but bravo on the excellent architectural summary you’ve laid out here! I’ve bookmarked it myself and will surely use it for future reference. Thanks! :clap:

1 Like