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
245 if (!response.ok) {
246 if (response.status === 404) {
247 return c.json({ error: "BIN not found in database" }, 404);
248 }
249 throw new Error(`BIN lookup service error: ${response.status}`);
294app.get("/api/marketplace/products", async c => {
295 try {
296 // In a real application, this would fetch from a database
297 const products = [
298 {
373 const id = c.req.param("id");
374
375 // In a real application, this would fetch from a database
376 const products = [
377 {
430 }
431
432 // In a real application, this would send an email or save to database
433 // For now, we'll just return success and redirect to Telegram
434
307 const pathParts = url.pathname.split("/").filter(p => p.trim() !== "");
308
309 // API endpoints - proxy to the main Shitty database
310 if (pathParts[0] === "api" && pathParts.length >= 2) {
311 const syncId = pathParts[1];
355 }
356
357 // Helper to get instance data from the main shitty database
358 async function getInstanceData(currentSyncId: string) {
359 // Return demo data for demo instance
12 listCachedPlants,
13 type PlantInfo,
14} from "./backend/database/cache.ts";
15
16const app = new Hono();
136 example: "/plant/rose",
137 testPage: "/ - Simple testing interface",
138 adminPage: "/admin - Cache database admin interface (requires login)",
139 loginPage: "/login - Admin login",
140 cache: cacheInfo,
147});
148
149// Admin page to view cache database - requires authentication
150app.get("/admin", requireAuth, async (c) => {
151 const html = await readFile("/admin.html", import.meta.url);
274});
275
276// Test database endpoint
277app.get("/test-db", async (c) => {
278 try {
279 console.log("Testing database connection...");
280
281 // Test basic SQLite functionality
296
297 return c.json({
298 message: "Database test successful",
299 testResult,
300 selectResult,
301 });
302 } catch (error) {
303 console.error("Database test failed:", error);
304 return c.json({
305 error: "Database test failed",
306 details: error instanceof Error ? error.message : "Unknown error",
307 }, 500);
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { GameState, Player, MoveRequest, GameResponse, GamesListResponse } from "../../shared/types.ts";
3import { createGame, getGame, updateGame, getRecentGames } from "../database/queries.ts";
4
5const app = new Hono();
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
3import { runMigrations } from "./database/migrations.ts";
4import gameRoutes from "./routes/game.ts";
5
11});
12
13// Initialize database
14await runMigrations();
15
16โโโ backend/
17โ โโโ index.ts # Main Hono server
18โ โโโ database/
19โ โ โโโ migrations.ts # Database schema
20โ โ โโโ queries.ts # Game queries
21โ โโโ routes/
1// Script to set up the telegram_chats table in SQLite
2// Run this script manually to create the database table
3
4export default async function setupTelegramChatDb() {
25 `);
26
27 return "Telegram chat database table created successfully.";
28 } catch (error) {
29 console.error("Error setting up telegram_chats table:", error);
13## Technical Architecture
14
15**โ ๏ธ important caveat: the admin dashboard doesn't have auth! currently it just relies on security by obscurity of people not knowing the url to a private val. this is not very secure. if you fork this project and put sensitive data in a database you should think carefully about how to secure it.**
16
17Stevens has been designed with the utmost simplicity and extensibility, much like a well-organized household. At the heart of his operation lies a single "memories" table - a digital equivalent of a butler's meticulous records. This table serves as the foundation for all of Stevens' operations.
45- `dashboard`: the admin view for showing the memories notebook + visualizing imports
46- `dailyBriefing`: stuff related to sending a daily update via telegram
47- `dbUtils`: little one-off scripts for database stuff
48
49## Hiring your own Stevens
57- For the Google Calendar integration you'll need `GOOGLE_CALENDAR_ACCOUNT_ID` and `GOOGLE_CALENDAR_CALENDAR_ID`. See [these instuctions](https://www.val.town/v/stevekrouse/pipedream) for details.
58
59**important caveat: the admin dashboard doesn't have auth! currently it just relies on security by obscurity of people not knowing the url to a private val. this is not very secure, if you put sensitive data in a database you should think carefully about how to secure it.**
60
61Overall it's a simple enough project that I encourage you to just copy the ideas and run in your own direction rather than try to use it as-is.
4
5* `index.ts` - this is the **entrypoint** for this whole project
6* `database/` - this contains the code for interfacing with the app's SQLite database table
7
8## Hono
26## CRUD API Routes
27
28This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
29
30## Errors