A local nutrition tracking app powered by AI
YuHeng uses an adapter pattern to support both SQLite and PostgreSQL databases. The appropriate adapter is automatically selected based on the DATABASE_URL environment variable.
The database layer is located in lib/db/:
interface.ts: Defines the IDatabaseAdapter interface.index.ts: Factory that selects and initializes the appropriate adapter.postgres.ts: PostgreSQL implementation of the adapter.sqlite.ts: SQLite implementation of the adapter.schema.ts: Drizzle schema shared between both databases.| Database | Connection String Format | Use Case |
|---|---|---|
| SQLite | file:/app/data/yuheng.db |
Single container, personal use, simple setup |
| PostgreSQL | postgresql://user:password@host:5432/yuheng |
Docker Compose, multi-user, scalable deployments |
db object, database-agnostic.YuHeng uses Drizzle Kit for database schema version management:
With PostgreSQL (Docker Compose):
docker compose up -d
bun run db:migrate
bun run dev
With SQLite:
# set in .env: DATABASE_URL=file:./data/yuheng.db
bun run db:migrate:sqlite
bun run dev
The application automatically connects using the connection string from .env.