Data Access Layer (DAL)
The DAL is the single point of contact between the application and the database. All database queries are encapsulated here.
Location
src/lib/dal/
Design Principles
- No direct Drizzle imports in routes or components — always go through DAL functions
- Functions return plain objects — no Drizzle query builders leak into application code
- Input validation happens at the API route level (via Zod schemas), not in the DAL
- Transactions are handled within DAL functions when multiple writes need to be atomic
Usage Example
// ✅ Correct — import from DAL
import { getOrderById, updateOrderStatus } from '@/lib/dal/orders';
// ❌ Wrong — never do this in routes/components
import { db } from '@/lib/db';
import { orders } from '@/lib/db/schema';
Available Modules
| Module | Responsibilities |
|---|---|
organisations.ts | CRUD for organisations, search, settings, portfolio, members |
orders.ts | Order lifecycle, status transitions, payment tracking |
offers.ts | Offer creation, withdrawal, acceptance |
requests.ts | Cake request creation, matching, expiry |
users.ts | User profiles, authentication records |
payments.ts | Payment records, earnings calculations, Stripe integration |
messages.ts | Message threads, read tracking |
reviews.ts | Review creation and retrieval |