diff --git a/docs/api-endpoints.md b/docs/api-endpoints.md new file mode 100644 index 0000000..3fe207f --- /dev/null +++ b/docs/api-endpoints.md @@ -0,0 +1,276 @@ +# API Endpoint Reference + +Base URL: `http://localhost:3000/api/v1` + +## Health Endpoints + +### GET /health + +Simple health check for load balancers. + +- **Auth:** None +- **Response:** `200 OK` + +```json +{ + "success": true, + "message": "OK", + "timestamp": "2025-01-15T10:30:00.000Z" +} +``` + +### GET /health/ready + +Readiness check with dependency probes. + +- **Auth:** None +- **Response:** `200 OK` or `503 Service Unavailable` + +```json +{ + "ready": true, + "timestamp": "2025-01-15T10:30:00.000Z", + "checks": [ + { "name": "database", "status": "ok", "latencyMs": 12 }, + { "name": "cache", "status": "ok" } + ] +} +``` + +### GET /health/detailed + +Full diagnostics including memory and system info. + +- **Auth:** None +- **Response:** `200 OK` + +```json +{ + "success": true, + "message": "Access Layer server is running", + "timestamp": "2025-01-15T10:30:00.000Z", + "version": "1.0.0", + "environment": "development", + "uptime": 12345.67, + "memory": { "used": 45.23, "total": 128.5 }, + "system": { "platform": "darwin", "nodeVersion": "v20.10.0" }, + "database": { "status": "connected", "responseTime": 12 }, + "services": [ + { "name": "API Server", "status": "healthy" }, + { "name": "Database", "status": "healthy" } + ] +} +``` + +--- + +## Auth Endpoints + +### POST /auth/login + +Authenticate a user. + +- **Auth:** None +- **Body:** + +```json +{ + "email": "user@example.com", + "password": "securepassword" +} +``` + +- **Response:** `200 OK` + +### POST /auth/register + +Register a new user. + +- **Auth:** None +- **Body:** + +```json +{ + "email": "user@example.com", + "password": "securepassword", + "name": "User Name" +} +``` + +- **Response:** `201 Created` + +--- + +## Config Endpoints + +### GET /config + +Get protocol bootstrap configuration. + +- **Auth:** None +- **Response:** `200 OK` + +```json +{ + "network": "testnet", + "contractAddress": "..." +} +``` + +--- + +## Creators Endpoints + +### GET /creators + +List all creators with pagination. + +- **Auth:** None +- **Query Params:** + - `page` (number, default: 1) + - `limit` (number, default: 10) +- **Response:** `200 OK` + +```json +{ + "creators": [...], + "pagination": { + "page": 1, + "limit": 10, + "total": 100 + } +} +``` + +### GET /creators/:id/stats + +Get public stats for a specific creator. + +- **Auth:** None +- **Response:** `200 OK` + +```json +{ + "creatorId": "...", + "totalSales": 150, + "totalEarnings": 12500.50 +} +``` + +--- + +## Creator Profile Endpoints + +### GET /creators/:creatorId/profile + +Get creator profile scaffold payload. + +- **Auth:** None +- **Response:** `200 OK` + +```json +{ + "creatorId": "...", + "displayName": "Creator Name", + "bio": "...", + "avatarUrl": "..." +} +``` + +### PUT /creators/:creatorId/profile + +Upsert creator profile. + +- **Auth:** Wallet ownership required +- **Headers:** + - `x-wallet-address: ` (must match creator) +- **Body:** + +```json +{ + "displayName": "New Name", + "bio": "Updated bio", + "avatarUrl": "https://..." +} +``` + +- **Response:** `200 OK` + +--- + +## Metrics Endpoints + +### GET /metrics/queues + +Queue depth metrics for indexer workers. + +- **Auth:** None +- **Response:** `200 OK` + +```json +{ + "queues": { + "indexer": { "depth": 42, "processing": 5 }, + "notifications": { "depth": 10, "processing": 2 } + } +} +``` + +--- + +## Admin Endpoints + +### PATCH /admin/creators/:id/metadata + +Update creator metadata. + +- **Auth:** Admin required +- **Body:** + +```json +{ + "metadata": { "key": "value" } +} +``` + +- **Response:** `200 OK` + +### POST /admin/indexer/replay + +Replay indexer events. + +- **Auth:** Admin required +- **Response:** `200 OK` + +--- + +## Common Headers + +| Header | Description | +|--------|-------------| +| `x-wallet-address` | Wallet address for ownership verification | +| `Authorization` | Bearer token for authenticated requests | +| `Content-Type` | `application/json` | + +## Error Responses + +```json +{ + "success": false, + "message": "Error description", + "error": "Detailed error (dev only)" +} +``` + +| Status | Description | +|--------|-------------| +| 400 | Bad request / validation error | +| 401 | Unauthorized | +| 403 | Forbidden | +| 404 | Not found | +| 429 | Rate limit exceeded | +| 500 | Internal server error | + +--- + +See [Local Setup](./local-setup.md) for development environment configuration. diff --git a/docs/local-setup.md b/docs/local-setup.md new file mode 100644 index 0000000..8b7c555 --- /dev/null +++ b/docs/local-setup.md @@ -0,0 +1,134 @@ +# Local Setup Guide + +This guide walks you through setting up the Access Layer server for local development. + +## Prerequisites + +- **Node.js** v20+ (check with `node --version`) +- **pnpm** v10+ (check with `pnpm --version`) +- **Docker** (for PostgreSQL database) + +## Step-by-Step Setup + +### 1. Clone the Repository + +```bash +git clone https://github.com/accesslayerorg/accesslayer-server.git +cd accesslayer-server +``` + +### 2. Install Dependencies + +```bash +pnpm install +``` + +### 3. Configure Environment Variables + +```bash +cp .env.example .env +``` + +Edit `.env` with your local configuration. The defaults work with the included Docker setup. + +### 4. Start the Database + +```bash +pnpm db:up +``` + +This starts a PostgreSQL container on port 5432. + +### 5. Generate Prisma Client + +```bash +pnpm generate +``` + +### 6. Run Database Migrations + +```bash +pnpm migrate +``` + +### 7. Start the Development Server + +**API Server:** +```bash +pnpm dev +``` + +The server starts on `http://localhost:3000`. + +**Indexer (if applicable):** +```bash +# Check package.json for indexer-specific scripts +pnpm start:indexer +``` + +## Verification + +### Health Check + +```bash +curl http://localhost:3000/api/v1/health +``` + +Expected response: +```json +{ + "success": true, + "message": "OK", + "timestamp": "2025-01-15T10:30:00.000Z" +} +``` + +### API Docs + +Open in browser: +``` +http://localhost:3000/api-docs +``` + +### Test Creator List + +```bash +curl http://localhost:3000/api/v1/creators +``` + +## Database Commands + +| Command | Description | +|---------|-------------| +| `pnpm db:up` | Start PostgreSQL container | +| `pnpm db:down` | Stop PostgreSQL container | +| `pnpm db:logs` | View database logs | +| `pnpm migrate` | Run migrations | +| `pnpm studio` | Open Prisma Studio | + +## Troubleshooting + +### Port Already in Use + +If port 3000 is occupied, update `PORT` in `.env`: +``` +PORT=3001 +``` + +### Database Connection Failed + +1. Ensure Docker is running: `docker ps` +2. Check if PostgreSQL container is up: `pnpm db:logs` +3. Verify `DATABASE_URL` in `.env` matches Docker defaults + +### Prisma Generation Failed + +```bash +rm -rf node_modules/.prisma +pnpm generate +``` + +## Next Steps + +- See [API Endpoints](./api-endpoints.md) for available routes +- Read [CONTRIBUTING.md](../CONTRIBUTING.md) for development workflow