App Structure
Smallweb apps follow a simple, convention-based structure. This guide explains the key files and directories.
Basic Structure
myapp/
├── main.ts # Entry point with fetch/run/email handlers
├── data/ # Persistent data storage (optional)
├── deno.json # Deno configuration (optional)
└── ... # Any other files your app needs
The main.ts File
The main.ts file exports handlers for different entry points:
export default {
// Handle HTTP requests
fetch: (request: Request) => {
return new Response("Hello!");
},
// Handle CLI commands (smallweb run myapp)
run: (args: string[]) => {
console.log("Running with args:", args);
},
// Handle incoming emails
email: (msg: ReadableStream) => {
console.log("Received email");
}
}
Static Files
If no main.ts exists, the directory is served as static files automatically.
The data/ Directory
Store persistent data in a data/ directory. This is a convention that keeps your data organized and separate from code.