Skip to content
16 min read

The whole valley in a browser tab

How I built Tiny Kathmandu with coding agents: a map format they could share, building heights the map didn’t have, an iPhone that kept reloading, and the checks I wrote so fixes stayed fixed.

Tiny Kathmandu is a playable 3D model of the Kathmandu Valley that runs in your browser. You can drive a Sajha bus, row a wooden dunga down the Bagmati, or fly a pigeon over Boudhanath. It has nearly 789,000 buildings, 48 landmarks, and a sky that follows Kathmandu’s time and weather.

I built it in two weeks with coding agents working in parallel. Most of my time went into noticing what looked wrong. The map didn’t know how tall anything was, my iPhone kept reloading the tab, and a supermarket faced the wrong road. The mountains I’d spent hours drawing vanished into the November haze.

A pigeon in flight over Boudhanath stupa, with prayer flags and the valley behind it
A pigeon in flight over Boudhanath stupa, with prayer flags and the valley behind it

It started on a Sunday evening when I found Tiny Warsaw, Dominik Roszkowski’s miniature Warsaw in a browser. Ten minutes later I wanted to fly over my own valley and recognise the streets below.

Here’s the launch trailer, if you’d like to see the valley move before reading how it was built.

Play the Tiny Kathmandu launch trailer

I wrote the map format down first

Before I let any agent build a house, I had to answer a boring question. If one agent draws a road and another puts a bus on it, which way is north? So my first commit wrote down the coordinate system and the map format that every part of the valley would share. I gave it one rule: if the format changed, the file describing it, the Python code that writes it, and the TypeScript code that reads it all changed in the same edit.

I used Claude Code for the whole project. That first night I split the work by area and gave each agent a folder of its own: the map pipeline, the city renderer, the sky, the landmarks, the street props, driving, flying, and the UI. The format file was the one thing they all had to agree on.

Then I let them build side by side. When I went back through the commit history, that night had moved faster than I remembered. The sky landed at 22:19, the first five landmarks at 22:21, the map pipeline at 22:37, and the city renderer at 22:40. Thirty-seven minutes after my first commit, the valley was on screen. Around 1 a.m., flying, driving, the sky, the street props, and the UI each got a round of QA fixes. By 3:30 there were 47 commits, and I could search in English and Nepali, drive around the Ring Road, and fly toward Langtang.

Agents working in parallel don’t settle disagreements with each other, so I had to write down what they shared before they started. Once that was done, my job for the next two weeks was mostly looking at the valley and turning whatever looked wrong into something the agents could check.

What I put in the shared format

I kept the format in one Markdown file, FORMAT.md. The map is in metres from an origin at (27.7025, 85.3225), with a base elevation of 1,300 m. The axes point east, up, and south, so north is the way a three.js camera faces by default. The file also spells out how to read the gzip-compressed map chunks: little-endian fields, decimetre units for building geometry, and counter-clockwise footprints.

Making Boudhanath look like Boudhanath

When I asked an agent for a bird to fly over Boudhanath, it put a griffon in the flight menu. By the next evening, I had a pigeon.

The griffon was the fun mistake. The others were less charming. Houses stood in the Bagmati and footbridges stopped halfway across the Ring Road. When I asked for toy colours, I got teal and lilac roofs, and big place labels floating over the city. Drag across Boudhanath to see what changed over the next two days.

The detail I kept coming back to was the side wall. From the street, a Kathmandu house shows you a painted front. From above, I kept seeing bare brick and grey stripes where the concrete floors meet the wall. If you expect a neighbour to build right up against that side, why paint it?

Once I started pointing at details like that in screenshots, I could give the agents something specific to build. I asked for ribbed shutters along the shops, rebar sticking out of roofs that might get another floor, and black wires sagging between poles. At the Phulbari corner I added a chiya seller in a Dhaka topi who pours tea when you slow down nearby.

Phulbari corner, Boudhanath
Phulbari street corner near Boudhanath rendered in Tiny Kathmandu, showing painted fronts with bare brick side walls, ribbed rolling shutters, rooftop water tanks, prayer flags, utility wires, and a chiya cart
Select a numbered marker, or a tab above, to zoom into a detail.
How I drew the street details
  • Brick and plaster. I gave each wall a flag that marks it as painted or bare, and bare means exposed brick or grey cement render. The fragment shader draws brick courses, concrete floor bands, and rain streaks from the wall’s coordinates, so I didn’t need an image texture.
  • Shutters and shop signs. Ground floors on busy streets get ribbed rolling shutters. My bake produced 36,096 shop signs from names in OpenStreetMap and Overture Places. My favourite to find is Honacha behind Krishna Mandir in Patan.
  • Rooftops and street life. Close to the camera, I add Hilltake water tanks, corrugated tin sheds, laundry, and rebar. One shared wind moves all the prayer flags, the trees, and the smoke.
  • Number plates. I drew Devanagari characters such as बा २ च ४५६७ with a seven-row pixel font made of flat rectangles. The same code draws red private plates and black public plates, again without an image texture.

Krishna Mandir’s stone shikhara and the pagoda temples of Patan Durbar Square, with the Honacha sign on the far side of the square
Krishna Mandir’s stone shikhara and the pagoda temples of Patan Durbar Square, with the Honacha sign on the far side of the square

A scooter ride through a galli with prayer flags, shop signs, and pedestrians
A scooter ride through a galli with prayer flags, shop signs, and pedestrians

The map didn’t know how tall anything was

A building outline told me how much ground a house covers, but not how high to pull up its walls. Of nearly 789,000 buildings in the finished model, only about one in 42 came with a usable height or storey count.

I could have given every house four floors, but then the whole valley would share one roofline, and the valley doesn’t look like that. In the old streets of Patan, a wall of taller brick houses feels right. Near the Bagmati, I wanted the houses closest to the water to stay low. So I taught the bake to use clues like those whenever it had to guess.

The outlines had gaps, too. Busy roads in Baneshwor, Koteshwor, and Kalanki had stretches that were empty on the map but built up in real life. Where there was room along the road, I filled those stretches with narrow row houses. They make the street feel continuous, but I made up their positions and heights.

The street below is made up, but it runs through four kinds of neighbourhood and uses the bake’s real rules. Step through them with Next, and select any house to see how it got its height.

How I estimated heights and filled gaps
  • Inputs. I started with OpenStreetMap outlines and added satellite-detected footprints from Overture Maps, which draws on Google and Microsoft sources. Of the 788,986 buildings in my November 29 bake, 18,588 (2.4%) had a usable height or storey tag. That total includes 295,849 detected footprints and 40,887 infill houses I generated. Together the outlines have about 3.5 million vertices.
  • Height rules. First I throw out implausible tags, like 0.1 m on a heritage footprint or 45 storeys on a small house. For ordinary untagged houses, I combine the number of buildings within 150 m with the distance to urban centres. Dense cores can get four to six storeys, and main-road frontage in town can get two to six. A stable seed varies the height from house to house. Near rivers, I cap untagged buildings at one storey within 6 m of the water and two within 14 m.
  • Tall blocks. I used the 2023 layer of Google’s Open Buildings 2.5D Temporal dataset to raise the estimates for 523 large blocks. Valid height or storey tags still win when I pick a starting height, and landmark sites get their own height limits around them.
  • Roads. To keep walls off the pavement, my pipeline uses the same road geometry as the renderer and trims overlapping footprints back to a 0.4 m gap. Before adding an infill house, I check it against roads, existing buildings, water, and other areas I wanted to keep clear.

My iPhone kept reloading the valley

The first time I flew over the valley on my iPhone, the tab reloaded mid-flight. The same flight had been smooth on my laptop. That sent me after two separate questions: how much of the valley the phone had to download, and how much it held in memory once it started drawing.

My baked map files came to 45 MB. I didn’t want a phone to fetch all of that up front, so the app starts with a small patch around Boudhanath and a simplified view of nearby buildings, then streams the rest as you explore. Faraway houses can be boxes. As you get closer they get real shapes, and closer still, water tanks and laundry. The narrow gallis help too. Down at street level, the first row of houses hides most of the blocks behind it, so the area that needs full detail shrinks.

This is the whole path, from the bake on my laptop to the tab on your phone.

How the valley gets from map data to your browserOpenStreetMap -> Prepare the map. Overture -> Prepare the map. Google 2.5D -> Prepare the map. AWS Terrain -> Prepare the map. Prepare the map -> 2,613 building chunks: pack map. 2,613 building chunks -> Cloudflare edge. Cloudflare edge -> Web Workers: fetch nearby. Web Workers -> three.jspack mapfetch nearbyBaked once on my laptopStreamed in your browserOpenStreetMapbuildings and roadsOverturedetected footprintsGoogle 2.5D523 tall blocksAWS Terrainvalley + HimalayaPrepare the mapMerge outlines, estimate heights, fill gaps, and trim roads2,613 building chunks45 MB map bakeCloudflare edgeopening and regional packsWeb Workersoff-thread meshes & road layoutthree.jsDetail follows the camera
5 steps

Press play to walk through it, or step with the arrows.

Memory was the other half. After the graphics card had its copy of the scenery, JavaScript was still holding on to copies it no longer needed. Dropping those was one of the changes that kept the valley running on my phone.

Drag the camera down toward the street to watch the area of full detail shrink. Then turn on Keep extra memory copies to see the phone before that fix. The memory figures are my estimates, not measurements.

How I stream and draw the valley

My offline bake turns the source data into terrain, 2,613 building chunks, 86,480 road segments, water layers, shop signs, and 44 transit routes. The OpenStreetMap extract for Nepal alone was about 415 MB going in. The 45 MB is the combined size of the baked files, before the production build repacks them into content-hashed packs.

  • Detail at a distance. Once the phone was streaming, I had to decide how far out full walls were worth drawing. I draw full building geometry within 700 m at street level and up to 2,200 m from high up, scaled by the quality setting. Rooftop clutter starts at 220 m from street level. I sort distant boxes by size within groups of chunks and draw fewer of them as they shrink, with a baseline cutoff of two pixels. A reversed depth buffer keeps surfaces from flickering across everything from kerbs to the distant Himalaya.
  • Memory after upload. Once three.js uploads static scenery to the GPU, I release JavaScript’s copies of the attributes nothing on the CPU reads again, such as normals and texture coordinates. I keep positions and indices for collision and picking, and use a raycast that only reads positions. When I was chasing the iPhone reloads, those duplicated arrays across landmarks, roads, and buildings added up to roughly 500 MB.
  • Work between frames. Web Workers build road and building geometry off the main thread and reuse scratch buffers. While the camera moves, I cap rooftop uploads at 1.5 MiB per frame. An iOS gesture guard stops double taps on the touch controls, like Jump and the pedals, from zooming the page.
How a smoother hill makes a smaller file

This one is about download size, not memory. Each terrain sample is a 16-bit number. On a steady slope the height changes at every step, but it changes predictably. So instead of storing each height, I predict it from the cells above and to the left and store only the error.

The predictor is height - left - above + topLeft. Zigzag encoding then maps errors of 0, −1, +1, −2, +2 to 0, 1, 2, 3, 4, so small errors in either direction stay small numbers. Last, I write all the low bytes first and all the high bytes after them. I call these byte planes. A small error has a high byte of zero, so the second plane turns into long runs of zeroes, which gzip compresses well. I ended up using byte planes for building data too.

On my November 29 city terrain grid, gzip at level 9 got the raw samples down to 5.64 MB. With the transform it got them to 2.56 MB, and the browser still recovers every sample exactly.

The figure runs the same steps on a kilometre of real elevation around Swayambhu, and your browser measures the gzip sizes live. Pick a step to see its bytes, and drag the line across the hill to read a different row. Turn on Random noise to see what happens when the hill stops being predictable.

SwayambhuRow 32/64
Six samples on row 32 → low plane | high planeZero high bytes · 98%
Low bytes (first 4 KiB)
125C00011C0C…
High bytes (second 4 KiB)
000000000000…
Blank cells are zeroestop: low · bottom: high

Gzip size for this patch

Uncompressed
8.0 KiB

Measuring gzip sizes…

The same bytes, reordered: all 4,096 low bytes first, then all 4,096 high bytes. The second half becomes one long run of zeroes, which gzip compresses well.

The supermarket faced the wrong road

The Bhat-Bhateni in Koteshwor faces the Ring Road. In one of my earlier builds, its entrance and signboard faced the local lanes behind the store.

When I dug in, I found my code was picking the front wall by its position in a list of edges. Any map rebuild that changed the order of those edges could move the entrance again. So I turned the fix into a check the agents could run. It looks outward from each wall and fails the build if an entrance faces a lane while a bigger road runs past another side.

Select either road on the map to move the striped storefront and see what my check would report.

Forty-eight landmarks I couldn’t keep checking by eye

The landmarks needed the same treatment. I modelled each one in code, then orbited it on a landmark gallery page to judge whether it felt right: whether Nyatapola’s five roofs sat in the right proportions, whether its stepped plinths climbed the way they do in Taumadhi Square.

Nyatapola’s five roofs and stepped plinths in Bhaktapur’s Taumadhi Square
Nyatapola’s five roofs and stepped plinths in Bhaktapur’s Taumadhi Square

That works for one temple, but not for 48 sites after every change an agent makes. So whenever I settled something by eye, I tried to write it down as a test. A test can tell me when a prayer flag stops fluttering, when a model gets too heavy to draw, or when the tip of Dharahara moves away from 72 metres.

What my build checks cover
  • Storefront check. For each eligible footprint edge, I sample straight out from three points, look for a road within reach, and compare road classes for shops. Hotels like Hotel Shanker are allowed to face their own driveway, so they get a longer search range and skip the road-class comparison.
  • Landmarks in code. All 48 landmarks are TypeScript meshes built from boxes, cylinders, extrusions, and similar shapes. Nyatapola’s five roofs, plinths, and guardians reuse my pagoda builder. The landmark test holds each one to at most six draw calls and fewer than 350,000 triangles. It also checks Dharahara’s height to within 20 cm, the prayer flag attributes, transfers to and from workers, and Boudhanath’s accelerated raycasts.
  • Visual review. The gallery page shows one landmark at a time with orbit controls and a night toggle, so I can look at each of the 48 in daylight and after dark. The launch trailer and several stills in this post came from a recorder that runs headless Chrome on a virtual clock, which lets it supersample every frame and add motion blur. The madal and flute in the soundtrack are procedural too.

The mountains disappeared

I spent hours making the Himalayan skyline visible beyond the valley’s green rim. A coarse terrain grid could flatten the peaks, so I sampled several heights inside each distant square and kept the highest. From a rooftop, I could finally see the snow behind the hills.

Then I looked at the skyline with live air quality turned on. It was November, the air quality index in the app read 114, and the haze swallowed the range I’d just finished drawing. I put a Preview clear air button in the time chip. It’s the most wishful control in the app.

Drag the divider over Bhaktapur to bring the peaks back. Switch to Boudha skies to compare daylight with the butter lamps at night.

How I use Kathmandu’s weather, air, and flights

My far terrain grid reaches about 100 km north. For each 250 m cell, I keep the highest of a 5 × 5 set of samples so the peaks don’t get flattened, and I give the distant range a little extra height in the scene.

The sun follows Kathmandu’s clock. I pull the weather and the air quality from Open-Meteo and map the reported concentration of fine particles (PM2.5) to the strength of the haze. I show the air quality index separately. Preview clear air turns that haze down.

Live flight positions come from adsb.lol, with OpenSky as a fallback. A Cloudflare Worker asks the edge to cache successful adsb.lol responses for eight seconds, so nearby requests can share them.

What I’d keep for the next city

Two weeks and 269 commits later, the things I’d do again are the boring ones. I’d write down the shared format before any agent builds on it, and split the work by area so the agents can run side by side. I’d fly the valley on my phone as often as on my laptop, so reloads show up early. And whenever I catch something wrong, like a supermarket facing the wrong road or a tower drifting from its real height, I’d turn it into a check so I only have to catch it once. The agents wrote the code, but deciding whether it looked like Kathmandu was my job the whole way through.

The Tiny Kathmandu project page has the stack and an overview of how the city runs in a browser.

Open Tiny Kathmandu, search for your neighbourhood in English or नेपाली, and see what you recognise. If there’s still a house standing in the Bagmati, tell me where.

Share