flixdb
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data β all from the browser, and deployed in milliseconds.
Hono-based API server that provides authentication and CRUD operations for notes and receipts using PocketBase.
The backend uses a generic CRUD factory pattern to eliminate code duplication between similar resources:
crud-factory.ts- Generic CRUD route factoryresource-configs.ts- Resource-specific configurations for notes and receiptsindex.ts- Main application setup and auth routes
POCKETBASE_URL- Your PocketBase instance URL
POST /api/auth/login- Login with email/passwordPOST /api/auth/logout- Logout (requires auth)GET /api/auth/me- Get current user info (requires auth)
GET /api/notes- Get all notes for authenticated userPOST /api/notes- Create a new notePUT /api/notes/:id- Update a noteDELETE /api/notes/:id- Delete a note (hard delete)
GET /api/receipts- Get all non-trashed receipts for authenticated userPOST /api/receipts- Create a new receiptPUT /api/receipts/:id- Update a receiptDELETE /api/receipts/:id- Delete a receipt (soft delete - sets trashed=true)
All resource endpoints require authentication via Bearer token in Authorization header.
To add a new resource type (e.g., tasks, bookmarks):
- Define the TypeScript types in
shared/types.ts - Create a resource configuration in
resource-configs.ts - Add the CRUD routes in
index.tsusingcreateCrudRoutes()
Example:
// In resource-configs.ts
export const tasksConfig: ResourceConfig<Task, CreateTaskRequest, UpdateTaskRequest> = {
collectionName: "tasks",
mapRecord: (record: any): Task => ({ /* mapping logic */ }),
createData: (req: CreateTaskRequest) => ({ /* create data */ }),
updateData: (req: UpdateTaskRequest) => ({ /* update data */ }),
};
// In index.ts
createCrudRoutes(app, "/tasks", tasksConfig, pb, requireAuth);
/- Serves the main HTML page/notes- Serves the notes page/receipts- Serves the receipts page/frontend/*- Serves frontend React components/shared/*- Serves shared TypeScript types