📦
Bunty

Quick Start

Build your first Bunty application in under 5 minutes.

Step 1: Create a New Project

Create a new Bunty project using Bun:

bun create bunty app
cd app

Step 2: Install Dependencies

Install the project dependencies:

bun install

Step 3: Create Your First Route

Create a simple HTTP server in src/index.ts:

import { createApp } from '@bunty/http';

const app = createApp();

app.get('/', (req, res) => {
  return res.json({ 
    message: 'Hello from Bunty!',
    timestamp: new Date().toISOString()
  });
});

app.get('/api/users', (req, res) => {
  const users = [
    { id: 1, name: 'Alice' },
    { id: 2, name: 'Bob' },
  ];
  return res.json(users);
});

app.listen(3000, () => {
  console.log('Server running on http://localhost:3000');
});

Step 4: Start the Development Server

Start your application:

bun run dev

Your server is now running at http://localhost:3000!

Step 5: Test Your API

Open your browser or use curl:

curl http://localhost:3000
curl http://localhost:3000/api/users

Optional: Add Database Support

If you want to work with a database, install the ORM package:

bun add @bunty/orm

Define a Table Schema

Bunty ORM focuses on productivity and type safety. Define tables with a fluent, type-safe API in src/db/schema.ts:

import { bunty } from "@bunty/orm/dialects/mysql/client/client";
import { bigint, varchar, enumerable } from "@bunty/orm/dialects/mysql/schema/column";

// Connect to your database
const db = bunty("mysql://root:password@localhost:3306/mydb");

// Define user status enum
export enum UserStatus {
    Active = "active",
    Inactive = "inactive",
    Pending = "pending"
}

// Define the users table with full type safety
export const usersTable = db.mysqlTable("users", {
    id: bigint("id", { size: 32 })
        .primaryKey()
        .notNullable()
        .autoIncrement()
        .unsigned(),
    
    email: varchar("email", { size: 128 })
        .notNullable(),
    
    password: varchar("password", { size: 128 })
        .notNullable()
        .hidden(), // Won't appear in queries by default
    
    firstName: varchar("firstName", { size: 32 })
        .nullable()
        .default(null),
    
    lastName: varchar("lastName", { size: 32 })
        .nullable()
        .default(null),
    
    status: enumerable("status", UserStatus)
        .notNullable()
        .default(UserStatus.Active),
})
.comment("User accounts table")
.charset("utf8mb4")
.collation("utf8mb4_general_ci")
.engine("InnoDB");

export { db };

Query Your Data

Use the type-safe query builder - all types are inferred automatically:

import { db, usersTable, UserStatus } from './db/schema';

app.get('/api/users', async (req, res) => {
    // Create a query builder - fully typed!
    const query = db.createQueryBuilder(usersTable);
    
    // Find all active users
    const users = await query
        .where('status', '=', UserStatus.Active)
        .findMany();
    
    return res.json(users);
});

app.post('/api/users', async (req, res) => {
    const query = db.createQueryBuilder(usersTable);
    
    // Insert new user - types are validated!
    const user = await query.insert({
        email: req.body.email,
        password: req.body.password,
        firstName: req.body.firstName,
        lastName: req.body.lastName,
        status: UserStatus.Active,
    });
    
    return res.json(user, 201);
});

app.get('/api/users/:id', async (req, res) => {
    const query = db.createQueryBuilder(usersTable);
    
    const user = await query
        .where('id', '=', req.params.id)
        .findOne();
    
    if (!user) {
        return res.json({ error: 'User not found' }, 404);
    }
    
    return res.json(user);
});

No decorators. No classes. Just pure type-safe functions. Your IDE will autocomplete everything - column names, types, and methods. Focus on building features, not fighting with types.

What’s Next?

Congratulations! You’ve just built your first Bunty application. Here are some next steps:

🎉 You’re All Set!

You’ve successfully created your first Bunty application. Remember, explore the packages and ecosystem to build powerful applications with ease!

Have questions? Join our Discord community
Found an issue? Edit this page on GitHub