|
1 | 1 | # listee-api |
2 | | -API server for Listee |
| 2 | + |
| 3 | +listee-api exposes Listee's HTTP interface. It packages `@listee/api` inside a Next.js App Router host so the CLI and web clients share the same business logic, validation, and database access. |
| 4 | + |
| 5 | +## Overview |
| 6 | +- Next.js 15 application that forwards requests to `createFetchHandler` from `@listee/api`. |
| 7 | +- Supabase supplies authentication (JWT) and the Postgres database. |
| 8 | +- Shared models and utilities come from the `@listee/*` packages (auth, db, types, api). |
| 9 | + |
| 10 | +## Architecture |
| 11 | +- `src/app/api/handler.ts` is the single hand-off into `@listee/api`. |
| 12 | +- `@listee/api` (Hono + Drizzle ORM) defines routes, validation, and service orchestration. |
| 13 | +- `@listee/db` provides Drizzle schema definitions and Postgres connection management. |
| 14 | +- Authentication is header-based via `@listee/auth`. |
| 15 | + |
| 16 | +## Environment Variables |
| 17 | +Configure these values in `.env.local` for development and in production: |
| 18 | +- `POSTGRES_URL` – Supabase Postgres connection string. |
| 19 | +- `SUPABASE_URL` – Supabase project base URL (e.g. `https://your-project.supabase.co`). |
| 20 | +- `SUPABASE_PUBLISHABLE_KEY` – Supabase publishable (anon) key used to call Auth endpoints. |
| 21 | +- `SUPABASE_JWT_AUDIENCE` – optional; audience value to enforce. |
| 22 | +- `SUPABASE_JWT_REQUIRED_ROLE` – optional; enforce a specific `role` claim (e.g. `authenticated`). |
| 23 | +- `SUPABASE_JWT_ISSUER` – optional; override the expected issuer. Defaults to `${SUPABASE_URL}/auth/v1`. |
| 24 | +- `SUPABASE_JWKS_PATH` – optional; override the JWKS endpoint path. Defaults to `/auth/v1/.well-known/jwks.json`. |
| 25 | +- `SUPABASE_JWT_CLOCK_TOLERANCE_SECONDS` – optional; non-negative integer clock skew tolerance. |
| 26 | + |
| 27 | +## Response Contract |
| 28 | +- Success responses always return JSON with a top-level `data` property. DELETE operations respond with `{ "data": null }`. |
| 29 | +- Error responses return `{ "error": "message" }` plus the appropriate HTTP status code (`400` validation, `401/403` auth, `404` missing resources, `500` unexpected failures). |
| 30 | + |
| 31 | +## API Surface |
| 32 | +| Method | Path | Description | |
| 33 | +| ------ | ---- | ----------- | |
| 34 | +| POST | `/api/auth/signup` | Forward email/password signups to Supabase Auth | |
| 35 | +| POST | `/api/auth/login` | Exchange email/password for Supabase access + refresh tokens | |
| 36 | +| POST | `/api/auth/token` | Refresh Supabase access tokens using a stored refresh token | |
| 37 | +| GET | `/api/users/:userId/categories` | List categories for the authenticated user | |
| 38 | +| POST | `/api/users/:userId/categories` | Create a new category | |
| 39 | +| GET | `/api/categories/:categoryId` | Fetch category details | |
| 40 | +| PATCH | `/api/categories/:categoryId` | Update a category name | |
| 41 | +| DELETE | `/api/categories/:categoryId` | Delete a category owned by the user | |
| 42 | +| GET | `/api/categories/:categoryId/tasks` | List tasks in a category | |
| 43 | +| POST | `/api/categories/:categoryId/tasks` | Create a task inside the category | |
| 44 | +| GET | `/api/tasks/:taskId` | Fetch task details | |
| 45 | +| PATCH | `/api/tasks/:taskId` | Update task name, description, or status | |
| 46 | +| DELETE | `/api/tasks/:taskId` | Delete a task owned by the user | |
| 47 | +| GET | `/api/healthz` | Database connectivity probe | |
| 48 | + |
| 49 | +All endpoints expect `Authorization: Bearer <token>` where `<token>` is a Supabase JWT access token issued for the authenticated user. |
| 50 | + |
| 51 | +## Local Development |
| 52 | +1. Install dependencies: `bun install`. |
| 53 | +2. Provide environment variables in `.env.local`. |
| 54 | +3. Run the dev server: `bun run dev` (Next.js on port 3000). |
| 55 | +4. Lint the project: `bun run lint`. |
| 56 | +5. Build for production verification: `bun run build`. |
| 57 | + |
| 58 | +### Database Migrations |
| 59 | +- Schema definitions live in `@listee/db`. Do not hand-edit generated SQL. |
| 60 | +- Generate migrations with `bun run db:generate` after schema changes. |
| 61 | +- Apply migrations with `bun run db:migrate` (uses `POSTGRES_URL`). |
| 62 | + |
| 63 | +## Testing |
| 64 | +Automated tests are not yet in place. Use CLI smoke tests (e.g. `listee categories update`, `listee tasks delete`) to verify JSON contracts until formal integration tests land. |
| 65 | + |
| 66 | +## Deployment Notes |
| 67 | +- `bun run build` produces the Next.js bundle for production. Deploy on Vercel or any Node 20+ platform capable of running Next.js 15. |
| 68 | +- Confirm environment variables for each target environment before deploy. |
| 69 | +- Monitor `/api/healthz` after rollout to confirm database access. |
| 70 | + |
| 71 | +## Conventions |
| 72 | +- Keep repository documentation and comments in English. |
| 73 | +- Follow Listee org standards: Bun 1.3.x, Biome linting, Drizzle migrations, and semantic versioning via Changesets when publishing packages. |
0 commit comments