A modern, full-stack application for managing Cloudflare resources, built with Hono, Turso, and Clerk.
- 🔐 Authentication and organization management with Clerk
- 📊 Database management with Turso
- 🔄 Real-time synchronization with external services
- 🌐 Cloudflare Workers for serverless deployment
- 🪝 Webhook integration for real-time updates
- 🎨 Modern UI with shadcn/ui and Tailwind CSS
The application is structured as a monorepo with the following main components:
apps/
├── api/ # Main API server (Hono + Turso)
├── web/ # Web frontend (React + Vite)
└── webhook-worker/ # Webhook handler (Cloudflare Worker)
The API server is built with Hono and uses Turso for database management. Key features include:
- Database Management: Uses Turso for edge-optimized SQLite
- Authentication: Clerk integration for auth and org management
- Sync Services: Real-time data synchronization with external services
- Type Safety: Full TypeScript support with Zod validation
The application uses a hybrid approach with Turso:
- Schema Management: Drizzle ORM for type-safe schemas and migrations
- Database Operations: Raw libSQL for optimized queries
- Service Layer: Organized services for users, organizations, and members
Key database features:
- Type-safe schema definitions
- Automated migration management
- Edge-optimized performance
- Built-in connection retries and failover
The sync services maintain data consistency with external services:
- User Sync: Handles user creation, updates, and deletion
- Organization Sync: Manages organization data and memberships
- Retry Mechanism: Built-in retry with exponential backoff
- Error Handling: Comprehensive error categorization and logging
A dedicated Cloudflare Worker handles webhook events:
- Unified Handler: Single entry point for all webhook providers
- Request Validation: Secure webhook signature verification
- Payload Transformation: Standardized event format
- Error Handling: Proper error propagation and logging
- Node.js 18+
- pnpm
- Turso CLI
- Cloudflare account
- Clerk account
- Clone the repository:
git clone https://github.com/yourusername/admin-cloudflare.git
cd admin-cloudflare- Install dependencies:
pnpm install- Set up environment variables:
# apps/api/.dev.vars
ENVIRONMENT="development"
# Database
TURSO_DATABASE_URL="libsql://your-database.turso.io"
TURSO_AUTH_TOKEN="your-auth-token"
TURSO_ORG_GROUP="your-org"
TURSO_ORG_TOKEN="your-org-token"
# Clerk
CLERK_SECRET_KEY="sk_test_..."
CLERK_WEBHOOK_SECRET="whsec_..."
# Cloudflare
CLOUDFLARE_API_TOKEN=""
CLOUDFLARE_ACCOUNT_ID=""- Initialize the database:
cd apps/api
pnpm db:generate # Generate migrations
pnpm db:migrate # Apply migrations- Start the API server:
cd apps/api
pnpm dev # Runs on port 8787- Start the webhook worker:
cd apps/webhook-worker
pnpm tunnel # Start Cloudflare tunnel
pnpm dev # Runs on port 8788- Start the web application:
cd apps/web
pnpm dev # Runs on port 5173# Build all packages
pnpm build
# Build specific package
cd apps/api && pnpm buildAll API routes under /api/* are protected by Clerk authentication:
- Requires valid session token
- Access user context via
c.get('userId') - Access organization context via
c.get('organizationId')
The application provides several database services:
-
User Service
- User CRUD operations
- Profile management
- Role management
-
Organization Service
- Organization CRUD operations
- Member management
- Settings management
-
Member Service
- Member role management
- Access control
- Member synchronization
The webhook worker handles events from various services:
-
Current Endpoints
- Clerk:
/webhooks/clerk - More providers planned (Stripe, GitHub)
- Clerk:
-
Event Types
- User events (created, updated, deleted)
- Organization events (created, updated, deleted)
- Membership events (created, updated, deleted)
- Authentication: Clerk handles user authentication and session management
- Authorization: Role-based access control for organizations
- Webhook Security: Signature verification for all webhook endpoints
- Database Security: Secure connection handling and query validation
- Environment Security: Strict environment variable validation
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Hono - Fast, Lightweight, Web-standards
- Turso - Edge SQLite Database
- Clerk - Authentication & User Management
- Cloudflare Workers - Edge Computing Platform
- shadcn/ui - UI Components