|
|
@@ -31,11 +31,22 @@ npm run preview
|
|
|
|
|
|
# Sync SvelteKit config (auto-runs on `npm install`)
|
|
|
npm run prepare
|
|
|
+
|
|
|
+# Start production server (requires `npm run build` first)
|
|
|
+npm start
|
|
|
```
|
|
|
|
|
|
### No test/lint commands
|
|
|
This is a fresh project with no test suite or linter configured. Do not assume these exist.
|
|
|
|
|
|
+### Setup Prerequisites
|
|
|
+
|
|
|
+Before first dev/build run, **MUST copy configuration**:
|
|
|
+```bash
|
|
|
+cp config.json.example config.json
|
|
|
+```
|
|
|
+Database is auto-initialized on first run (creates `/data/app.db`, seeds admin user `admin@delete.me` / `deleteme`).
|
|
|
+
|
|
|
## Architecture & Key Files
|
|
|
|
|
|
### SvelteKit Project Structure
|
|
|
@@ -44,12 +55,18 @@ This is a fresh project with no test suite or linter configured. Do not assume t
|
|
|
src/
|
|
|
├── app.html # HTML shell (dark mode preset)
|
|
|
├── hooks.js # Paraglide i18n route localization
|
|
|
+├── hooks.server.js # Graceful shutdown, db cleanup, signal handlers
|
|
|
├── routes/
|
|
|
│ ├── +layout.svelte # Root layout component
|
|
|
│ ├── +page.svelte # Home page (Flowbite Alert, language switcher, dark mode toggle)
|
|
|
+│ ├── +error.svelte # Error page
|
|
|
│ └── layout.css # Route-level styles
|
|
|
└── lib/
|
|
|
- ├── index.js # $lib alias exports (currently empty)
|
|
|
+ ├── index.js # $lib alias exports
|
|
|
+ ├── config.js # Loads config.json (db & password settings)
|
|
|
+ ├── crypto.js # Argon2id hashing & verification (hashPassword, verifyPassword)
|
|
|
+ ├── sqlite3/
|
|
|
+ │ └── database.js # Database initialization, schema, admin user seeding
|
|
|
├── paraglide/ # i18n (auto-generated, DO NOT EDIT)
|
|
|
│ ├── messages.js # Locale-aware message functions
|
|
|
│ ├── runtime.js # getLocale(), setLocale(), deLocalizeUrl()
|
|
|
@@ -57,6 +74,14 @@ src/
|
|
|
└── assets/ # Static assets
|
|
|
```
|
|
|
|
|
|
+### Backend Infrastructure
|
|
|
+
|
|
|
+- **Configuration**: `config.json` (loaded by `src/lib/config.js`, must exist before runtime)
|
|
|
+- **Database**: SQLite3 (auto-initialized in `/data/app.db` on first run)
|
|
|
+- **Schema**: `users` table with `id`, `email`, `password` (hashed), `created_at`, `updated_at`
|
|
|
+- **Auth**: Argon2id password hashing via `src/lib/crypto.js`
|
|
|
+- **Admin User**: Auto-seeded if users table is empty (`admin@delete.me` / `deleteme`)
|
|
|
+
|
|
|
### Build Artifacts (gitignored)
|
|
|
|
|
|
- `.svelte-kit/` — SvelteKit type hints & config cache
|
|
|
@@ -103,10 +128,10 @@ runes: ({ filename }) =>
|
|
|
## Git & Workflow
|
|
|
|
|
|
- **Branch**: master
|
|
|
-- **Recent commits**: 5 commits total (initial + dark mode + i18n + documentation + icon fix)
|
|
|
-- **Status**: Clean working tree (no staged/unstaged changes)
|
|
|
+- **Recent commits**: 14 commits total (backend infrastructure: SQLite3, Argon2id, config management, graceful shutdown)
|
|
|
+- **Current state**: 6 files staged for commit (crypto, database setup, config changes)
|
|
|
|
|
|
-**Convention**: No established commit message convention yet. Keep it clear and atomic.
|
|
|
+**Convention**: Clear, atomic commits. Prefix context: "feat:", "fix:", "docs:", "refactor:" when possible.
|
|
|
|
|
|
## Known Issues & Observations
|
|
|
|
|
|
@@ -116,6 +141,8 @@ runes: ({ filename }) =>
|
|
|
|
|
|
3. **Minimal jsconfig**: Inherits TypeScript config from `.svelte-kit/tsconfig.json` but doesn't enforce type checking (`checkJs: false`)
|
|
|
|
|
|
+4. **Config must exist**: Application crashes at startup if `config.json` is missing. Always ensure it's copied from `config.json.example` before running dev/build.
|
|
|
+
|
|
|
## Common Agent Tasks & Gotchas
|
|
|
|
|
|
### Adding Components
|
|
|
@@ -142,6 +169,42 @@ runes: ({ filename }) =>
|
|
|
- Reference via `import { env } from '$env/dynamic/public'` or `$env/static/public`
|
|
|
- Prefix public vars with `VITE_` for client access
|
|
|
|
|
|
+## Database & Configuration
|
|
|
+
|
|
|
+### Configuration Loading (`src/lib/config.js`)
|
|
|
+
|
|
|
+The application loads `config.json` at startup. This must exist before running dev/build:
|
|
|
+
|
|
|
+```bash
|
|
|
+cp config.json.example config.json
|
|
|
+```
|
|
|
+
|
|
|
+**Failure mode**: If missing, the app crashes with `Failed to load config.json` error during `npm run dev` or `npm run build`.
|
|
|
+
|
|
|
+### Database Initialization (`src/lib/sqlite3/database.js`)
|
|
|
+
|
|
|
+- **Lazy initialization**: Database is created on first `getSqlite3()` call
|
|
|
+- **Schema**: `users` table auto-created with `id`, `email`, `password`, `created_at`, `updated_at`
|
|
|
+- **Admin seeding**: If no users exist, `admin@delete.me` / `deleteme` is inserted (hashed with Argon2id)
|
|
|
+- **Path**: `/data/app.db` (relative to project root, directory auto-created if missing)
|
|
|
+
|
|
|
+**Idempotent**: Safe to call multiple times; schema and admin user only created once.
|
|
|
+
|
|
|
+### Password Hashing (`src/lib/crypto.js`)
|
|
|
+
|
|
|
+Two exported functions:
|
|
|
+- `hashPassword(password)` — async, returns Argon2id hash (configured in `config.json`)
|
|
|
+- `verifyPassword(password, hash)` — async, returns boolean
|
|
|
+
|
|
|
+Use these for any user auth operations. Config pulls settings from `config.password.options`.
|
|
|
+
|
|
|
+### Graceful Shutdown (`src/hooks.server.js`)
|
|
|
+
|
|
|
+Database connection is properly closed on process termination (SIGTERM, SIGINT) or runtime errors. Exit codes:
|
|
|
+- `0` — Graceful shutdown (SIGTERM/SIGINT)
|
|
|
+- `1` — Uncaught exception or unhandled rejection
|
|
|
+- `2` — Cleanup error during shutdown
|
|
|
+
|
|
|
## Performance Notes
|
|
|
|
|
|
- Vite dev server is fast; rebuilds are near-instant
|
|
|
@@ -157,4 +220,4 @@ runes: ({ filename }) =>
|
|
|
|
|
|
---
|
|
|
|
|
|
-**Last Updated**: Verified against current project state (5 commits, i18n enabled, no typos, clean build)
|
|
|
+**Last Updated**: Verified against current project state (14 commits, backend infrastructure added, i18n enabled, clean build)
|