DEV Community

Cover image for Building a Serverless Web Game With WebAssembly and Three.js
Samy Fodil
Samy Fodil

Posted on

Building a Serverless Web Game With WebAssembly and Three.js

In this tutorial, we'll build an online tower stacking game.

πŸ‘‰ Try the final result: Play Now

Taubyte - live demo

πŸ› οΈ Tech Stack

  • Frontend: Three.js + TypeScript
  • Backend: Go serverless functions on Taubyte
  • Local Dev: Dream (Taubyte's local cloud) + GitHub integration

⚑ Step 1: Run the Frontend Locally

Clone and run the game β€” at this stage, it has no leaderboard:

git clone https://github.com/taubyte/example-games-tower-blocks.git
cd example-games-tower-blocks

npm install
npm run dev
Enter fullscreen mode Exit fullscreen mode

Taubyte - npm install npm run dev

Open http://localhost:3000 β€” the game works, but scores aren't saved anywhere yet.

Taubyte - local game test

πŸ”§ Step 2: Start Taubyte Local Cloud (Dream)

Install Dream and start a local cloud instance:

npm install -g @taubyte/dream
dream new multiverse
Enter fullscreen mode Exit fullscreen mode

Keep this terminal open β€” it runs your local Taubyte cloud.

Taubyte - new local cloud

🌐 Step 3: Connect to Console

  1. Go to console.taubyte.com
  2. Log in with your email and GitHub

Taubyte - login

  1. From the dropdown, select Dream/blackhole (your local cloud).

Taubyte - login

πŸ–₯️ Step 4: Create Applications

Create and open a new project , this will create a code and a config repositories to save your project's data .

Taubyte - Applications

You'll need two apps:

  • frontend β†’ hosts the website
  • backend β†’ handles leaderboard logic

Taubyte - Applications

Frontend Setup

  1. Inside frontend app, add a Website resource
  • Name: tower_game
  • Repo: pick your GitHub fork (console fetches repos automatically)
  • Domain: use the default generated domain
  • Path: /

Taubyte - Website

  1. Push configuration to GitHub (green Push button).

Taubyte - push button

  1. In another terminal, trigger builds:
dream inject push-all
Enter fullscreen mode Exit fullscreen mode

Taubyte - dream inject push-all

trigger a build for the website specifically:

dream inject push-specific --rid <ID> --fn <FULL_NAME>
Enter fullscreen mode Exit fullscreen mode

Taubyte - id and fullname

Find rid and full_name in the YAML tab of the resource.

Taubyte - Yaml

  1. Add your Dream domain to /etc/hosts:
127.0.0.1 your-domain.blackhole.localtau
Enter fullscreen mode Exit fullscreen mode

Taubyte -

  1. In the console, click the ⚑ button on the website resource β†’ frontend should now load locally.

Taubyte -

Taubyte -

πŸ—„οΈ Step 5: Implement Backend

Create Database

Inside backend app, add a Database resource:

  • Name: leaderboard
  • Matcher: /leaderboard

Taubyte - database

Create Library

Add a Library resource:

  • Name: api_leaderboard
  • Language: Go (empty template)

Use this reference implementation:
The Library's Code

Taubyte - library

Taubyte - library repo

Create Functions

In the Functions tab, create:

  • getAll

    • Method: GET
    • Path: /api/leaderboard
    • Entry: getAll

Taubyte - function

  • get

    • Method: GET
    • Path: /api/score
    • Query param: player_name
    • Entry: get

Taubyte - function

  • set

    • Method: POST
    • Path: /api/score
    • Entry: set

Taubyte - function

πŸš€ Step 6: Deploy and Test

  1. Push builds:
dream inject push-all
Enter fullscreen mode Exit fullscreen mode

(Use push-specific for just the library if needed.)

  1. Wait for builds to complete in the Builds tab.
  1. Test each function by clicking the ⚑ button in the console β†’ you'll see live responses.

Taubyte - lightning function

🌍 Step 7: Push to Production

All that is left now is to push to production.

It's a really simple process:

  1. Log out of the local cloud's console.
  2. Make sure you already have a Taubyte cloud online set up.
  3. Log in using your email and domain name.
  4. Instead of creating a project like we did the first time, import the local project from GitHub. Select it from the dropdown and click Import.
  1. Open the imported project. Change the applications' local generated domain to a production one by toggling Generate Domain. Do this for both frontend and backend apps.

Taubyte - generate domain

  1. Push your changes β†’ this will trigger a config build.
  1. If your project has a Library or Website, you must register the resource with Auth before builds work. This can be done from the web console using the broken heart icon πŸ’” next to the resource.

Opening your game now in the production domain should work properly with all features up and running πŸŽ‰

βœ… Summary

You now have:

  • A frontend game hosted via Taubyte
  • A backend with a database + Go library
  • Three serverless functions powering a leaderboard

All running locally with Dream, and ready to deploy globally once you push to production.

πŸ“š Resources

Top comments (1)

Collapse
 
reynaldi profile image
reynaldi

I tried