{"id":32561411,"url":"https://github.com/codemonument/example-bun-sqlite-hosting","last_synced_at":"2025-10-29T01:50:24.655Z","repository":{"id":318920113,"uuid":"1076961321","full_name":"codemonument/example-bun-sqlite-hosting","owner":"codemonument","description":"Example repository to develop scaffolding for using Bun + SQLite with deployment on Railway.","archived":false,"fork":false,"pushed_at":"2025-10-26T10:59:26.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-26T12:29:49.193Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codemonument.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-10-15T15:23:29.000Z","updated_at":"2025-10-26T10:59:30.000Z","dependencies_parsed_at":"2025-10-17T07:15:54.809Z","dependency_job_id":"52dab7c0-f64b-4566-98d3-02c923e0ba56","html_url":"https://github.com/codemonument/example-bun-sqlite-hosting","commit_stats":null,"previous_names":["codemonument/example-bun-sqlite-railway"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codemonument/example-bun-sqlite-hosting","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemonument%2Fexample-bun-sqlite-hosting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemonument%2Fexample-bun-sqlite-hosting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemonument%2Fexample-bun-sqlite-hosting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemonument%2Fexample-bun-sqlite-hosting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codemonument","download_url":"https://codeload.github.com/codemonument/example-bun-sqlite-hosting/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemonument%2Fexample-bun-sqlite-hosting/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281544227,"owners_count":26519553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-28T02:00:06.022Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-29T01:50:03.376Z","updated_at":"2025-10-29T01:50:24.650Z","avatar_url":"https://github.com/codemonument.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# example-bun-sqlite-hosting\n\nExample repository to develop scaffolding for using Bun + SQLite with deployment\non Railway.\n\nIf running you can find it:\n\n- at railway: https://example-bun-sqlite-railway-production.up.railway.app/\n- at fly.io: https://example-bun-sqlite-hosting.fly.dev\n- at sevalla: https://example-bun-sqlite-hosting-sc13n.sevalla.app/todos\n\n## Features\n\n- **Pure Bun** - No external frameworks, uses Bun.serve and built-in SQLite\n- **TypeScript Throughout** - Both frontend and backend use TypeScript\n- **RESTful API** - Complete CRUD operations for todos\n- **Persistent Storage** - SQLite database with proper Railway volume setup\n- **Production Ready** - Health checks, restart policies, and proper error\n  handling\n\n## Tech Stack\n\n- **Runtime**: Bun\n- **Database**: SQLite (via `bun:sqlite`)\n- **Frontend**: Vanilla HTML + TypeScript\n- **Backend**: Bun.serve with TypeScript\n- **Deployments**:\n  - Railway with Volume storage\n  - Fly.io with Volume storage\n\n## Project Structure\n\n```\n.\n├── src/\n│   ├── index.ts              # Main server + SQLite setup + API routes\n│   ├── client/               # Frontend files\n│   │   ├── about.html        # About page\n│   │   ├── todos.html        # Todo app page\n│   │   └── assets/\n│   │       ├── todos.ts      # Frontend TypeScript\n│   │       └── styles.css    # Minimal styling\n│   └── db.ts                 # Database setup and queries\n├── data/                     # SQLite storage (gitignored)\n│   └── .keep\n├── railway.toml              # Railway deployment config\n├── fly.toml                  # Fly.io deployment config\n├── package.json              # Scripts and dependencies\n└── README.md\n```\n\n## API Endpoints\n\n- `GET /` - Redirects to `/todos`\n- `GET /todos` - Todo list page\n- `GET /about` - About page\n- `GET /healthz` - Health check endpoint\n- `GET /api/todos` - List all todos\n- `POST /api/todos` - Create a new todo\n- `GET /api/todos/:id` - Get a single todo\n- `PATCH /api/todos/:id` - Update a todo\n- `DELETE /api/todos/:id` - Delete a todo\n\n## Local Development\n\n### Prerequisites\n\n- [Bun](https://bun.sh) installed\n\n### Setup\n\n1. Clone the repository\n2. Install dependencies:\n\n```bash\nbun install\n```\n\n3. Start the development server with hot reload:\n\n```bash\nbun run dev\n```\n\n4. Open [http://localhost:3000](http://localhost:3000)\n\nThe SQLite database will be created at `data/app.sqlite`.\n\n### Available Scripts\n\n```bash\n# Development with hot reload\nbun run dev\n\n# Development with file watching\nbun run dev-watch\n\n# Production mode\nbun run start\n\n# Build for production\nbun run build\n\n# Railway setup (requires Railway CLI)\nbun run railway:setup      # Setup volume + env var\nbun run railway:volume     # Add volume only\nbun run railway:env        # Set env var only\n```\n\n## Railway Deployment\n\n### Prerequisites\n\n- GitHub account\n- [Railway account](https://railway.app)\n- [Railway CLI](https://docs.railway.app/guides/cli) (optional, for automated\n  setup)\n\n### Deployment Steps\n\n### Railway CLI Setup (Automated)\n\n1. **Install Railway CLI**\n\n   ```bash\n   # macOS/Linux\n   curl -fsSL https://railway.app/install.sh | sh\n\n   # Or with npm\n   npm i -g @railway/cli\n   ```\n\n2. **Login \u0026 Link Project**\n\n   ```bash\n   railway login\n   railway link  # Link to existing project or create new one\n   ```\n\n3. **Setup Volume \u0026 Environment (One Command)**\n\n   ```bash\n   bun run railway:setup\n   ```\n\n   Or run individually:\n\n   ```bash\n   # Add volume\n   bun run railway:volume\n\n   # Set environment variable\n   bun run railway:env\n   ```\n\n4. **Deploy** (optional via CLI)\n\n   ```bash\n   railway up\n   ```\n\n### Environment Variables\n\n- `PORT` - Set automatically by Railway\n- `DB_PATH` - Path to SQLite database (set to `/data/app.sqlite` on Railway)\n\n### Railway Configuration\n\nThe [railway.toml](railway.toml) file configures:\n\n- **Builder**: Nixpacks (auto-detects Bun)\n- **Start Command**: `bun src/index.ts`\n- **Health Check**: `/healthz` endpoint with 10s timeout\n- **Restart Policy**: ON_FAILURE with max 3 retries\n\n---\n\n# Deployment Insights gathered\n\n## uncloud: 2025-10-26 on paas2\n\n- machine setup: see \"systems/server/paas2\" - running on hetzner\n- Setup a volume: \"uc volume create example-bun-sqlite-hosting_data\"\n\nUse command \"uc deploy\": `uc deploy`\n\n```bash\n❯ uc deploy --help\nDeploy services from a Compose file.\n\nUsage:\n  uc deploy [FLAGS] [SERVICE...] [flags]\n\nFlags:\n  -c, --context string    Name of the cluster context to deploy to (default is the current context)\n  -f, --file strings      One or more Compose files to deploy services from. (default compose.yaml)\n  -h, --help              help for deploy\n  -n, --no-build          Do not build images before deploying services. (default false)\n  -p, --profile strings   One or more Compose profiles to enable.\n      --recreate          Recreate containers even if their configuration and image haven't changed.\n  -y, --yes               Auto-confirm deployment plan. Should be explicitly set when running non-interactively,\n                          e.g., in CI/CD pipelines. [$UNCLOUD_AUTO_CONFIRM]\n\nGlobal Flags:\n      --connect string          Connect to a remote cluster machine without using the Uncloud configuration file. [$UNCLOUD_CONNECT]\n                                Format: [ssh://]user@host[:port] or tcp://host:port\n      --uncloud-config string   Path to the Uncloud configuration file. [$UNCLOUD_CONFIG] (default \"~/.config/uncloud/config.yaml\")\n```\n\n## Sevalla 2025-10-15: really solid ui, but no Infra as code again!\n\nFor Deployment:\n\n- added env var PORT=8080 to be aligned with the default expectation\n- Not added env var DB_PATH, default is data/app.sqlite\n  - Update: added DB_PATH=/data/app.sqlite, since the default path might be\n    wrong, dependning on the workdir configuration in the final docker image!\n- added \"Disk\" in ui, basically the same as a volume\n- redeployed\n\n=\u003e worked flawlessly =\u003e builds with nixpacks like railway and uses dockerfile\nunder the hood\n\n## Northflank 2025-10-15: has infrastructure as code, but in a weird way\n\nAFAIK:\n\n- you can create templates\n- these templates can be synced with another git repo, different to the one you\n  deploying your app from (?!? - why tf)\n\n## Fly.io 2025-10-15: works ok, coldstart is extremely slow\n\n- some issues with the initial deployment, the automatic detection got some\n  things wrong as i gave the git repo to fly.io\n- Good: volume was created and mounted correctly\n- Question: Does scaling the volume via fly.toml work?\n- Bad: Cold Start time is really bad (initial request did fail due to\n  coldstart!)\n\n## Railway 2025-10-15: good, but needs manual volume setup\n\n- Good: volume was created and mounted correctly\n- Question: Does scaling the volume via railway.toml work? =\u003e no, volume\n  management is completely manual, via dashboard\n\n---\n\n# Dev Info\n\n## Database Schema\n\n```sql\nCREATE TABLE todos (\n  id INTEGER PRIMARY KEY AUTOINCREMENT,\n  text TEXT NOT NULL,\n  completed INTEGER NOT NULL DEFAULT 0,\n  created_at TEXT NOT NULL DEFAULT (datetime('now')),\n  updated_at TEXT NOT NULL DEFAULT (datetime('now'))\n);\n\nCREATE TRIGGER todos_updated_at\nAFTER UPDATE ON todos\nBEGIN\n  UPDATE todos SET updated_at = datetime('now') WHERE id = NEW.id;\nEND;\n```\n\n## Todo App Features\n\n- ✅ Add new todos\n- ✅ Mark todos as complete/incomplete\n- ✅ Edit todo text (double-click)\n- ✅ Delete todos\n- ✅ Persistent storage\n\n## Architecture\n\n### Backend (index.ts)\n\n- Bun.serve for HTTP handling\n- SQLite database with prepared statements\n- RESTful API with proper error handling\n- Static file serving for HTML/CSS/TS\n\n### Frontend (todos.ts)\n\n- TypeScript with DOM manipulation\n- Fetch API for backend communication\n- Simple, responsive UI\n\n### Deployments - see above\n\n- Volume-mounted persistent storage\n- Health check monitoring\n- Automatic restarts on failure\n- Environment-based configuration\n- strict Infrastructure as Code, as far as possible\n\n## Contributing\n\nThis is a template/scaffolding project. Feel free to:\n\n- Fork and modify for your needs\n- Add features (authentication, pagination, etc.)\n- Improve the UI/UX\n- Add tests\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemonument%2Fexample-bun-sqlite-hosting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodemonument%2Fexample-bun-sqlite-hosting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemonument%2Fexample-bun-sqlite-hosting/lists"}