Discovering Bud: A Lightweight Full-Stack Framework

What is Bud?

Bud is a lightweight full-stack framework that starts minimalistic but can scale up when needed. It uses Go for the backend and Svelte for the frontend, leveraging the faster toolsets for their respective parts of the web stack. This approach allows developers to focus on building their application without unnecessary complexity.

Setting Up Bud

To get started with Bud, you’ll need to install it using the following command:

curl -sf https://raw.githubusercontent.com/livebud/bud/main/install.sh | sh

Once installed, create a new app using bud create first-app, and then run npm install to install all dependencies. Finally, start the development server using bud run, and your web app will be visible at localhost:3000.

Bud’s Folder Structure

When you examine your project, you’ll see the following structure:

  • controller: contains controller files that represent the backend routes of your app
  • view: contains Svelte files that auto-generate routes based on the file name
  • public: hosts static assets like images and CSS files
  • internal: ignored by the framework, making it a good place to host application-specific code

Creating the Root Page

To create the root page, you’ll need to create a controller folder and a file called controller.go. This will handle the endpoint /. For other controllers, you’ll create a folder with a similarly named Go file inside of it.

Delivering Data to Your View

The return value of a method that renders a view will be passed as a prop to the Svelte template. You can use this to send data from your Go method to your Svelte template.

// controller.go
package main

import (
    "livebud/bud"
)

func main() {
    bud.Get("/", func(ctx bud.Context) (interface{}, error) {
        return map[string]string{"message": "Hello, World!"}, nil
    })
}

<script>
  export let message;
</script>

<h1>{message}</h1>

How Bud Compares to Other Frameworks

Bud is still in its early stages, but it’s already showing promise. When compared to other frameworks like Ruby on Rails and Laravel, Bud has a more minimalistic approach. However, it still lacks some features, such as web sockets and channels. When compared to Next.js, Nuxt.js, and SvelteKit, Bud uses a more traditional approach to state management, relying on the backend to manage state.

Leave a Reply