15
16- **Backend**: TypeScript with Hono framework
17- **Database**: SQLite
18- **Frontend**: HTML, CSS, JavaScript with Bootstrap 5
19- **Authentication**: Session-based authentication
23```
24โโโ backend/
25โ โโโ database/
26โ โ โโโ migrations.ts # Database schema setup
27โ โ โโโ queries.ts # Database query functions
28โ โโโ routes/
29โ โ โโโ auth.ts # Authentication routes
44## Getting Started
45
461. The system will automatically set up the database on first run
472. Default admin credentials: admin@hospital.com / admin123
483. Access the system through the main HTTP endpoint
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 { getMessageTemplates, getContacts, getSettings } from "./database/queries.ts";
5import messages from "./routes/messages.ts";
6import scheduler from "./routes/scheduler.ts";
13});
14
15// Initialize database on startup
16await runMigrations();
17
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { ApiResponse } from "../../shared/types.ts";
3import { getPendingMessages, updateMessageStatus, createScheduledMessage } from "../database/queries.ts";
4import { generateWhatsAppUrl, getNextRecurrence } from "../../shared/utils.ts";
5
7 updateMessageStatus,
8 createOrUpdateContact
9} from "../database/queries.ts";
10import { formatPhoneNumber, validatePhoneNumber, isValidFutureDateTime, generateId } from "../../shared/utils.ts";
11
10
11export async function runMigrations() {
12 console.log('Running database migrations...');
13
14 // Scheduled Messages table
67 await insertDefaultSettings();
68
69 console.log('Database migrations completed');
70}
71
25- **Frontend**: React with TypeScript
26- **Backend**: Hono API framework
27- **Database**: SQLite for message storage
28- **Styling**: TailwindCSS
29- **Storage**: Local storage + server backup
34โโโ backend/
35โ โโโ index.ts # Main API server
36โ โโโ database/
37โ โ โโโ migrations.ts # Database schema
38โ โ โโโ queries.ts # Database operations
39โ โโโ routes/
40โ โโโ messages.ts # Message CRUD operations
95- **HTTP-Only Cookies**: Session cookies are not accessible via JavaScript
96- **Token Refresh**: Automatic refresh of expired access tokens
97- **Secure Storage**: Tokens are stored securely in the database
98
99## Troubleshooting
3## Description
4
5This is an AI-powered Grocery Shopping assistant that turns an imprecise list of items like "milk, bread, eggs" into a Kroger cart full of groceries. It relies on the Kroger API to search each item, then uses an LLM to decide which specific UPC to add to the cart (again, using the Kroger API). Once an item is selected, we store the UPC in the database so we can avoid consulting the LLM for that item again.
6
7Households have preferences for which items to buy, and what priorities they have for each item. For example, we prefer to buy free range eggs and poultry, but don't particularly care whether they are organic or not. These details are stored in a database, which should also be consulted to add context to the LLM's decisions.
8
9## Kroger OAuth Implementation
35- **User Management**: Create/update users based on Kroger profile ID
36
37## Database Schema
38
39The database consists of the following tables:
40
41### kroger_users_1
119โโโ backend/
120โ โโโ index.ts # Main HTTP handler with OAuth routes
121โ โโโ database/
122โ โ โโโ migrations.ts # Database schema setup
123โ โ โโโ krogerQueries.ts # Database query functions
124โ โโโ services/
125โ โโโ krogerAuth.ts # Kroger OAuth service
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);
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