HobenaKICoffee Backend
A TypeScript backend for HobenaKICoffee built with Bun, PostgreSQL, and Supabase.
A TypeScript backend for HobenaKICoffee built with Bun, PostgreSQL, and Supabase.
Tech Stack
- Runtime: Bun
- Database: PostgreSQL with Supabase
- Language: TypeScript (strict mode)
- Database Seeding: Snaplet Seed
- Package Manager: Bun
Getting Started
Prerequisites
- Bun installed
- PostgreSQL database (local or Supabase)
- Environment variables configured
Installation
# Install dependencies
bun install
# Copy environment template
cp .env.example .envEnvironment Setup
Create a .env file with the following variables:
SUPABASE_PROJECT_ID=your_project_id
SEED_DATABASE_URL=postgresql://user:pass@host:port/db
NEON_DATABASE_URL=postgresql://user:pass@host:port/dbDevelopment
# Start development server with hot reload
bun dev
# Run type checking
bun run typecheck
# Run linting with Ultracite
bun run lint
# Format code with Ultracite
bun x ultracite fix
# Clean build artifacts
bun run cleanSeeding
The project uses Snaplet Seed for database seeding with mock data.
# Initialize Snaplet seed configuration
bun run db:seed:init
# Sync seed configuration with database schema
bun run db:seed:sync
# Seed database with mock data (destructive!)
bun run db:seedDatabase Operations
Type Generation
# Generate types from local database
bun run supabase:gen:types:local
# Generate types from remote Supabase project
bun run supabase:gen:types:remoteDatabase Migration Workflow
Important: Use supabase db diff, Not Hand-Coding
Never hand-code migration files directly in supabase/migrations/. Instead:
- Make Changes: Edit schema files in
supabase/schemas/directory - Generate Migration: Run
supabase db diffto automatically create migration - Review Generated Migration: Check the generated migration file
- Apply Migration: Use
supabase db pushor your preferred deployment method
Schema File Organization:
supabase/schemas/: Contains schema definitions (edit these)supabase/migrations/: Contains auto-generated migrations (don't edit manually)
Project Structure
backend/
├── src/
│ └── types/ # Generated TypeScript types
├── supabase/
│ ├── migrations/ # Database migrations
│ ├── seeds/ # Seed data and constants
│ └── schemas/ # Database schemas
├── .github/prompts/ # Development guides and prompts
├── seed.ts # Database seeding script
├── seed.config.ts # Snaplet seed configuration
└── env.d.ts # Environment variable typesDatabase Schema
The project uses a coffee gifting/support platform schema with tables for:
profiles- User profilessupporters- People who support creatorstransactions- Financial transactionsactivities- User activities and eventscoffee_gifts- Coffee gift recordswallets- User wallet balances
Available Scripts
| Script | Description |
|---|---|
bun dev | Start development server with hot reload |
bun run typecheck | Run type checking |
bun run lint | Run linting with Ultracite |
bun x ultracite fix | Format code with Ultracite |
bun run clean | Clean build artifacts |
bun run db:seed:init | Initialize Snaplet seed configuration |
bun run db:seed:sync | Sync seed configuration with database schema |
bun run db:seed | Seed database with mock data |
bun run supabase:gen:types:local | Generate types from local database |
bun run supabase:gen:types:remote | Generate types from remote Supabase project |
Development Guidelines
- Always run
bun run typecheckandbun run lintbefore committing - Use
bun x ultracite fixto automatically fix formatting and linting issues - Follow the PostgreSQL style guide in
.github/prompts/postgres-sql-style-guide.prompt.md - Use snake_case for database tables and columns
- TypeScript strict mode is enabled
- No test framework is currently configured
API Development
When adding API endpoints:
- Create TypeScript types in
src/types/ - Update database schema if needed
- Generate new types:
bun run supabase:gen:types:local - Update seed data if required
Supabase
Necessary Supabase configuration for local development:
| Tool | URL |
|---|---|
| Studio | http://127.0.0.1:54323 |
| Mailpit | http://127.0.0.1:54324 |
| MCP | http://127.0.0.1:54321/mcp |
| API | URL |
|---|---|
| Project URL | http://127.0.0.1:54321 |
| REST | http://127.0.0.1:54321/rest/v1 |
| GraphQL | http://127.0.0.1:54321/graphql/v1 |
| Edge Functions | http://127.0.0.1:54321/functions/v1 |
Fill the other envs on the .env.local file as per your local Supabase setup. For more details, refer to the Supabase documentation.
For generating declarative database schema, follow this link: Supabase DB Schema Generation.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run type checking:
bun run typecheck - Submit a pull request
License
Private project - All rights reserved.