Skip to content

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

Contributors

Languages