179```
180โโโ backend/
181โ โโโ database/
182โ โ โโโ migrations.ts # Schema definitions
183โ โ โโโ queries.ts # DB query functions
239 ```
240
241### Database Patterns
242- Run migrations on startup or comment out for performance
243- Change table names when modifying schemas rather than altering
7It's currently super limited (no pagination, editing data, data-type specific viewers), and is just a couple dozens lines of code over a couple different vals. Forks encouraged! Just comment on the val if you add any features that you want to share.
8
9To use it on your own Val Town SQLite database, [fork it](https://www.val.town/v/stevekrouse/sqlite_admin/fork) to your account.
10
11It uses [basic authentication](https://www.val.town/v/pomdtr/basicAuth) with your [Val Town API Token](https://www.val.town/settings/api) as the password (leave the username field blank).
7It's currently super limited (no pagination, editing data, data-type specific viewers), and is just a couple dozens lines of code over a couple different vals. Forks encouraged! Just comment on the val if you add any features that you want to share.
8
9To use it on your own Val Town SQLite database, [fork it](https://www.val.town/v/stevekrouse/sqlite_admin/fork) to your account.
10
11It uses [basic authentication](https://www.val.town/v/pomdtr/basicAuth) with your [Val Town API Token](https://www.val.town/settings/api) as the password (leave the username field blank).
4- **No explicit test/lint commands** - Val Town platform handles these automatically
5- **Development**: Val Town auto-deploys on changes, no local build needed
6- **Database**: SQLite migrations run automatically on startup in backend/index.ts
7
8## Architecture
10- **Backend**: Hono API server (backend/index.ts) handling event management and check-ins
11- **Frontend**: React 18.2.0 with TypeScript (frontend/index.tsx, components/)
12- **Database**: SQLite with events_4, attendees_4, checkins_4, and sessions_2 tables
13- **Features**: Password-protected event creation, CSV attendee upload, fuzzy search, analytics
14- **Shared**: TypeScript types and utilities (shared/types.ts)
28- **Styling**: Default to TailwindCSS via CDN script tag
29- **Error Handling**: Let errors bubble up with context, avoid empty catch blocks
30- **Database**: Change table names (e.g., _3, _4) when modifying schemas instead of ALTER TABLE
31- **Platform**: Use Val Town utils for file operations (readFile, serveFile)
32- **SQLite**: ALWAYS handle query results properly - use `result.rows || result` pattern to access data
11 csrfMiddleware
12} from "./auth.ts";
13import { initDatabase, TABLES } from "./database.ts";
14
15const app = new Hono();
20});
21
22// Database table names imported from centralized schema
23
24// Initialize database on startup
25await initDatabase();
26console.log(`๐ [System] Event check-in system ready!`);
27
212 [eventId, name, passwordHash, location || null]
213 );
214 console.log(`โ
[API] Event successfully inserted into database with ID: ${eventId}`);
215 } catch (error) {
216 console.error(`๐ฅ [API] Failed to insert event:`, error);
247 const verifyAttendees = verifyAttendeesResult.rows || verifyAttendeesResult;
248 const actualAttendeeCount = Number(verifyAttendees[0]?.count || 0);
249 console.log(`๐ [API] Attendee verification: expected ${attendees.length}, found ${actualAttendeeCount} in database`);
250
251 console.log(`โ
[API] Successfully added ${insertedCount} attendees to event ${eventId}`);
2import { getCookie, setCookie, deleteCookie } from "https://esm.sh/hono@3.11.7/cookie";
3import type { Context } from "https://esm.sh/hono@3.11.7";
4import { TABLES } from "./database.ts";
5
6// Session configuration
8const SESSION_COOKIE_NAME = "session_token";
9
10// Database interfaces
11interface Session {
12 id: string;
20}
21
22// Note: Sessions table initialization moved to database.ts
23
24// Generate secure random string for session IDs and secrets
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { getAllPosts, getPostBySlug, getRecentPosts, getActiveFollowers, getFollowerCount, getPostActivityCounts } from "./database/queries.ts";
3import { initializeDatabase } from "./database/schema.ts";
4import { generateActorDocument } from "./services/activitypub.ts";
5import { generateRSSFeed } from "./services/rss.ts";
15});
16
17// Initialize database lazily on first request to avoid startup memory issues
18let dbInitialized = false;
19async function ensureDbInitialized() {
20 if (!dbInitialized) {
21 await initializeDatabase();
22 dbInitialized = true;
23 }
11
12/**
13 * Initialize database tables with memory optimization
14 */
15export async function initializeDatabase() {
16 // Prevent concurrent initialization
17 if (isInitializing || isInitialized) {
99
100 isInitialized = true;
101 console.log('Database initialized successfully');
102 } catch (error) {
103 console.error('Database initialization failed:', error);
104 throw error;
105 } finally {
28- [ ] Add validation for duplicate names (case-insensitive)
29
30### Database Schema
31- [ ] Add `allow_onsite_registration` column to events table (default false) (consider migrations carefully)
32- [ ] No changes to attendees or checkins tables required
43No external API keys required for basic functionality. Optional Discord integration available for future features.
44
45### Database
46
47The system uses SQLite with the following schema:
126- **Backend**: Hono (API framework)
127- **Frontend**: React 18.2.0 with TypeScript
128- **Database**: SQLite
129- **Styling**: TailwindCSS
130- **Platform**: Val Town (Deno runtime)