Emails
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.
Viewing readonly version of main branch: v81View latest version
The Webmail for Val Town application follows a serverless architecture within the Val Town platform, leveraging its HTTP and email trigger capabilities:
- Frontend: A simple HTML interface rendered by
webmail.tsfor displaying emails in an inbox format. - Backend: Two main scripts,
webmail.tsfor serving the web interface and fetching emails, andreciever.tsfor processing incoming emails via an email trigger. - Database: Utilizes Val Town's provided SQLite database for storing email data, accessed through Drizzle ORM for type-safe operations.
- Drizzle ORM Adoption: Chosen for database interactions to ensure type safety and maintainability over raw SQL queries.
- SQLite with LibSQL: Using
@libsql/clientwith Drizzle ORM to interact with SQLite in a way compatible with Val Town's environment. - Migration Approach: Opting for Drizzle's migration system to manage schema changes, pending user input on migration file setup.
- Separation of Concerns: Database schema is defined in
shared/db/schema.tsfor reuse acrosswebmail.tsandreciever.ts. - Type-Safe Queries: Leveraging Drizzle ORM's query builder to construct type-safe database operations, reducing runtime errors.
- Webmail Interface (
webmail.ts): Fetches email data from the SQLite database using Drizzle ORM and renders it as HTML. - Email Receiver (
reciever.ts): Captures incoming emails via Val Town's email trigger and inserts them into the database using Drizzle ORM. - Shared Schema (
shared/db/schema.ts): Defines the structure of the email table, ensuring consistency across different parts of the application.
- Email Fetching Flow: HTTP request ->
webmail.ts-> Drizzle ORM query -> SQLite database -> Render HTML with email data. - Email Reception Flow: Incoming email ->
reciever.ts(email trigger) -> Drizzle ORM insert -> SQLite database storage.