fylepad-backend

July 9, 2026 · View on GitHub

The backend API for fylepad. Handles authentication, AI completions, note storage, image uploads, and collection management.

What It Does

  • Authentication — Google OAuth via Better Auth, with a special desktop callback flow for the Tauri app
  • AI Completions — proxies requests to AI models (e.g., Claude Haiku) through the Vercel AI SDK Gateway
  • Notes API — CRUD operations for notes with cloud sync and conflict handling
  • Collections API — organize notes into collections
  • Image Uploads — upload profile photos and note images to Cloudinary
  • Email — transactional emails via Resend

Tech Stack

  • Framework: Hono (lightweight, fast)
  • Database: Turso (libSQL / SQLite edge database)
  • ORM: Drizzle ORM
  • Auth: Better Auth with Drizzle adapter
  • AI: Vercel AI SDK + AI Gateway
  • Storage: Cloudinary (image uploads)
  • Email: Resend
  • Runtime: Node.js (also deployable to Vercel)

Prerequisites

  • Node.js ≥ 18
  • pnpm ≥ 10
  • Turso database
  • Cloudinary account
  • Google Cloud project with OAuth credentials
  • Resend API key

Setup

  1. Install dependencies

    pnpm install
    
  2. Create your .env file

    cp .env.example .env   # or create manually
    

    Fill in the required values:

    # AI
    AI_GATEWAY_API_KEY=your_ai_gateway_key
    
    # Auth
    BETTER_AUTH_SECRET=your_random_secret
    BETTER_AUTH_URL=http://localhost:3008
    GOOGLE_CLIENT_ID=your_google_client_id
    GOOGLE_CLIENT_SECRET=your_google_client_secret
    
    # Database
    TURSO_CONNECTION_URL=libsql://your-db.turso.io
    TURSO_AUTH_TOKEN=your_turso_token
    
    # Server
    PORT=3008
    
    # Cloudinary
    CLOUDINARY_CLOUD_NAME=your_cloud_name
    CLOUDINARY_API_KEY=your_api_key
    CLOUDINARY_API_SECRET=your_api_secret
    
    # Email
    RESEND_API_KEY=your_resend_key
    
  3. Run database migrations

    npx drizzle-kit push
    
  4. Start the dev server

    pnpm dev
    

    The server will start at http://localhost:3008.

API Routes

MethodPathDescription
GET/Health check
GET/POST/auth/*Better Auth routes (login, callback, session)
GET/meGet current user (requires auth)
POST/me/profileUpload profile photo (requires auth)
POST/api/completionAI text completion
*/api/notes/*Notes CRUD
*/api/collections/*Collections CRUD
*/api/uploads/*Image uploads

Build & Deploy

# Build
pnpm build

# Start production server
pnpm start

The app also exports a default Hono app for serverless deployment (e.g. Vercel).

Project Structure

src/
├── auth/       # Auth config, middleware, session helpers
├── db/         # Drizzle schema and database client
├── lib/        # Shared utilities (CORS, Cloudinary upload)
├── routes/     # API route handlers (ai, auth, notes, collections, uploads)
├── types/      # TypeScript types
├── utils/      # Constants and helpers
├── views/      # HTML templates (desktop OAuth page)
├── app.ts      # Hono app setup
└── index.ts    # Server entry point

migrations/     # Drizzle database migrations

License

MIT