A unified infrastructure layer that connects users, AI applications, and model providers into a single system.
AI Gateway acts as:
- Identity layer β Login with AI Gateway (one account across all AI apps)
- Billing layer β Credits & subscriptions (one wallet, multiple apps)
- Routing layer β Connects apps to AI model providers intelligently
- Monetization layer β Developers earn automatically per usage
ai-gateway/
βββ apps/
β βββ web/ # Landing + dashboard (Next.js)
β βββ api/ # Main backend API (Fastify)
β βββ gateway/ # Core request engine
β βββ auth-service/ # Auth + token service
β βββ billing-service/ # Razorpay + subscriptions
β βββ credit-service/ # Wallet + credit logic
β βββ routing-service/ # Model routing + fallback
β βββ analytics-service/ # ClickHouse ingestion
β βββ worker/ # Kafka consumers
β
βββ packages/
β βββ sdk-js/ # JavaScript SDK
β βββ ui/ # Shared React components
β βββ config/ # Shared config + env schemas
β βββ types/ # Shared TypeScript types
β βββ utils/ # Shared helpers
β
βββ infra/
β βββ docker/ # Dockerfiles per service
β βββ kafka/ # Kafka topic configs
β βββ db/ # PostgreSQL + ClickHouse schemas
β
βββ docs/
βββ agents/ # Coding agent guidelines
βββ modules/ # Module documentation
βββ architecture.md
βββ techstack.md
| Layer | Technology |
|---|---|
| Backend | Node.js + TypeScript + Fastify |
| Frontend | Next.js 14 (App Router) + Tailwind CSS |
| Messaging | Apache Kafka |
| Primary DB | PostgreSQL |
| Analytics DB | ClickHouse |
| Cache | Redis |
| Payments | Razorpay |
| Infra | Docker + Docker Compose |
- Node.js 20+
- pnpm 9+
- Docker + Docker Compose
pnpm installdocker-compose up -dpnpm --filter @ai-gateway/api db:migratepnpm devInstall PM2 globally if you haven't already:
npm install -g pm2Development β starts all services with hot-reload (tsx watch / next dev):
pnpm pm2:devProduction β starts all services from compiled output (node dist/index.js / next start):
pnpm build # build all services first
pnpm pm2:startUseful PM2 commands:
pnpm pm2:status # view status of all processes
pnpm pm2:logs # tail logs from all services
pnpm pm2:stop # stop all services
pnpm pm2:delete # remove all services from PM2- Auth Module
- Gateway Core
- Credit System
- Basic SDK
- One model integration (OpenAI)
- Billing (Razorpay subscriptions)
- User Dashboard
- Dev SDK improvements
- Usage tracking
- Revenue sharing + Dev wallet
- Dev dashboard + Earnings
- Analytics (ClickHouse)
- Admin panel
Build once. Earn automatically.