Skip to content

Easily create scalable, monetisable backend APIs with Hono + Cloudflare workers. All the batteries included.

License

Notifications You must be signed in to change notification settings

Dhravya/backend-api-kit

Repository files navigation

Backend API kit

Easily create scalable, monetisable backend APIs with Hono + Cloudflare workers

Why? While buildling supermemory, markdowner, reranker, i found myself solving all the same problems again and again - there's a lot of starter kits for frontend / full stack stuff, but almost none if you just want to build and monetise a small API.

Features

Getting set up

Quick Setup

  1. Clone & set up the repo
git clone https://github.com/dhravya/backend-api-kit.git
cd backend-api-kit
npm i -g bun
bun install
  1. Run the setup script
bun run setup

The setup script will:

  • Create a D1 database and configure it in wrangler.jsonc
  • Set up environment variables in .dev.vars
  • Run database migrations
  • Optionally deploy the worker

See guide for setting up lemonsqueezy

How to make changes to database schema

Writing and running tests

Changing ratelimits

If the quick setup script fails, you can manually set up the database and environment variables.

Development

Start the development server:

bun run dev

Now, write your business logic inside api

Congrats! You're all set for shipping your backend API!

Manual Setup

  1. Clone & set up the repo
git clone https://github.com/dhravya/backend-api-kit.git
cd backend-api-kit
npm i -g bun
bun install
  1. Create a D1 database
bunx wrangler d1 create <your-database-name>
  1. Update wrangler.jsonc with your database configuration
{
  // ... other config
  "d1_databases": [
    {
      "binding": "DATABASE",
      "database_name": "<your-database-name>",
      "database_id": "<your-database-id>",
      "migrations_dir": "./drizzle"
    }
  ]
}
  1. Set up environment variables
  • Copy .dev.vars.example to .dev.vars
  • Fill in the required environment variables:
    • AUTH_GITHUB_ID and AUTH_GITHUB_SECRET: GitHub OAuth credentials
    • BETTER_AUTH_URL: Your auth URL (default: http://localhost:8787)
    • SECRET: A secure random string
    • LEMONSQUEEZY_CHECKOUT_LINK: Your Lemonsqueezy checkout link
  1. Run database migrations
bunx drizzle-kit generate --name setup
bunx wrangler d1 migrations apply <your-database-name>
bunx wrangler d1 migrations apply <your-database-name> --remote
  1. Deploy (optional)
bunx wrangler deploy

License

This project is open-sourced under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a PR.

These are some things that contributions would be helpful for:

  • Adding or improving documentation
  • Adding or improving tests
  • More configurations (for eg, adding more auth providers, payment providers, database providers, etc)
  • Usage based pricing

Acknowledgements

This project is built thanks to these open source projects 🙏:

About

Easily create scalable, monetisable backend APIs with Hono + Cloudflare workers. All the batteries included.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •