Skip to content

About

[Under Construction 🚧] : Identity ; subscription ; credits , billing etc management layer for ai agent saas apps!

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

290 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Gateway

A unified infrastructure layer that connects users, AI applications, and model providers into a single system.

What It Is

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

Monorepo Structure

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

Tech Stack

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

Getting Started

Prerequisites

  • Node.js 20+
  • pnpm 9+
  • Docker + Docker Compose

Install dependencies

pnpm install

Start infrastructure (Postgres, Redis, Kafka, ClickHouse)

docker-compose up -d

Run DB migrations

pnpm --filter @ai-gateway/api db:migrate

Start all services in dev mode

pnpm dev

Start all services with PM2 (recommended for persistent processes)

Install PM2 globally if you haven't already:

npm install -g pm2

Development β€” starts all services with hot-reload (tsx watch / next dev):

pnpm pm2:dev

Production β€” starts all services from compiled output (node dist/index.js / next start):

pnpm build        # build all services first
pnpm pm2:start

Useful 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

Build Phases

Phase 1 (Core MVP)

  • Auth Module
  • Gateway Core
  • Credit System
  • Basic SDK
  • One model integration (OpenAI)

Phase 2 (Make It Usable)

  • Billing (Razorpay subscriptions)
  • User Dashboard
  • Dev SDK improvements
  • Usage tracking

Phase 3 (Make It Valuable)

  • Revenue sharing + Dev wallet
  • Dev dashboard + Earnings
  • Analytics (ClickHouse)
  • Admin panel

Documentation


Build once. Earn automatically.

About

[Under Construction 🚧] : Identity ; subscription ; credits , billing etc management layer for ai agent saas apps!

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages