Overview

The API server is built with Hono, running on Bun runtime. It handles wallet data, transaction parsing, and serves the web application.

Tech Stack

Technology Purpose
Hono Web framework (fast, lightweight)
Bun Runtime
Drizzle ORM Database access
Graphile Worker Background jobs
Pino Structured logging

Directory Structure

apps/api/
├── src/
│   ├── index.ts         # Entry point
│   ├── routes/          # API route handlers
│   │   ├── health.ts    # Health check
│   │   ├── wallets.ts   # Wallet endpoints
│   │   └── swaps.ts     # Swap endpoints
│   ├── middleware/      # Hono middleware
│   │   ├── auth.ts      # JWT verification
│   │   └── logging.ts   # Request logging
│   ├── services/        # Business logic
│   └── jobs/            # Background job handlers
└── tsconfig.json

Development

# Start API server
pnpm --filter @posit/api dev

# Run with watch mode
pnpm --filter @posit/api dev:watch

# Type check
pnpm --filter @posit/api typecheck

API Routes

Method Path Description
GET /health Health check
POST /wallets Add wallet to track
GET /wallets/:address/swaps Get wallet swaps
GET /wallets/:address/positions Get wallet positions
POST /wallets/:address/backfill Trigger backfill job

Authentication

The API uses JWT tokens from Privy for authentication. The auth middleware verifies tokens and attaches user context:

import { authMiddleware } from './middleware/auth';

app.use('/api/*', authMiddleware);

app.get('/api/me', (c) => {
  const user = c.get('user');
  return c.json({ wallet: user.walletAddress });
});

Background Jobs

Long-running tasks use Graphile Worker:

See also: API Reference for full endpoint documentation.