NebulaKit Documentation
Single source of truth for setup, development, and deployment. This page is intentionally detailed so you can move from first run to production without guesswork.
Start Here
If this repo is being used as a template, first complete the customization workflow in
docs/INITIAL_CUSTOMIZATION.md. The current repository status file is still set
to
pending, which means template branding cleanup has not been finished yet.
- Create your repository from the template.
- Install dependencies and run the app locally.
- Apply database migrations locally.
- Configure OAuth and owner access through the setup flow.
- Run tests and coverage before shipping changes.
Quick Start
Then clone your repository, run the commands below, and open http://localhost:4277.
Bun is the recommended default for this repo. Switch to npm commands if your environment requires it.
terminal bun
# Install dependencies
$
bun install
# Start development server
$
bun run dev
# Apply local D1 migrations
$
bun run db:migrate:local
# Build for production
$
bun run build
# Type-check and tests
$
bun run check
$
bun run test
# Coverage report
$
bun run test:coverage
# Deploy to Cloudflare Pages
$
bun run deploy
What You Get Out of the Box
This starter already ships with the main product surfaces wired together. The fastest way to understand the repo is to think of it as a Cloudflare-first app shell with auth, theming, content management, and AI entry points already in place.
Core App Shell
- Keyboard-first navigation with command palette for fast route switching.
- Theme system with persistent light and dark preferences.
- Responsive layout, navigation, footer, and shared metadata components.
Account and Admin Flow
- Setup-first authentication flow for owner configuration.
- Login, signup, profile, reset, and admin routes are already scaffolded.
- Cloudflare D1 and KV are used for setup state and application data.
Content and AI Surfaces
- CMS-style content routes and admin tooling are included for structured content.
- Chat route becomes your primary AI surface once a provider is configured.
- Command palette can expose AI-related navigation when providers are available.
How To Use the App
Use the app in this order if you want the least confusing first run. That sequence matches how the repo is structured and avoids most setup-related false alarms.
- Open
/setupfirst on a fresh environment and configure owner credentials. - Complete
/setupbefore expecting sign-in or AI features to work. - Sign in through
/auth/loginor create an account through/auth/signup. - Open the command palette with Ctrl/Cmd + K to move between major routes quickly.
- Use
/chatfor AI interactions,/profilefor account settings, and/adminfor operator tasks. - Use the theme toggle to verify light and dark presentation while you customize branding.
Common First-Run Checks
- If auth looks broken, re-check setup lock state and provider credentials first.
- If chat is missing from navigation, verify AI provider configuration and route access.
- If admin tools are unavailable, confirm you are signed in as the configured owner.
Where To Extend
- Modify routes under
src/routeswhen changing page behavior. - Use
src/lib/componentsfor reusable UI and shell elements. - Keep business logic in
src/lib/servicesand shared helpers insrc/lib/utils.
Working With AI in This Repo
Treat AI as a fast pair programmer, not as a source of truth. It is useful here because the repo already includes app structure, tests, and strong conventions, which gives the assistant real context to work against.
Good Prompts
- Point the assistant at a concrete file, route, failing test, or command.
- Ask it to write or update tests first when changing behavior.
- Ask for narrow fixes instead of broad rewrites unless you want architectural change.
Good Validation Habits
- Have the assistant explain which route, store, or service controls the behavior.
- Require executable validation after changes, not only a diff summary.
- Always finish by running check, tests, and coverage.
What AI Is Best At Here
- Tracing a route from UI to service layer and identifying the smallest edit surface.
- Adding tests around setup, auth, chat, or command palette behavior.
- Summarizing repo conventions such as Cloudflare bindings, migrations, and theme rules.
If you are using an AI coding agent, keep requests concrete: mention the page or failing test, state the desired behavior, and ask for the smallest validating change that solves it.
Core Commands
These scripts are defined in package.json and are the canonical local workflow.
Development
npm run devruns on host 0.0.0.0, port 4277.npm run previewpreviews the production build on port 4277.npm run checkruns Svelte sync plus svelte-check.
Testing
npm run testruns Vitest in CI mode.npm run test:watchruns Vitest in watch mode.npm run test:e2eruns Playwright tests.npm run test:allruns unit tests, then E2E tests.
Deploy and Validation
npm run deploybuilds then deploys .svelte-kit/cloudflare.npm run validate:contrastchecks theme contrast.npm run validate:allruns check + test + contrast validation.
Cloudflare Bindings
NebulaKit is configured for Cloudflare Pages with these bindings in wrangler.toml:
DBas D1 database binding (database name: nebulakit-db).KVas KV namespace for runtime config and flags.BUCKETas R2 bucket binding.- Queue producer binding is documented but commented out by default.
Set app secrets in Cloudflare dashboard or Wrangler secrets for production. Avoid committing raw secrets to source control.
Database Migrations
Migrations are ordered SQL files under migrations/ and tracked by D1. Never edit
or delete existing migration files once committed to main.
# Apply pending migrations to local D1
npm run db:migrate:local
# Apply pending migrations to remote D1
npm run db:migrate
# List migration status
npm run db:migrate:list When schema changes are needed, create a new file with the next sequence number (for
example,
0006_add_feature_flag.sql) and use ALTER TABLE or new CREATE statements.
Authentication and Setup Flow
Auth uses @auth/sveltekit with a setup-first workflow. The main routes are
/setup, /auth/login, and /reset.
1. Configure
Open /setup and submit GitHub OAuth credentials plus admin GitHub username.
2. Lock Setup
After the admin logs in the first time, setup is locked to prevent accidental reconfiguration.
3. Reset When Needed
/reset clears setup-related KV keys and session cookie. Admins can disable reset
route access.
Testing and Quality Gates
NebulaKit follows Test-Driven Development. Write failing tests first, then implementation, then refactor.
# Run all tests
npm run test
# Run tests in watch mode
npm run test:watch
# Check coverage
npm run test:coverage
# Run E2E tests
npm run test:e2e
# Run all tests (unit + E2E)
npm run test:all Coverage guidance in repository docs is mixed: several files reference 90 percent, while AI assistant workflow instructions enforce 95 percent as a stricter floor. For new work, target 95 percent or higher to satisfy both interpretations safely.
Project Structure
NebulaKit/
├── .github/ # Copilot and workflow instructions
├── src/
│ ├── lib/
│ │ ├── components/ # Reusable UI components
│ │ ├── services/ # Business logic
│ │ ├── stores/ # Svelte stores
│ │ ├── types/ # Shared type definitions
│ │ └── utils/ # Helpers
│ ├── routes/ # SvelteKit routes
│ │ ├── api/ # API endpoints
│ │ ├── auth/ # Authentication pages
│ │ ├── chat/ # Chat UI
│ │ ├── setup/ # First-time setup flow
│ │ └── documentation/ # This page
│ ├── app.css # Global styles & theme
│ └── app.html # HTML template
├── tests/ # unit/integration/e2e tests
├── migrations/ # Immutable D1 migration files
├── docs/ # Extended project docs
└── wrangler.toml # Cloudflare bindings/configDeployment to Cloudflare Pages
- Push your repository to GitHub.
- In Cloudflare dashboard, open Pages and connect the repository.
- Use build command
npm run build. - Use output directory
.svelte-kit/cloudflare. - Add D1, KV, and R2 bindings to the Pages project settings.
- Add required environment variables and secrets.
- Deploy and verify auth, setup flow, and database connectivity.
The local deploy script already uses wrangler pages deploy .svelte-kit/cloudflare.
Troubleshooting
- If setup API reports KV unavailable, create KV namespaces and update wrangler.toml binding IDs.
- If login fails after setup, confirm OAuth callback URL and ensure GitHub credentials are valid.
- If migrations fail, run
npm run db:migrate:listand check migration numbering. - If command palette entries are missing, verify AI provider status and authentication state.
References
Contributing
Use TDD, keep changes small and reviewable, and run tests plus checks before opening a pull request.
- Write tests before implementation changes.
- Run npm run check, npm run test, and npm run test:coverage.
- Prefer Cloudflare-native services and minimal external dependencies.
- Do not edit past migration files; create a new one instead.