# CodeWithDanko

Monorepo for a Remix + Cloudflare Workers template. Repo: https://github.com/dankopeng/codewithdanko

- Frontend Worker: `apps/web` (name: `codewithdanko`, domain: `codewithdanko.dankopeng.com`)
- Backend Worker: `apps/api` (name: `codewithdanko-api`)

## Architecture

- Two Workers: frontend (Remix) and backend (API). The frontend proxies `/api/*` to the backend via a Worker Service Binding `API -> codewithdanko-api`.
- Auth uses Authorization header Bearer tokens end-to-end. Session max age: 7 days.
- Storage: D1 (`codewithdanko-db`) and R2 (`codewithdanko-media`). Upload limit: 50MB.

## Dev

1. Install Node.js/npm (npm v10+ recommended)
2. Install deps: `npm install`
3. Login to Cloudflare: `npx wrangler login`
4. Configure environment
   - Backend `apps/api/wrangler.toml`:
     - Bind D1: `codewithdanko-db`
     - Bind R2: `codewithdanko-media`
     - Set `JWT_SECRET`
     - `UPLOAD_MAX_BYTES=52428800`
   - Frontend `apps/web/wrangler.json`:
     - Service binding `env.API` -> `codewithdanko-api`
     - `SESSION_MAX_AGE=604800` (7 days)
     - `UPLOAD_MAX_BYTES=52428800`

## Deploy

- Full deploy (backend + frontend): `npm run deploy`
- Dry run (both): `npm run deploy:dev`
- Individual:
  - Backend: `npm run deploy:backend` | dry run: `npm run deploy:backend:dev`
  - Frontend: `npm run deploy:frontend` | dry run: `npm run deploy:frontend:dev`

After first deploy, bind custom domain `codewithdanko.dankopeng.com` to the frontend Worker.

### Notes
- Frontend static assets are served from `apps/web/build/client` as configured in `apps/web/wrangler.json`.
- Production-only deployment for now. API base URL is provided via service binding, not CORS.

This repo uses npm workspaces (root `package.json`). The file `pnpm-workspace.yaml` is unused and can be ignored.