How I Put a Real Fruit Fly Brain in the Browser
September 27, 2026 · 8 min read
Neuroscience in a Browser Tab
Tap a button and a few thousand neurons light up, one wave after another, along the real wiring of a fruit fly's nervous system. That's WiredMind: three short classroom lessons where students stimulate neurons, silence them, and watch what changes. No install, no login, no ads.
It's free and open source under the MIT license, and the code is on GitHub. Here's how it works, and the engineering decisions that made it fit in a browser tab.
The Wiring Is Real
Every neuron in WiredMind comes from MaleCNS v1.0: the connectome of the complete central nervous system of one male fruit fly, published by HHMI Janelia FlyEM, the University of Cambridge, the MRC Laboratory of Molecular Biology, and Google Research.
Each connection's weight is the number of synapses the dataset reports between two cells. Each neuron's predicted transmitter sets its sign: acetylcholine excites, GABA and glutamate inhibit.
The full dataset is far too big for a classroom laptop, so each lesson runs on a cut of it:
| Lesson | Built from | Neurons |
|---|---|---|
| How a fly remembers a smell | Receptors, projection neurons, Kenyon cells, output neurons | 4,500 |
| How a fly knows which way it's facing | Ring and compass neurons, plus two hops of partners | 4,000 |
| The 30-millisecond escape | The giant fiber, plus two hops of partners | 3,000 |
Connections of fewer than five synapses are dropped.
From Flat Files to a Browser Tab
The data pipeline is a small Python package managed with uv. It downloads three MaleCNS tables (annotations, transmitters, and synapse weights), checks each file's hash, keeps only typed neurons, cuts the three circuits, and exports three files per circuit:
graph.bin: a 24-byte header, then one 12-byte record per connection (source, target, synapse count, sign).neurons.json: cell type, label, and transmitter for every neuron.- A
.glbmodel: each neuron's skeleton, Draco-compressed, with a point budget that steps down until the file fits under 15 MB.
None of it lives in git. The files ship as a versioned GitHub Release, pinned by sha256 in a lock file, and a pre-commit hook refuses any model or graph file over 1 MB. On deploy, a fetch script downloads the release, verifies every hash, and bakes the landing page animation. The repository stays small enough for a stranger to clone.
A Spiking Simulator That Runs at Frame Rate
Each cell is a leaky integrate-and-fire neuron with the published parameters of Shiu et al. (2024), a whole-brain fly model: rest at −52 mV, threshold at −45 mV, a 20 ms membrane time constant, a 1.8 ms axonal delay, and 0.275 mV per synapse.
The engine steps in 0.1 ms ticks, which divide the delay and the 2.2 ms refractory period exactly. A few choices keep it fast enough to run inside the render loop:
- All state lives in typed arrays, and connections are stored as compressed sparse rows.
- Delays are a ring buffer of 19 tick slots holding the neurons that fired.
- Only neurons that aren't at rest get integrated each tick.
- Noise comes from a counter-based hash of the seed, the neuron, and the tick, so a seed always produces the same spikes.
The viewer also adapts how much fly time it simulates per frame:
const elapsed = performance.now() - started;
if (elapsed > 6)
modelMs.current = Math.max(MIN_MODEL_MS, modelMs.current * 0.75);
else if (elapsed < 2.5) {
modelMs.current = Math.min(MAX_MODEL_MS, modelMs.current + 0.1);
}
A fast laptop plays a lesson at up to 2 ms of fly time per frame. A slower device backs off toward 0.2 ms. Either way it's slow motion, and the simulation gives way before it eats the frame. WebGPU compute sits behind a flag and stays off, because the typed-array engine already holds 60 fps on a 5,000-neuron benchmark.
Drawing Thousands of Neurons
The model file holds a mesh per neuron, but WiredMind never draws those meshes. The browser decodes them with Draco in small batches, yielding to the main thread in between, and reduces each neuron to a centerline of up to 12 points. Every neuron in a circuit then goes into one line geometry.
Spikes are drawn in the shader. Textures with one byte per neuron tell a patched line material which cells are flashing, and neurons outside the lesson's focus fade to 4% of their color. The moving dots are illustration, not real conduction, and they're capped at 32.
The landing page uses a lighter trick. It plays the first 64 milliseconds of the escape reflex, baked ahead of time from the same circuit and simulator, on a 2D canvas at one hundredth of real speed. It pauses off screen, and readers who prefer reduced motion get a still frame.
Share Links That Replay Spike for Spike
The Share button copies a link that reproduces a student's run. Its ?r= parameter is a compact binary record, base64url-encoded: the lesson, the noise seed, and every button press with the simulator tick it landed on.
Open the link and WiredMind resets with that seed and applies each press on its recorded tick, so the same neurons fire at the same moments. A teacher sees exactly what the student saw. The analytics script drops query strings, so replay data never goes to analytics.
Honest About the Science
WiredMind is a teaching tool, not a research model, and the About page says exactly where the line falls. The wiring, synapse counts, signs, and shapes are real. The activity comes from one simple neuron model applied to every cell.
There are no gap junctions, and that matters in the escape lesson: in a real fly, the giant fiber's link to the jump motor neuron leans heavily on electrical synapses. Here it's 90 chemical synapses. Nothing learns, stimulation is idealized, and silencing is a hard clamp.
The copy is tested, too. The science tests run each lesson's steps on the real circuits and check what the text promises:
- Escape: across eight seeds, the giant fiber fires within 10 ms and the jump neurons within 30 ms. Silence the giant fiber and the jump neurons never fire.
- Smell: silencing the Kenyon cells drops their spikes to zero and cuts the output neurons to under 20% of normal.
- About page: the numbers it quotes (1,861 smell receptors, 304 looming cells, 90 synapses) are checked against the data.
If a sentence says something lights up, a test checks that it does.
What Founders Can Take From This
WiredMind is a science project, but its engineering choices are the same ones I make on client work:
- Keep heavy data out of the repo. Version it, pin it by hash, and fetch it at build time.
- Budget for the weakest device. Measure the frame and adapt, instead of hoping.
- Make your claims testable. If the copy says the product does something, write the test that proves it.
- Say what you don't do. A clear list of limitations earns more trust than a vague promise.
Try It
Open wiredmind-edu.vercel.app on a laptop, Chromebook, tablet, or phone. Each lesson takes about 10 minutes, and all three, with discussion, fit in one or two class periods. Next on the roadmap: a Hebrew translation with a right-to-left layout, learning in the smell circuit, and offline support for schools with patchy Wi-Fi.
The code is on GitHub, with good first issues for anyone who wants to contribute.
Neuron data: MaleCNS v1.0 (Berg et al., Cell, 2026), CC BY 4.0. Neuron model and parameters: Shiu et al., Nature, 2024.