Skip to content

Nishal77/AskDB

Repository files navigation

AskYourDatabase

AI-powered system that enables users to query databases using natural language instead of writing SQL queries.

Demo Video

demovideo.mov

Prerequisites

  • Node.js 18+ and pnpm 8+
  • PostgreSQL database
  • OpenRouter API key

Installation

  1. Clone the repository:
git clone https://github.com/Nishal77/AskDB.git
cd Askyourdatabase
  1. Install dependencies:
pnpm install
  1. Setup environment variables:
pnpm setup:env
  1. Configure environment variables: Edit the .env file in the root directory and set the following required values:
  • OPENROUTER_API_KEY - Your OpenRouter API key
  • DATABASE_URL - PostgreSQL connection string
  • JWT_SECRET - Generate a secret key using: openssl rand -base64 32
  1. Setup database:
pnpm db:setup

Running the Application

Local Development

Start both API and web services:

pnpm dev

Start services individually:

pnpm dev:api    # API only
pnpm dev:web    # Web only

Docker

Start all services with Docker:

pnpm docker:dev

Stop Docker services:

pnpm docker:dev:down

Prisma Commands

Database Setup

# Generate Prisma Client and run migrations
pnpm db:setup

Generate Prisma Client

pnpm prisma:generate

Database Migrations

# Deploy migrations (production)
pnpm migrate

# Create new migration (development)
pnpm migrate:dev

# Check migration status
pnpm migrate:status

Prisma Studio (Database GUI)

cd packages/prisma
pnpm prisma studio

API Documentation

Base URL

http://localhost:3000/api/v1

Authentication Endpoints

  • POST /api/v1/auth/register - Register a new user
  • POST /api/v1/auth/login - Login and get JWT token
  • GET /api/v1/auth/me - Get current user profile (requires authentication)
  • POST /api/v1/auth/openrouter-key - Update OpenRouter API key (requires authentication)
  • DELETE /api/v1/auth/openrouter-key - Remove OpenRouter API key (requires authentication)

Query Endpoints

  • POST /api/v1/query/execute - Execute natural language query (requires authentication)
  • GET /api/v1/query/history - Get query history (requires authentication)
  • GET /api/v1/query/history/:id - Get specific query by ID (requires authentication)

Schema Endpoints

  • GET /api/v1/schema/connection/:connectionId - Get database schema (requires authentication)
  • GET /api/v1/schema/connection/:connectionId/embed - Get schema for embedding (requires authentication)
  • GET /api/v1/schema/connection/:connectionId/tables - Get tables with row counts (requires authentication)

Admin Endpoints

  • GET /api/v1/admin/connections - Get all database connections (requires authentication)

Health Check

  • GET /health - Health check endpoint (no authentication required)
  • GET /api/v1/health - Health check with API prefix (no authentication required)

Authentication

Most endpoints require JWT authentication. Include the token in the Authorization header:

Authorization: Bearer <your-jwt-token>

Services and Ports

License

Private

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors