This repository is a Cloudflare Workers-based temporary email service that provides disposable email addresses with attachment support. The service receives emails via Cloudflare Email Routing, stores them in D1 database, and provides REST API endpoints for managing emails and attachments.
- Type: Cloudflare Worker + Hono Framework
- Purpose: Temporary email service with attachment support
- Live API: https://api.barid.site
- Web Client: https://web.barid.site
- Runtime: Cloudflare Workers (Edge Computing)
- Package Manager: Bun
- Runtime: Cloudflare Workers (Edge Computing)
- Framework: Hono.js (Lightweight web framework)
- Language: TypeScript (ESNext target)
- Package Manager: Bun
- @hono/zod-openapi: OpenAPI documentation generation
- @hono/zod-validator: Request validation with Zod
- zod: Schema validation
- postal-mime: Email parsing
- html-to-text: HTML content conversion
- @paralleldrive/cuid2: Unique ID generation
- Biome: Code formatting and linting (configured with tabs, 100 char line width)
- TypeScript: Strict mode enabled
- Wrangler: Cloudflare Workers CLI
- Knip: Unused dependency detection
- D1 Database: SQLite database for email storage
- R2 Storage: Object storage for email attachments (up to 50MB)
- Email Routing: Email receiving service
- Scheduled Functions: Automated cleanup and reporting
src/
├── app.ts # Main Hono application setup
├── index.ts # Worker entry point (email, scheduled, fetch)
├── config/ # Configuration files
│ ├── constants.ts # Application constants (limits, types)
│ └── domains.ts # Supported email domains configuration
├── database/ # Database interaction modules
│ ├── d1.ts # D1 database operations
│ └── r2.ts # R2 storage operations
├── handlers/ # Event handlers
│ ├── emailHandler.ts # Email processing handler
│ └── scheduledHandler.ts # Scheduled task handlers
├── middlewares/ # Route middlewares
│ ├── cors.ts # CORS middleware
│ └── validateDomain.ts # Domain validation middleware
├── routes/ # API route definitions
│ ├── emailRoutes.ts # Email-related endpoints
│ ├── attachmentRoutes.ts # Attachment-related endpoints
│ └── healthRoutes.ts # Health check endpoint
├── schemas/ # Zod schemas for validation
│ ├── emails/ # Email-related schemas
│ └── attachments/ # Attachment-related schemas
└── utils/ # Utility functions
├── docs.ts # OpenAPI documentation setup
├── helpers.ts # Helper functions
├── http.ts # HTTP response utilities
├── logger.ts # Logging utilities (including Telegram)
├── mail.ts # Email processing utilities
├── performance.ts # Performance monitoring
└── telegram.ts # Telegram logging integration
sql/ # Database schema files
├── schema.sql # Database table definitions
└── indexes.sql # Database indexes
cloudflare-info/ # Cloudflare information utility
└── index.ts # Account info script
bun run dev- Start local development serverbun run deploy- Deploy to Cloudflare Workersbun run tail- View live logs from deployed worker
bun run db:create- Create D1 databasebun run db:tables- Apply database schemabun run db:indexes- Apply database indexes
bun run r2:create- Create R2 bucket for attachmentsbun run r2:create-preview- Create R2 preview bucket
bun run check- Run all linting and formatting checksbun run lint- Run Biome linterbun run lint:fix- Fix linting issues automaticallybun run format- Format code with Biomebun run tsc- Run TypeScript compilerbun run knip- Check for unused dependencies
bun run cf-info- Display Cloudflare account informationbun run cf-typegen- Generate TypeScript types for Cloudflare bindings
- Multiple Domains: Supports 9+ donated domains (barid.site, vwh.sh, etc.)
- Email Storage: Stores emails in D1 database with full content
- HTML Processing: Converts HTML emails to text with size limits
- Automatic Cleanup: Scheduled deletion of old emails (3-hour retention)
- File Size: Up to 50MB per attachment
- File Count: Up to 10 attachments per email
- Supported Types: Images, documents, archives, databases, and more
- Storage: Cloudflare R2 for reliable object storage
- RESTful API with OpenAPI documentation
- Email management (list, get, delete)
- Attachment handling (upload, download, delete)
- Health check endpoint
- Domain listing endpoint
- Telegram Integration: Optional Telegram bot logging
- Performance Monitoring: Built-in performance tracking
- Error Handling: Comprehensive error logging
- Observability: Cloudflare Workers observability enabled
- Separation of Concerns: Clear separation between routes, handlers, database, and utilities
- Dependency Injection: Cloudflare bindings injected via environment
- Schema-Driven: Zod schemas for request/response validation
- Edge Computing: Runs on Cloudflare's edge network
- Serverless: No server management required
- Multi-Service Integration: Uses D1, R2, Email Routing, and Scheduled Functions
- Environment-Based: Different configs for dev/preview/production
- Domain Configuration: Centralized domain management
- Constants: Application-wide constants for limits and settings
- Bun package manager
- Cloudflare account with Workers access
- Domain with Email Routing enabled
# Install dependencies
bun install
# Login to Cloudflare
bun wrangler login
# Set up database (update wrangler.jsonc with generated IDs)
bun run db:create
bun run db:tables
bun run db:indexes
# Set up storage
bun run r2:create
bun run r2:create-preview
# Run locally
bun run dev
# Deploy
bun run deployTELEGRAM_LOG_ENABLE: Enable/disable Telegram loggingHOURS_TO_DELETE_D1: Email retention period (default: 3 hours)TELEGRAM_BOT_TOKEN: Telegram bot token (secret)TELEGRAM_CHAT_ID: Telegram chat ID for logging (secret)
- D1: Database binding for email storage
- R2: Object storage for attachments
- Scheduled: Cron job triggers for cleanup
- Use
.dev.varsfor local development secrets - Update
wrangler.jsoncwith your Cloudflare resource IDs - Use Biome for consistent code formatting
- Leverage the extensive TypeScript types and schemas
- Indentation: Tabs, 2 spaces width
- Line Width: 100 characters maximum
- Quotes: Double quotes for strings
- Semicolons: Always used
- Brackets: K&R style (bracket on same line)
- Strict Mode: Enabled
- Module Resolution: Bundler-style
- Path Aliases:
@/*maps to./src/* - JSX: Uses Hono JSX with React-jsx transform
- Use Zod schemas for all input validation
- Leverage Cloudflare Workers' edge computing capabilities
- Implement proper error handling and logging
- Follow the established modular architecture
- Use TypeScript interfaces for type safety
This project follows modern Cloudflare Workers development patterns with a focus on performance, reliability, and maintainability.