How raspberrypifoundation/blockly works
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: core Core runtime · package.json blockly pkg · tests Test suites · demos Demos
Components 18
Repo
Monorepo root, workflows, and shared release infrastructure
- Blockly repo · Top-level repository for the Blockly library, docs, demos, and release tooling
- Build & release · Gulp scripts, packaging helpers, migrations, and CI/CD workflows
packages/blockly/scripts
Blockly package
Distributable Blockly library and its internal subsystems
- blockly pkg · Primary npm-distributed Blockly package
packages/blockly/package.json - Core runtime · Workspace, blocks, events, fields, interactions, and public composition APIs
packages/blockly/core - Rendering · Common renderer abstractions plus Geras, Zelos, and Thrasos implementations
packages/blockly/core/renderers - Themes · Theme definitions and theme manager influencing block and category appearance
packages/blockly/core/theme - Serialization · Workspace, block, variable, procedure, and comment save/load support
packages/blockly/core/serialization - Built-in blocks · Standard Blockly block definitions bundled with the library
packages/blockly/blocks - Code generators · Target-language generation for JavaScript, Python, Lua, Dart, and PHP
packages/blockly/generators - Messages · JSON message sources, runtime message glue, and type-safe message typings
packages/blockly/msg/json - Integration API · Inject, workspace, toolbox, flyout, clipboard, shortcuts, and other embedding surfaces
packages/blockly/core/inject.ts - Demos · In-repo reference applications showing factory, code, and storage workflows
packages/blockly/demos - App Engine · Older hosted storage and redirect support for legacy deployments
packages/blockly/appengine
Docs site
Docusaurus documentation site and content
- Docs site · Separate documentation and codelab site for Blockly usage and architecture
packages/docs - Guides · Getting started, configuration, custom blocks, programming, and design guides
packages/docs/docs/guides - Codelabs · Step-by-step integration examples for generators, renderers, toolboxes, and more
packages/docs/docs/codelabs - Docs UI · Docusaurus pages, components, theme overrides, and site utilities
packages/docs/src
Tests
Browser, node, generator, migration, and type coverage
- Test suites · Browser, node, generator, migration, theme, type, and integration tests
packages/blockly/tests
Connections 30
- 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