Bridge the gap between visual puzzle blocks and real-world code.
ScratchBridge is an interactive, browser-based workspace that lets you assemble visual programming blocks and instantly see the equivalent Python or JavaScript output — live, with semantic validation as you build.
- Visual Block Editor — toolbox with Print, Assign Variable, and Repeat Loop blocks
- Live Code Preview — every block change instantly re-generates Python and JavaScript output side-by-side
- AST-Backed Architecture — UI interactions map to a typed Abstract Syntax Tree (AST), keeping codegen and validation cleanly separated
- Semantic Validation — real-time detection of empty variable names, negative repeat counts, and static divide-by-zero errors
- Dual Language Output — toggle between Python and JavaScript previews with a single click
- TypeScript Throughout — fully typed AST nodes, expressions, and codegen pipeline
| Layer | Technology |
|---|---|
| Framework | Next.js 16 (App Router) |
| UI | React 19 + Tailwind CSS v4 |
| Language | TypeScript 5 |
| Unit Tests | Vitest |
| E2E Tests | Playwright |
src/
├── app/
│ └── page.tsx # Main workspace UI (block editor + live preview)
├── ast/
│ ├── ast-types.ts # TypeScript types for the AST
│ └── validate-ast.ts # Semantic validator (empty names, div/0, negative counts)
└── codegen/
├── generate-python.ts
└── generate-javascript.ts
tests/
├── generate-javascript.test.ts
└── validate-ast.test.ts
- Node.js 20+
- pnpm (recommended)
# Install dependencies
pnpm install
# Start the development server
pnpm devOpen http://localhost:3000 in your browser.
| Command | Description |
|---|---|
pnpm dev |
Start local dev server |
pnpm build |
Production build |
pnpm test |
Run unit tests (Vitest) |
pnpm test:watch |
Unit tests in watch mode |
pnpm test:e2e |
Run end-to-end tests (Playwright) |
pnpm lint |
Lint the codebase |
- Add blocks from the toolbox on the left panel
- Configure each block inline (variable name, value, repeat count, print text)
- The UI state is derived into an AST on every render
- The AST is validated for semantic errors (shown in the header and a warning tray)
- The AST is compiled to Python and JavaScript, displayed live in the right panel
The validator (validate-ast.ts) catches these errors at edit-time:
| Rule | Example |
|---|---|
| Empty variable name | Assign block with blank name field |
| Negative repeat count | Repeat block set to -5 |
| Static divide-by-zero | 100 / 0 binary expression |
MIT