Core tour
Blockly code
The code for Blockly can be found on GitHub. This page is intended as a guide so that you can explore Blockly's repository and determine where to start if you're working on a GitHub issue.
If you would like to learn more about Blockly's code, you can do the following:
- Read this document
- Click through the code on GitHub
- Consult the API documentation
Don't worry, you do not have to read and understand every piece of Blockly's code in order to contribute to Blockly! You just need to understand the parts that relate to what you're working on.
Folder structure
The root folder of Blockly's repository contains many files (and some folders) for the configuration of our development tools.
Blockly's source code is located in packages/blockly. As an external
contributor, you will likely focus on the files in the core/ and tests/
folders, but all of the folders are listed below.
packages/blockly/
blocks/- Block definitions for built-in blockscore/bubbles/- Code for creating popover bubbles, such as mutator UIclipboard/- Copy/paste logiccomments/- Workspace comments and block commentsdragging/- Mechanics for dragging objects in the workspaceevents/- Events class and built-in eventsicons/- Icon class and built-in iconsinputs/- Input types and their connectionsinterfaces/- Shared interfaces implemented across corekeyboard_nav/- Keyboard navigationnavigation_policies/- Engines that decide where keyboard focus movesnavigators/- Per-element rules telling the navigator where an element's neighbors are
renderers/- Default rendererscommon/- Base classes shared by the renderersgeras/- Built-in renderer with 3-D edgesmeasurables/- Classes that represent each part of a blockthrasos/- Built-in minimalist renderer, Blockly defaultzelos/- Built-in renderer with rounded blocks
serialization/- Saving and loading workspace statetheme/- Built-in themestoolbox/- The toolboxutils/- Utility functions used throughout core
demos/- Some deprecated Blockly demos. Up-to-date demos and examples are in blockly-samples.generators/- Code generators for the built-in languagesmedia/- Sound effects, cursors, etc.msg/- Translated message stringsscripts/- Scripts for building, packaging, and maintaining Blockly.tests/- Unit teststypings/- Supplemental hand-written type declarations
Core files
There are many files in core/ that don't live in a subfolder, for various
reasons. If you're making a change to Blockly, you should take a look at these
files, as well as the subfolders in core/, to find the relevant code.
Note that Blockly's foundational base classes, like Block, Workspace, and
Connection are located in the core/ folder, outside of any subfolders.
Blockly docs
Blockly's documentation is located in packages/docs.
As an external contributor, you will likely focus on the files in the docs/
and static/ folders, but all of the folders are listed below.
packages/docs/
docs/- The documentation content itself, written in Markdown/MDXcodelabs/- Step-by-step tutorialsguides/- Topic-based how-to guidespublications/- Academic papers and talks about Blocklyreference/- Generated API reference
src/- Source code for the Docusaurus sitecomponents/- Custom React components used in the docscss/- Custom stylespages/- Standalone pages outside the docs contenttheme/- Docusaurus theme overridesutils/- Utilities for website analytics
static/- Static assets (images, redirects, etc.)
API documentation
Blockly also offers API reference documentation that details the public API code. The API docs are automatically generated from the code itself, so they are another great resource for understanding Blockly's code.
Model vs. view
Before digging into core/, it's worth understanding one key part of Blockly's
architecture: Blockly separates data modeling from rendering. In practice, this
means that some parts of Blockly have two classes that represent them: one for
the data model, and one for the rendered version.
For an example, look at the implementation of blocks. In the core/ folder,
there are two files that implement blocks: block.ts and block_svg.ts.
In block.ts, the Block parent class has functions to handle data associated
with that block and how it behaves. There are functions in the Block class
that do deal with visual aspects of a block, like setColour. If you look
closely at setColour in the Block class, you'll see that setColour just
saves the colour. It does not render or display that colour.
block_svg.ts, on the other hand, creates a BlockSvg class that extends the
Block class to add render management. The setColour override in BlockSvg
calls the super (which saves the colour) and also applies that colour
to the rendered block.