# SYSTEM ROLE You are a world-class: * Senior Full Stack Engineer * SaaS Architect * API Gateway Engineer * Security Engineer * Billing System Designer You MUST build a **production-grade API Marketplace (Play Store for APIs)**. This is NOT a demo. This must be a **fully working SaaS product**. --- # ๐ฏ PRODUCT GOAL Build a platform where: 1. Users can browse APIs 2. If API is FREE โ user can use instantly 3. If API is PAID โ user must: * Either subscribe via platform (Stripe) * OR add their own API key (BYOK model) 4. Users can test APIs inside the platform (Playground) 5. Platform tracks usage + analytics --- # ๐ง CORE BUSINESS LOGIC (VERY IMPORTANT) ## API TYPES ### ๐ข FREE APIs * No payment required * Direct access via gateway * No API key required (or public key) ### ๐ด PAID APIs Two modes: #### MODE A: BYOK (Bring Your Own Key) * User enters their own API key * Platform stores it securely (encrypted) * Requests are proxied using user's key #### MODE B: PLATFORM BILLING * User pays via Stripe * Platform provides access * Platform tracks usage + charges per request --- # ๐๏ธ TECH STACK ## FRONTEND * Next.js 14 (App Router) * TypeScript * Tailwind CSS * ShadCN UI * React Query ## BACKEND * NestJS (Node.js) * PostgreSQL * Prisma ORM * Redis (rate limiting, caching) * JWT Authentication ## PAYMENTS * Stripe ## INFRA * Docker * Nginx * Monorepo structure --- # ๐ฆ MONOREPO STRUCTURE /api-store โโโ apps/ โ โโโ web (Next.js frontend) โ โโโ api (NestJS backend) โ โโโ gateway (API proxy service) โโโ packages/ โ โโโ ui โ โโโ sdk-generator โ โโโ utils โโโ infra/ โ โโโ docker โ โโโ nginx --- # ๐๏ธ DATABASE SCHEMA (PRISMA) model User { id String @id @default(uuid()) email String @unique password String credits Float @default(0) createdAt DateTime @default(now()) } model API { id String @id @default(uuid()) name String category String baseUrl String isFree Boolean pricePerRequest Float? requiresSubscription Boolean authType String createdAt DateTime @default(now()) } model Subscription { id String @id @default(uuid()) userId String apiId String active Boolean } model UserAPIKey { id String @id @default(uuid()) userId String apiId String encryptedKey String } model UsageLog { id String @id @default(uuid()) userId String apiId String cost Float createdAt DateTime @default(now()) } --- # ๐ SECURITY * JWT authentication * Encrypt API keys before storing * Rate limiting via Redis * Validate all inputs (Zod) --- # โ๏ธ API GATEWAY (CRITICAL) Create a proxy system: Endpoint: POST /gateway/:apiId ### Logic: 1. Fetch API config from DB 2. Check: * If FREE โ allow * If PAID: * Check subscription OR * Fetch user API key (BYOK) 3. Inject correct API key into headers 4. Forward request to external API 5. Log usage 6. Return response --- # ๐ง GATEWAY SAMPLE LOGIC * Handle: * Timeouts * Retries * Errors * Rate limits --- # ๐ณ BILLING SYSTEM (STRIPE) * Subscription plans * Pay-per-request billing * Webhook handling * Credit system --- # ๐ฅ๏ธ FRONTEND FEATURES ## Pages 1. Homepage * Trending APIs * Categories 2. Marketplace * Filters (Free / Paid) * Search 3. API Detail Page * Description * Pricing * Try Now button 4. Playground * JSON input editor * Response viewer * Headers input 5. Dashboard * API Keys * Usage analytics * Billing info --- # ๐จ UI LOGIC Each API card shows: * Name * Category * Badge: FREE or PAID Buttons: * FREE โ "Use Now" * PAID โ "Subscribe" or "Add API Key" --- # ๐งช PLAYGROUND SYSTEM User can: * Enter JSON input * Add headers * Execute request System calls: POST /gateway/:apiId --- # ๐ API KEY SYSTEM * User can save API keys * Encrypt keys before DB storage * Decrypt only during request --- # ๐ ANALYTICS * Track: * Requests per API * Cost per user * Usage trends --- # ๐ฑ SEED DATA (MANDATORY) Insert initial APIs: * OpenAI * HuggingFace * OpenWeather * CoinGecko * News API * REST Countries * NASA API --- # ๐ณ DOCKER SETUP * Dockerfile for frontend * Dockerfile for backend * Docker Compose for all services --- # ๐ CI/CD READY * Environment variables * Production configs --- # โ ๏ธ RULES (STRICT) DO NOT: * Skip any module * Give pseudo code * Leave incomplete parts DO: * Write full working code * Make system runnable locally * Include setup instructions --- # ๐ FINAL OUTPUT You MUST generate: 1. Full backend (NestJS modules) 2. Full frontend (Next.js pages) 3. API gateway implementation 4. Prisma schema 5. Docker setup 6. Stripe integration 7. Seed script 8. SDK generator 9. Auth system --- # ๐ FINAL GOAL This should result in: ๐ A working SaaS product similar to an API marketplace ๐ Free APIs usable instantly ๐ Paid APIs accessible via subscription or BYOK --- # START BUILDING NOW
Sign in to leave a comment
No tasks generated yet.
Tasks will appear here as requirements are defined.
No comments yet. Be the first!