# raspberrypifoundation/blockly architecture

> Architecture diagram of the GitHub repository raspberrypifoundation/blockly, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/raspberrypifoundation/blockly
- Repository: https://github.com/raspberrypifoundation/blockly

## Overview

This repository is a monorepo centered on the Blockly visual programming library, plus a documentation site and supporting deployment/test infrastructure.

1. **Primary product: `packages/blockly`**
   - This is the distributable library consumed by application developers via npm.
   - It is written primarily in TypeScript/JavaScript and organized around the Blockly editor runtime, block definitions, generators, localization, and packaging assets.

2. **Core runtime boundary: `packages/blockly/core`**
   - `core` contains the editing engine: workspace, blocks, connections, fields, inputs, drag/drop, events, rendering, serialization, keyboard navigation, toolbox/flyout, themes, and UI components.
   - This layer is the main internal dependency hub; most other subsystems build on top of it rather than vice versa.

3. **Block model and editor composition**
   - `packages/blockly/blocks` defines the built-in block catalog, while `packages/blockly/core/blocks.ts` and related infrastructure register and manage them.
   - The editor uses block definitions + core workspace state to render interactive block graphs and emit workspace events.

4. **Code generation boundary**
   - `packages/blockly/generators` contains language-specific generators for JavaScript, Python, Lua, Dart, and PHP.
   - The data flow is from Blockly workspace/block graph to target-language source code, with each language having a shared top-level generator entry and per-category emitters.

5. **Localization and user-facing strings**
   - `packages/blockly/msg/json` is the source of truth for translations; `packages/blockly/msg/messages.js` and `typings/msg` support runtime and type-safe consumption.
   - The library uses message files to externalize UI text across the editor, toolbox, errors, and demos.

6. **Serialization and persistence**
   - `core/serialization` and `core/xml.ts` handle saving/loading workspaces, blocks, variables, procedures, and comments.
   - This is the boundary between in-memory editor state and persisted formats such as XML/JSON used by apps, demos, and tests.

7. **Rendering and themes**
   - The rendering system is split into renderer abstractions and implementations such as `geras`, `zelos`, and `thrasos`, with shared measurable/path-object infrastructure.
   - Themes live in `core/theme` and influence block appearance, category styling, and renderer-specific visual constants.

8. **Integration surfaces for apps**
   - `core/inject.ts`, `workspace.ts`, `toolbox`, `flyout`, `clipboard`, `shortcut_registry`, and related modules are the public-facing composition points used by host applications.
   - Applications embed Blockly into a page, configure options/themes/toolboxes, listen to events, and then serialize or generate code from the workspace.

9. **Demos and developer examples**
   - `packages/blockly/demos` contains in-repo sample applications such as the block factory, code demo, and storage demo.
   - These are reference integrations showing how consumers wire Blockly together with custom blocks, toolboxes, generation, and persistence.

10. **Documentation site: `packages/docs`**
    - This is a separate Docusaurus site containing guides, codelabs, design docs, and images.
    - It documents Blockly’s architecture and extension points, but is not part of the runtime library; it serves as the external knowledge layer for developers.

11. **Legacy App Engine hosting**
    - `packages/blockly/appengine` contains an older Google App Engine deployment with Python/JS pieces, including storage and redirect helpers.
    - This appears to support legacy hosted demos/storage behavior rather than the core library itself.

12. **Build, packaging, and release tooling**
    - `packages/blockly/scripts`, `gulpfile.mjs`, and the repo-level GitHub Actions workflows handle building, packaging, testing, docs deployment, browser testing, and publishing.
    - The release pipeline produces npm artifacts and site updates; tests validate both core behavior and generated outputs.

13. **Testing strategy**
    - There is broad coverage across Mocha browser/node tests, generator golden tests, TypeScript tests, migration validation, and browser-based integration tests.
    - The tests reflect the architecture: they exercise rendering, events, serialization, generators, keyboard navigation, and workspace behavior as separate concerns.

14. **Important architectural boundary**
    - The cleanest diagram boundary is: external app or demo imports `packages/blockly` → configures workspace/toolbox/blocks/themes → user edits blocks in the browser → workspace events/serialization capture state → generators or serializers export code/data.
    - Docs, demos, and App Engine are support systems around that core editor pipeline rather than part of the editor engine itself.

Main entry points: [`packages/blockly/core`](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/core) (Core runtime), [`packages/blockly/package.json`](https://github.com/raspberrypifoundation/blockly/blob/main/packages/blockly/package.json) (blockly pkg), [`packages/blockly/tests`](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/tests) (Test suites), [`packages/blockly/demos`](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/demos) (Demos)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_repo["Repo"]
  node_root["Blockly repo<br/>monorepo"]
  node_build_release["Build & release<br/>tooling"]
end

subgraph group_blockly_pkg["Blockly package"]
  node_blockly_pkg_root["blockly pkg<br/>library package<br/>[package.json]"]
  node_core_runtime["Core runtime<br/>editor engine"]
  node_rendering["Rendering<br/>renderer system"]
  node_theme_system["Themes<br/>theme system"]
  node_serialization["Serialization<br/>persistence layer"]
  node_blocks_catalog["Built-in blocks<br/>block catalog"]
  node_generators["Code generators<br/>language emitters"]
  node_localization["Messages<br/>i18n resources"]
  node_integration_api["Integration API<br/>host integration<br/>[inject.ts]"]
  node_demos["Demos<br/>sample apps"]
  node_appengine["App Engine<br/>legacy hosting"]
end

subgraph group_docs_pkg["Docs site"]
  node_docs_site["Docs site<br/>docusaurus site"]
  node_docs_guides["Guides<br/>docs content"]
  node_docs_codelabs["Codelabs<br/>docs content"]
  node_docs_components["Docs UI<br/>site components"]
end

subgraph group_tests_pkg["Tests"]
  node_tests["Test suites<br/>verification"]
end

node_root -->|"contains"| node_blockly_pkg_root
node_root -->|"contains"| node_docs_site
node_root -->|"orchestrates"| node_build_release
node_blockly_pkg_root -->|"depends on"| node_core_runtime
node_blockly_pkg_root -->|"ships"| node_blocks_catalog
node_blockly_pkg_root -->|"ships"| node_generators
node_blockly_pkg_root -->|"ships"| node_localization
node_core_runtime -->|"exposes"| node_integration_api
node_core_runtime -->|"persists via"| node_serialization
node_core_runtime -->|"renders through"| node_rendering
node_core_runtime -->|"styles with"| node_theme_system
node_core_runtime -->|"registers"| node_blocks_catalog
node_core_runtime -->|"uses"| node_localization
node_generators -.->|"reads state from"| node_serialization
node_demos -->|"demonstrates"| node_integration_api
node_demos -->|"uses"| node_blocks_catalog
node_demos -->|"uses"| node_generators
node_demos -->|"uses"| node_serialization
node_docs_site -->|"publishes"| node_docs_guides
node_docs_site -->|"publishes"| node_docs_codelabs
node_docs_site -->|"implements"| node_docs_components
node_docs_guides -.->|"documents"| node_integration_api
node_docs_codelabs -.->|"mirrors"| node_demos
node_build_release -->|"verifies"| node_tests
node_build_release -->|"deploys"| node_docs_site
node_build_release -.->|"deploys"| node_appengine
node_tests -->|"covers"| node_core_runtime
node_tests -->|"covers"| node_generators
node_tests -->|"covers"| node_serialization
node_tests -->|"covers"| node_theme_system

click node_blockly_pkg_root "https://github.com/raspberrypifoundation/blockly/blob/main/packages/blockly/package.json"
click node_core_runtime "https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/core"
click node_rendering "https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/core/renderers"
click node_theme_system "https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/core/theme"
click node_serialization "https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/core/serialization"
click node_blocks_catalog "https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/blocks"
click node_generators "https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/generators"
click node_localization "https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/msg/json"
click node_integration_api "https://github.com/raspberrypifoundation/blockly/blob/main/packages/blockly/core/inject.ts"
click node_demos "https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/demos"
click node_appengine "https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/appengine"
click node_docs_site "https://github.com/raspberrypifoundation/blockly/tree/main/packages/docs"
click node_docs_guides "https://github.com/raspberrypifoundation/blockly/tree/main/packages/docs/docs/guides"
click node_docs_codelabs "https://github.com/raspberrypifoundation/blockly/tree/main/packages/docs/docs/codelabs"
click node_docs_components "https://github.com/raspberrypifoundation/blockly/tree/main/packages/docs/src"
click node_build_release "https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/scripts"
click node_tests "https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/tests"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_root,node_build_release toneBlue
class node_blockly_pkg_root,node_core_runtime,node_rendering,node_theme_system,node_serialization,node_blocks_catalog,node_generators,node_localization,node_integration_api,node_demos,node_appengine toneAmber
class node_docs_site,node_docs_guides,node_docs_codelabs,node_docs_components toneMint
class node_tests toneRose
```

## Components

### Repo

Monorepo root, workflows, and shared release infrastructure

- **Blockly repo**: monorepo · Top-level repository for the Blockly library, docs, demos, and release tooling
- [Build & release](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/scripts): tooling · Gulp scripts, packaging helpers, migrations, and CI/CD workflows · `packages/blockly/scripts`

### Blockly package

Distributable Blockly library and its internal subsystems

- [blockly pkg](https://github.com/raspberrypifoundation/blockly/blob/main/packages/blockly/package.json): library package · Primary npm-distributed Blockly package · `packages/blockly/package.json`
- [Core runtime](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/core): editor engine · Workspace, blocks, events, fields, interactions, and public composition APIs · `packages/blockly/core`
- [Rendering](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/core/renderers): renderer system · Common renderer abstractions plus Geras, Zelos, and Thrasos implementations · `packages/blockly/core/renderers`
- [Themes](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/core/theme): theme system · Theme definitions and theme manager influencing block and category appearance · `packages/blockly/core/theme`
- [Serialization](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/core/serialization): persistence layer · Workspace, block, variable, procedure, and comment save/load support · `packages/blockly/core/serialization`
- [Built-in blocks](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/blocks): block catalog · Standard Blockly block definitions bundled with the library · `packages/blockly/blocks`
- [Code generators](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/generators): language emitters · Target-language generation for JavaScript, Python, Lua, Dart, and PHP · `packages/blockly/generators`
- [Messages](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/msg/json): i18n resources · JSON message sources, runtime message glue, and type-safe message typings · `packages/blockly/msg/json`
- [Integration API](https://github.com/raspberrypifoundation/blockly/blob/main/packages/blockly/core/inject.ts): host integration · Inject, workspace, toolbox, flyout, clipboard, shortcuts, and other embedding surfaces · `packages/blockly/core/inject.ts`
- [Demos](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/demos): sample apps · In-repo reference applications showing factory, code, and storage workflows · `packages/blockly/demos`
- [App Engine](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/appengine): legacy hosting · Older hosted storage and redirect support for legacy deployments · `packages/blockly/appengine`

### Docs site

Docusaurus documentation site and content

- [Docs site](https://github.com/raspberrypifoundation/blockly/tree/main/packages/docs): docusaurus site · Separate documentation and codelab site for Blockly usage and architecture · `packages/docs`
- [Guides](https://github.com/raspberrypifoundation/blockly/tree/main/packages/docs/docs/guides): docs content · Getting started, configuration, custom blocks, programming, and design guides · `packages/docs/docs/guides`
- [Codelabs](https://github.com/raspberrypifoundation/blockly/tree/main/packages/docs/docs/codelabs): docs content · Step-by-step integration examples for generators, renderers, toolboxes, and more · `packages/docs/docs/codelabs`
- [Docs UI](https://github.com/raspberrypifoundation/blockly/tree/main/packages/docs/src): site components · Docusaurus pages, components, theme overrides, and site utilities · `packages/docs/src`

### Tests

Browser, node, generator, migration, and type coverage

- [Test suites](https://github.com/raspberrypifoundation/blockly/tree/main/packages/blockly/tests): verification · Browser, node, generator, migration, theme, type, and integration tests · `packages/blockly/tests`

## Connections

- Blockly repo → blockly pkg: contains · Repository root contains the distributable Blockly package
- Blockly repo → Docs site: contains · Repository root contains the documentation site
- Blockly repo → Build & release: orchestrates · Repo-level workflows coordinate build, release, deploy, and test automation
- blockly pkg → Core runtime: depends on · Primary library entry is built around the editor runtime
- blockly pkg → Built-in blocks: ships · Library bundles built-in block definitions
- blockly pkg → Code generators: ships · Library bundles target-language code generation
- blockly pkg → Messages: ships · Library exposes localized UI text and typings
- Core runtime → Integration API: exposes · Core runtime provides the public embedding and composition APIs
- Core runtime → Serialization: persists via · Workspace state is saved and restored through serializers and XML
- Core runtime → Rendering: renders through · Block and workspace UI is rendered via the renderer subsystem
- Core runtime → Themes: styles with · Themes control colors, styles, and renderer constants
- Core runtime → Built-in blocks: registers · Built-in blocks are registered into the core runtime
- Core runtime → Messages: uses · Editor UI strings are resolved through the message layer
- Code generators → Serialization: reads state from · Generators consume workspace/block models that are often serialized or reconstructed
- Demos → Integration API: demonstrates · Demos show how host apps embed and configure Blockly
- Demos → Built-in blocks: uses · Reference apps load built-in and custom blocks
- Demos → Code generators: uses · Code demos and factory flows exercise language generation
- Demos → Serialization: uses · Sample apps demonstrate workspace persistence
- Docs site → Guides: publishes · Site serves user and contributor guides
- Docs site → Codelabs: publishes · Site serves hands-on codelabs
- Docs site → Docs UI: implements · Site UI and layout are built from local React/Docusaurus components
- Guides → Integration API: documents · Guides explain embedding, toolbox, events, serialization, and configuration
- Codelabs → Demos: mirrors · Codelabs provide worked examples similar to in-repo demo flows
- Build & release → Test suites: verifies · Build and release tooling is guarded by the repository test suites
- Build & release → Docs site: deploys · Tooling handles docs build and deployment workflows
- Build & release → App Engine: deploys · Tooling includes legacy App Engine deployment support
- Test suites → Core runtime: covers · Tests exercise workspace behavior, events, rendering, keyboard nav, and UI flows
- Test suites → Code generators: covers · Generator suites validate emitted source across languages
- Test suites → Serialization: covers · Serialization tests validate XML/JSON load-save boundaries
- Test suites → Themes: covers · Theme tests validate appearance and theme switching
