221aee06e20d9692e6ff3ccae3a30c4de1e19700
TalkCody Agent Marketplace API
The backend API service for TalkCody Agent Marketplace, built with Hono, Bun, and Drizzle ORM.
Tech Stack
- Runtime: Bun
- Framework: Hono
- Database: Neon (Serverless PostgreSQL)
- ORM: Drizzle
- Authentication: @hono/oauth-providers (GitHub, Google)
- Validation: Zod
- JWT: jose
Getting Started
Prerequisites
- Bun >= 1.0.0
- Neon PostgreSQL database (free tier available)
- GitHub OAuth App credentials
- Google OAuth App credentials
Setup
- Install dependencies:
bun install
- Copy environment variables:
cp .env.example .env
- Fill in your
.envfile with actual values:
DATABASE_URL=postgresql://user:password@host:5432/database
JWT_SECRET=your-secure-random-string
GITHUB_CLIENT_ID=your-github-app-id
GITHUB_CLIENT_SECRET=your-github-app-secret
GOOGLE_CLIENT_ID=your-google-app-id
GOOGLE_CLIENT_SECRET=your-google-app-secret
# Optional: explicit callback URL registered in Google Console
# Example: https://api.talkcody.com/api/auth/google
GOOGLE_REDIRECT_URI=
- Generate database migrations:
bun run db:generate
- Run migrations:
bun run db:migrate
- Seed the database with initial data:
bun run db:seed
Development
Run the development server with hot reload:
bun run dev
The API will be available at http://localhost:3000
Testing
Run tests:
bun test
Database Management
# Generate migrations from schema changes
bun run db:generate
# Run migrations
bun run db:migrate
# Push schema changes directly (dev only)
bun run db:push
# Open Drizzle Studio (database GUI)
bun run db:studio
# Seed database with initial data
bun run db:seed
Building for Production
Build for Bun runtime:
bun run build
Build for Cloudflare Workers:
bun run build:cloudflare
Deployment
Cloudflare Workers
- Install Wrangler CLI:
bun install -g wrangler
- Login to Cloudflare:
wrangler login
- Set environment variables:
wrangler secret put DATABASE_URL
wrangler secret put JWT_SECRET
wrangler secret put GITHUB_CLIENT_ID
wrangler secret put GITHUB_CLIENT_SECRET
wrangler secret put GOOGLE_CLIENT_ID
wrangler secret put GOOGLE_CLIENT_SECRET
- Deploy:
bun run deploy
Other Platforms (Railway, Fly.io, etc.)
Use the standard Bun deployment process for your platform.
API Endpoints
Health Check
GET /health- Health check and database status
Authentication
GET /api/auth/github- GitHub OAuthGET /api/auth/github/callback- GitHub OAuth callbackGET /api/auth/google- Google OAuthGET /api/auth/google/callback- Google OAuth callbackGET /api/auth/me- Get current user (requires auth)POST /api/auth/logout- Logout
Marketplace (Public)
GET /api/marketplace/agents- List agents (with filters)GET /api/marketplace/agents/featured- Featured agentsGET /api/marketplace/agents/:slug- Agent detailsGET /api/marketplace/agents/:slug/versions- Agent versionsGET /api/marketplace/agents/:slug/versions/:version- Version detailsPOST /api/marketplace/agents/:slug/download- Track downloadPOST /api/marketplace/agents/:slug/install- Track installGET /api/marketplace/categories- List categoriesGET /api/marketplace/tags- List tagsGET /api/marketplace/collections- List collectionsGET /api/marketplace/collections/:slug- Collection details
Agents (Requires Auth)
POST /api/agents- Publish new agentPUT /api/agents/:slug- Update agentDELETE /api/agents/:slug- Delete agentPOST /api/agents/:slug/versions- Publish new version
Users (Requires Auth)
GET /api/users/me/agents- Get my agentsGET /api/users/me/stats- Get my statistics
Project Structure
apps/api/
├── src/
│ ├── index.ts # Main application entry
│ ├── db/
│ │ ├── schema.ts # Database schema
│ │ ├── client.ts # Database connection
│ │ ├── migrate.ts # Migration script
│ │ ├── seed.ts # Seed script
│ │ └── migrations/ # Migration files
│ ├── routes/ # API routes
│ │ ├── auth.ts
│ │ ├── marketplace.ts
│ │ ├── agents.ts
│ │ └── users.ts
│ ├── services/ # Business logic
│ │ ├── agent-service.ts
│ │ ├── user-service.ts
│ │ ├── auth-service.ts
│ │ └── stats-service.ts
│ ├── middlewares/ # Middleware
│ │ ├── auth.ts
│ │ └── error-handler.ts
│ ├── lib/ # Utilities
│ │ ├── jwt.ts
│ │ └── utils.ts
│ └── types/ # Type definitions
│ ├── env.ts
│ └── context.ts
├── package.json
├── tsconfig.json
├── drizzle.config.ts
├── wrangler.toml
└── README.md
License
MIT
Description
Languages
TypeScript
95.3%
JavaScript
4.6%