···11+# CLAUDE.md
22+33+This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44+55+## Project Overview
66+77+Blento is a Bluesky-powered customizable bento grid website builder. Users authenticate via ATProto OAuth and can create personalized websites with draggable/resizable cards that are stored directly in their Bluesky PDS (Personal Data Server) using the `app.blento.card` collection.
88+99+## Commands
1010+1111+- `pnpm dev` - Start development server (Vite)
1212+- `pnpm build` - Build for production
1313+- `pnpm preview` - Build and preview with Wrangler (Cloudflare Workers)
1414+- `pnpm check` - Run svelte-check for type checking
1515+- `pnpm lint` - Run Prettier check and ESLint
1616+- `pnpm format` - Format code with Prettier
1717+- `pnpm deploy` - Build and deploy to Cloudflare Workers
1818+1919+## Architecture
2020+2121+### Tech Stack
2222+- **Framework**: SvelteKit 2 with Svelte 5 (using runes: `$state`, `$derived`, `$props`)
2323+- **Styling**: Tailwind CSS 4 with container queries (`@container`)
2424+- **Deployment**: Cloudflare Workers via `@sveltejs/adapter-cloudflare`
2525+- **UI Components**: `@foxui/core`, `@foxui/social` (custom component libraries)
2626+2727+### Grid System
2828+The site uses an 8-column grid layout (`COLUMNS = 8` in `src/lib/index.ts`). Each card has:
2929+- Desktop position/size: `x`, `y`, `w`, `h`
3030+- Mobile position/size: `mobileX`, `mobileY`, `mobileW`, `mobileH`
3131+3232+Grid margins: 20px desktop, 12px mobile.
3333+3434+### Key Components
3535+3636+**Website Rendering:**
3737+- `Website.svelte` - Read-only view of a user's bento grid
3838+- `EditableWebsite.svelte` - Full editing interface with drag-and-drop, card creation, and save functionality
3939+4040+**Card System (`src/lib/cards/`):**
4141+- `CardDefinition` type in `types.ts` defines the interface for card types
4242+- Each card type exports a definition with: `type`, `contentComponent`, `editingContentComponent`, optional `creationModalComponent`, `sidebarComponent`, `loadData`, `upload`
4343+- Card types: Text, Link, Image, Youtube, BlueskyPost, Embed, Map, Livestream, ATProtoCollections, Section
4444+- `AllCardDefinitions` and `CardDefinitionsByType` in `index.ts` aggregate all card types
4545+4646+**ATProto Integration (`src/lib/oauth/`):**
4747+- `auth.svelte.ts` - OAuth client state and login/logout flow using `@atcute/oauth-browser-client`
4848+- `atproto.ts` - ATProto API helpers: `resolveHandle`, `listRecords`, `getRecord`, `putRecord`, `deleteRecord`, `uploadImage`
4949+- Data is stored in user's PDS under collection `app.blento.card`
5050+5151+**Data Loading (`src/lib/website/`):**
5252+- `load.ts` - Fetches user data from their PDS, with Cloudflare KV caching (`USER_DATA_CACHE`)
5353+- `data.ts` - Defines which collections/records to fetch
5454+- `context.ts` - Svelte contexts for passing DID, handle, and data down the component tree
5555+5656+### Routes
5757+- `/` - Landing page
5858+- `/[handle]` - View a user's bento site (loads from their PDS)
5959+- `/[handle]/edit` - Edit mode for the user's site
6060+- `/edit` - Self-hosted edit mode
6161+- `/api/links` - Link preview API
6262+- `/api/geocoding` - Geocoding API for map cards
6363+6464+### Item Type
6565+Cards are represented by the `Item` type (`src/lib/types.ts`) with grid position, size, cardType, and cardData properties.
6666+6767+### Collision/Layout Helpers
6868+`src/lib/helper.ts` contains grid layout algorithms:
6969+- `fixCollisions` - Push cards down when they overlap
7070+- `compactItems` - Move cards up to fill gaps
7171+- `simulateFinalPosition` - Preview where a dragged card will land