4import type { Place } from "../models/place-models.ts";
5import { processCheckinEvent as _processCheckinEvent } from "../ingestion/record-processor.ts";
6import { db } from "../database/db.ts";
7import { checkinsTable } from "../database/schema.ts";
8import { eq } from "https://esm.sh/drizzle-orm";
9import type { OAuthSessionsInterface } from "jsr:@tijs/atproto-oauth-hono@^0.2.6";
429 console.log(`โ
Created checkin record: ${checkinResult.uri}`);
430
431 // IMMEDIATELY save to local database for instant feed updates
432 try {
433 const rkey = extractRkey(checkinResult.uri);
443 },
444 });
445 console.log(`โ
Saved checkin to local database: ${rkey}`);
446 } catch (localSaveError) {
447 console.error(
448 "Failed to save checkin to local database:",
449 localSaveError,
450 );
198```
199โโโ backend/
200โ โโโ database/
201โ โ โโโ migrations.ts # Schema definitions
202โ โ โโโ queries.ts # DB query functions
257 ```
258
259### Database Patterns
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
27 isEmailAlreadyInvited,
28 isEmailAlreadyParticipant
29} from "../database/queries.ts";
30
31const api = new Hono();
274 }
275
276 // Add user message to database
277 const userMessage = await addMessage(currentConversationId, 'user', message);
278
305 }
306
307 // Add assistant message to database
308 const assistantMessage = await addMessage(currentConversationId, 'assistant', assistantResponse);
309
1# Backend
2
3Hono-based API server with LastLogin authentication, SQLite database, and group chat functionality.
4
5## Structure
6
7- `index.ts` - Main HTTP handler with LastLogin wrapper
8- `database/` - Database migrations and query functions
9- `routes/` - API route handlers
10
34- `GET /api/conversations/:id/stream` - Server-Sent Events for real-time updates
35
36## Database Schema
37
38### Core Tables
39- **Backend**: Hono, LastLogin auth, SQLite, OpenAI, Server-Sent Events
40- **Frontend**: React, TailwindCSS, Real-time SSE connections
41- **Database**: SQLite with participant and invitation tables
42
43## Getting Started
2import { lastlogin } from "https://esm.town/v/stevekrouse/lastlogin_safe";
3import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
4import { runMigrations } from "./database/migrations.ts";
5import api from "./routes/api.ts";
6
10app.onError((err) => Promise.reject(err));
11
12// Run database migrations on startup
13await runMigrations();
14
71 `);
72
73 console.log('Database migrations completed');
74}
90 // ---- Query Firestore publicLenses ----
91 const pubDocRes = await fetch(
92 `https://firestore.googleapis.com/v1/projects/${projectId}/databases/(default)/documents/publicLenses/${id}`,
93 { headers: { Authorization: `Bearer ${access_token}` } },
94 );
106 // ---- Query Firestore private user doc ----
107 const privDocRes = await fetch(
108 `https://firestore.googleapis.com/v1/projects/${projectId}/databases/(default)/documents/users/${owner}/lenses/${id}`,
109 { headers: { Authorization: `Bearer ${access_token}` } },
110 );
53- `POST /api/threads/:id/messages` - Send message and get AI response
54
55## Database Schema
56
57**Tables:**
11app.onError((err) => Promise.reject(err));
12
13// Initialize database tables
14async function initDatabase() {
15 // Create threads table
16 await sqlite.execute(`
37}
38
39// Initialize database on startup
40await initDatabase();
41
42// Serve static files