Skip to content

An intelligent AI agent for chatting with databases: ask questions in natural language, get accurate SQL execution, structured results, and auto-generated charts.

Notifications You must be signed in to change notification settings

Cyronlee/chat-database-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chat Database Agent

中文版

A Next.js application for interacting with databases using natural language. Built with AI capabilities to help users query and visualize data.

Features

🤖 AI Agent Chat

Chat with your database using natural language queries powered by AI.

AI Agent

📊 Interactive Dashboards

Create and customize dashboards with various chart types to visualize your data.

Dashboard

🔍 Data Studio

Explore your database schema and write SQL queries with visual query results.

Data Studio

Tech Stack

  • Runtime: Bun / Node.js
  • Framework: Next.js 15
  • Language: TypeScript
  • Styling: Tailwind CSS, Shadcn/ui
  • Database ORM: Prisma
  • AI: Google Generative AI

Quick Start

One-Click Startup (Recommended)

The easiest way to start the project is using the startup script:

./start.sh

This script will:

  1. Start the System Database (PostgreSQL on port 5433) - stores user data and application data
  2. Start the Northwind Database (PostgreSQL on port 5434) - sample database for querying
  3. Initialize and seed the system database if needed
  4. Start the Next.js development server

Requirements:

  • Docker (must be running)
  • One of: bun, pnpm, or npm

Default Credentials

After startup, you can login with:

The Northwind sample database will be automatically added as an external database connection.ssss

Manual Setup

1. Start System Database Only

# Create the db/system-database directory if it doesn't exist
mkdir -p db/system-database

# Create Dockerfile for system-db
cat > db/system-database/Dockerfile << 'EOF'
FROM postgres:15-alpine

ENV POSTGRES_DB=chat_database_agent
ENV POSTGRES_USER=postgres
ENV POSTGRES_PASSWORD=postgres

EXPOSE 5432
EOF

# Build and run
docker build -t system-db-image -f db/system-database/Dockerfile db/system-database
docker run -d --name system-db -p 5433:5432 system-db-image

2. Start Northwind Database Only

# Build and run
docker build -t northwind-db-image -f db/northwind-database/Dockerfile db/northwind-database
docker run -d --name northwind-db -p 5434:5432 northwind-db-image

3. Configure Environment

Copy the example environment file and update it:

cp .env.example .env

Update .env with your settings:

# Google Generative AI API Key
GOOGLE_GENERATIVE_AI_API_KEY=your-api-key-here

# System Database (for user data and application data)
DATABASE_URL="postgresql://postgres:postgres@localhost:5433/chat_database_agent?schema=public"

4. Initialize Database

# Install dependencies
bun install

# Run migrations
bun run prisma migrate deploy

# Seed the database
bun run prisma db seed

5. Start Development Server

bun run dev

Open http://localhost:3000 in your browser.

Database Connections

Database Host Port Database Username Password
System DB localhost 5433 chat_database_agent postgres postgres
Northwind localhost 5434 northwind postgres postgres

Docker Commands

Stop Databases

docker stop system-db northwind-db

Remove Containers

docker rm system-db northwind-db

View Logs

docker logs system-db
docker logs northwind-db

Reset Databases

# Stop and remove containers
docker stop system-db northwind-db
docker rm system-db northwind-db

# Remove images (optional, for full rebuild)
docker rmi system-db-image northwind-db-image

# Restart with start.sh
./start.sh

Project Structure

├── agent/              # AI agent configuration
├── api-clients/        # API client functions
├── app/                # Next.js app directory
│   ├── (main)/         # Main application routes
│   └── api/            # API routes
├── components/         # React components
│   ├── ai-elements/    # AI-related components
│   ├── chart/          # Chart components
│   ├── chat/           # Chat components
│   └── ui/             # Shadcn/ui components
├── db/                 # Database configurations
│   ├── northwind-database/ # Northwind sample database
│   └── system-database/    # System database configuration
├── lib/                # Utility functions
├── prisma/             # Prisma schema and migrations
└── tools/              # AI tools

Learn More

About

An intelligent AI agent for chatting with databases: ask questions in natural language, get accurate SQL execution, structured results, and auto-generated charts.

Resources

Stars

Watchers

Forks

Languages