TechSetupGuides
Intermediatedatabasesqlaijavareactelectronmysqlpostgresqlnosql

Chat2DB: AI-driven database tool and SQL client

AI-powered database management tool supporting MySQL, PostgreSQL, Oracle, SQL Server, SQLite, MongoDB, Redis and more with intelligent SQL generation and reporting.

  1. Step 1

    What is Chat2DB?

    Chat2DB is an AI-driven database management tool and SQL client that provides intelligent capabilities for database operations. It supports over 16 database types including MySQL, PostgreSQL, Oracle, SQL Server, SQLite, MongoDB, Redis, ClickHouse, and more. The tool features AI-powered SQL generation, SQL explanations, SQL optimization, and automated reporting capabilities.

  2. Step 2

    Technology stack

    Chat2DB is built using a modern full-stack architecture with Electron for desktop deployment:

    Backend (Server):

    • Java 17 with Maven
    • Spring Boot 3.1.0
    • MyBatis-Plus for ORM
    • H2, Flyway for database management
    • Sa-Token for authentication
    • Forest for HTTP clients
    • FastJSON2 for JSON processing
    • MapStruct for object mapping
    • Apache Commons, Guava utilities
    • Hutool (cn.hutool) utility library
    • Logback for logging

    Frontend (Client):

    • React 16/18
    • Umi 4 (React framework)
    • TypeScript 5
    • Ant Design 5 (antd)
    • Electron 22 for desktop app
    • Monaco Editor for SQL editing
    • AliReact-Table for data tables
    • ECharts for data visualization
    • Zustand for state management
    • Tailwind CSS 3
    • SQL-Formatter for SQL formatting

    AI Integration:

    • OpenAI API integration
    • Custom AI model support
    • Natural language to SQL conversion
    • SQL optimization and explanation
    • SQL dialect conversion

    Database Support:

    • Relational: MySQL, PostgreSQL, Oracle, SQL Server, SQLite, MariaDB, DB2, H2, ClickHouse, DM, KingBase, OceanBase, Snowflake
    • NoSQL: MongoDB, Redis, Couchbase, Cassandra, Presto, Hive
    • Plus data warehouse and specialized databases
    Backend:
    ├── Java 17
    ├── Spring Boot 3.1.0
    ├── MyBatis-Plus
    ├── H2 / Flyway
    ├── Sa-Token
    ├── Forest HTTP client
    ├── FastJSON2
    ├── MapStruct
    └── Logback
    
    Frontend:
    ├── React 16/18
    ├── Umi 4
    ├── TypeScript 5
    ├── Ant Design 5
    ├── Electron 22
    ├── Monaco Editor
    ├── AliReact-Table
    ├── ECharts
    └── Zustand
    
    Databases:
    ├── Relational: MySQL, PostgreSQL, Oracle, SQL Server, SQLite
    ├── NoSQL: MongoDB, Redis, Couchbase, Cassandra
    └── Data Warehouse: ClickHouse, Presto, Hive, Snowflake
  3. Step 3

    Prerequisites

    Before setting up Chat2DB, ensure you have the following:

    For Docker deployment (recommended):

    • Docker and Docker Compose installed
    • At least 2GB of free disk space
    • Port 10824 available

    For development build:

    • Java 17 or higher (OpenJDK or Oracle JDK)
    • Maven 3.8+ for backend
    • Node.js 16+ for frontend
    • npm or yarn package manager
    # Verify Docker installation
    docker --version
    docker-compose --version
    
    # Or for development setup:
    # Java 17+
    java --version
    
    # Maven 3.8+
    mvn --version
    
    # Node.js 16+
    node --version
    npm --version
  4. Step 4

    Quick start with Docker

    The fastest way to run Chat2DB is using Docker. This spins up the complete application with the web interface accessible at port 10824.

    # Run Chat2DB with Docker
    docker run -d \
      -p 10824:10824 \
      -v ~/.chat2db-docker:/root/.chat2db \
      --name chat2db \
      chat2db/chat2db:latest
    
    # Access the web interface at:
    # http://localhost:10824
  5. Step 5

    Docker Compose deployment

    For more control over configuration, use Docker Compose to define your Chat2DB deployment with volumes and environment variables.

    version: '3'
    services:
      chat2db:
        image: chat2db/chat2db:latest
        container_name: chat2db-latest
        volumes:
          - ~/.chat2db-docker:/root/.chat2db
        ports:
          - "10824:10824"
        restart: unless-stopped
        environment:
          - JAVA_OPTS=-Xmx1024m
  6. Step 6

    Development setup from source

    To run Chat2DB from source for development or contribution, clone the repository and build both the server and client components separately.

    Backend setup:

    1. Navigate to the chat2db-server directory
    2. Configure database settings in application.yml
    3. Build with Maven
    4. Run the Spring Boot application

    Frontend setup:

    1. Navigate to the chat2db-client directory
    2. Install npm dependencies
    3. Start the development server
    4. Access at http://localhost:8000
    # Clone the repository
    git clone https://github.com/CodePhiliaX/Chat2DB.git
    cd Chat2DB
    
    # === Backend Setup ===
    cd chat2db-server
    
    # Configure database (optional, defaults to H2)
    # Edit chat2db-server-start/src/main/resources/application.yml
    
    # Build with Maven
    mvn clean package -Dmaven.test.skip=true
    
    # Run the server
    java -jar chat2db-server-start/target/chat2db-server-start.jar
    
    # Server runs at http://localhost:10824
    
    # === Frontend Setup ===
    cd ../chat2db-client
    
    # Install dependencies
    npm install
    
    # Start development server
    npm run start:web:hot
    
    # Access at http://localhost:8000
  7. Step 7

    Building desktop application

    Build the Electron-based desktop application for Windows, macOS, or Linux. This requires both the web build and Electron packaging.

    Prerequisites:

    • Node.js 16+
    • Python 3.x (for Windows builds)
    • Visual Studio Build Tools (Windows only)
    • Xcode Command Line Tools (macOS only)
    # Build the desktop application
    cd chat2db-client
    
    # Install dependencies
    npm install
    
    # Build for local machine
    npm run build:desktop
    
    # Build outputs:
    # - Windows: .exe installer and portable version
    # - macOS: .dmg and .zip
    # - Linux: AppImage
    
    # Check the release output
    ls -la release/  # or build/ depending on version
  8. Step 8

    AI functionality configuration

    Chat2DB's AI features require API configuration. You can use OpenAI or configure custom AI models.

    OpenAI Configuration:

    1. Get an OpenAI API key from https://platform.openai.com
    2. In Chat2DB settings, navigate to AI Configuration
    3. Enter your API key
    4. Test the connection

    Custom AI Model:

    • Deploy your own AI model (ChatGLM, Llama, etc.)
    • Configure the custom API endpoint in Chat2DB settings
    • Ensure the API follows the expected request/response format
    # Environment variable method (for server mode)
    export OPENAI_API_KEY="your-api-key-here"
    export OPENAI_BASE_URL="https://api.openai.com/v1"
    
    # Or configure in the application settings:
    # 1. Open Chat2DB UI
    # 2. Go to Settings -> AI Configuration
    # 3. Enter your OpenAI API Key
    # 4. Select model (gpt-3.5-turbo or gpt-4)
    # 5. Test connection
  9. Step 9

    Core features

    Chat2DB provides comprehensive database management capabilities:

    Visual Table Editor:

    • Browse and edit table structures visually
    • Add, modify, or delete columns
    • Create indexes and constraints
    • Import/export table schemas

    SQL Console:

    • Write and execute SQL queries
    • Intelligent SQL formatting
    • Query history and saved queries
    • Result set export (CSV, Excel, JSON)
    • Explain plan visualization

    AI-Powered Features:

    • Natural Language to SQL: Convert plain English to SQL queries
    • SQL Explanation: Get human-readable explanations of complex queries
    • SQL Optimization: Receive suggestions to improve query performance
    • SQL Conversion: Convert SQL between different database dialects

    Data Reporting:

    • Generate visual reports from query results
    • Chart creation with ECharts
    • Dashboard creation
    • Automated report scheduling (Pro version)

    Database Management:

    • Multi-database support with single interface
    • Connection pool management
    • Data import/export
    • Table data synchronization
    • Bulk data operations
    {
      "ai_features": {
        "natural_language_to_sql": true,
        "sql_explanation": true,
        "sql_optimization": true,
        "sql_conversion": true,
        "chatbot_assistant": true
      },
      "supported_databases": {
        "relational": [
          "MySQL",
          "PostgreSQL",
          "Oracle",
          "SQL Server",
          "SQLite",
          "MariaDB",
          "DB2",
          "H2",
          "ClickHouse",
          "DM",
          "KingBase",
          "OceanBase",
          "Snowflake"
        ],
        "nosql": [
          "MongoDB",
          "Redis",
          "Couchbase",
          "Cassandra",
          "Presto",
          "Hive"
        ]
      }
    }
  10. Step 10

    Connection setup

    Connect to your database through the Chat2DB interface.

    Supported connection methods:

    • Local database connections
    • Remote database connections
    • SSH tunnel connections
    • Cloud database connections

    Connection parameters:

    • Host/Connection String
    • Port
    • Database Name
    • Username & Password
    • SSL Options
    • Connection Pool Settings
    # Example MySQL connection:
    # In Chat2DB UI:
    # 1. Click "New Connection"
    # 2. Select "MySQL"
    # 3. Fill in:
    #    - Host: localhost
    #    - Port: 3306
    #    - Database: mydb
    #    - Username: root
    #    - Password: your_password
    #    - SSL: false (or true for secure connections)
    # 4. Test Connection
    # 5. Save Connection
    
    # Example PostgreSQL connection:
    # Host: localhost
    # Port: 5432
    # Database: postgres
    # Username: postgres
    # Password: your_password
  11. Step 11

    Project structure

    Understanding the Chat2DB codebase structure helps with development and customization:

    chat2db-server/ (Backend)

    • chat2db-server-domain: Domain models and business logic
    • chat2db-server-start: Boot application entry point
    • chat2db-server-web: Web API layer
    • chat2db-server-tools: Utility tools
    • chat2db-plugins: Database driver plugins
    • chat2db-spi: Service provider interfaces

    chat2db-client/ (Frontend)

    • src/pages: React page components
    • src/services: API service calls
    • src/models: Data models and state
    • src/components: Reusable UI components
    • src/main: Electron main process

    docker/ - Docker deployment files document/ - Documentation files

    Chat2DB/
    ├── chat2db-server/
    │   ├── chat2db-server-domain/     # Business logic
    │   ├── chat2db-server-start/      # Application entry
    │   ├── chat2db-server-web/        # REST API
    │   ├── chat2db-server-tools/      # Utilities
    │   ├── chat2db-plugins/          # Database drivers
    │   ├── chat2db-spi/              # SPI layer
    │   └── pom.xml                    # Maven build
    ├── chat2db-client/
    │   ├── src/
    │   │   ├── pages/                # React pages
    │   │   ├── services/             # API calls
    │   │   ├── models/               # State models
    │   │   ├── components/           # UI components
    │   │   └── main/                 # Electron
    │   ├── package.json              # NPM dependencies
    │   └── umi.config.ts             # Umi configuration
    ├── docker/                       # Docker files
    ├── document/                     # Documentation
    └── README.md
  12. Step 12

    Build configuration

    Configure build options for different deployment scenarios:

    Server configuration (application.yml):

    • Database connection settings
    • Port configuration (default: 10824)
    • Spring Boot profiles (dev, prod)
    • Logging levels

    Client configuration (umi.config.ts):

    • Build mode (development, production)
    • API proxy settings
    • Port configuration (default: 8000)
    • Environment variables
    # Example application.yml (Server)
    spring:
      application:
        name: Chat2DB
      datasource:
        type: com.zaxxer.hikari.HikariDataSource
        hikari:
          maximum-pool-size: 10
          minimum-idle: 1
          idle-timeout: 60000
        url: jdbc:h2:file:./data/chat2db;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE
        username: sa
        password: 
      servlet:
        encoding:
          charset: utf-8
          force: true
    
    server:
      port: 10824
      servlet:
        encoding:
          charset: utf-8
  13. Step 13

    Environment setup

    Set up the required environment variables and configurations:

    Development environment:

    • Java 17 set in JAVA_HOME
    • Maven configured in PATH
    • Node.js 16+ configured in PATH

    Production environment (Docker):

    • Persistent volumes for data
    • Appropriate memory limits
    • Port mappings
    # Set up Java environment
    export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
    export PATH=$JAVA_HOME/bin:$PATH
    
    # Set up Maven
    export MAVEN_HOME=/opt/apache-maven-3.9.6
    export PATH=$MAVEN_HOME/bin:$PATH
    
    # For Docker production deployment:
    # Memory configuration
    docker run -d \
      --memory="2g" \
      --memory-swap="2g" \
      -e JAVA_OPTS="-Xmx1024m -Xms512m" \
      chat2db/chat2db:latest
    
    # Persistent storage
    docker run -d \
      -v /data/chat2db:/root/.chat2db \
      chat2db/chat2db:latest
  14. Step 14

    Troubleshooting

    Common issues and solutions:

    Port already in use:

    • Change port in docker run or docker-compose.yml
    • Or modify server.port in application.yml

    Database connection failed:

    • Check network connectivity
    • Verify credentials
    • Ensure firewall allows the port
    • Check SSL settings

    AI features not working:

    • Verify API key is configured
    • Check network can reach AI provider
    • Verify subscription status

    Memory issues:

    • Increase JVM heap size with JAVA_OPTS
    • Increase Docker memory limits

    Build failures:

    • Clean and rebuild: mvn clean install
    • Clear npm cache: npm cache clean --force
    • Check Java version matches requirements
    # Check Docker logs
    docker logs chat2db
    
    # Check server logs (development)
    tail -f chat2db-server/logs/chat2db.log
    
    # Increase JVM memory
    export JAVA_OPTS="-Xmx2048m -Xms1024m"
    
    # Clean Maven build
    mvn clean install -Dmaven.test.skip=true
    
    # Clean npm install (client)
    rm -rf node_modules package-lock.json
    npm install
  15. Step 15

    Resources

    Official website: https://chat2db.ai

    GitHub repository: https://github.com/CodePhiliaX/Chat2DB

    Docker Hub: https://hub.docker.com/r/chat2db/chat2db

    Discord community: https://discord.com/invite/uNjb3n5JVN

    Documentation: https://github.com/CodePhiliaX/Chat2DB/wiki

    Release notes: https://github.com/CodePhiliaX/Chat2DB/releases

    License: Apache License 2.0

    Official Site: https://chat2db.ai
    GitHub: https://github.com/CodePhiliaX/Chat2DB
    Docker: https://hub.docker.com/r/chat2db/chat2db
    Discord: https://discord.com/invite/uNjb3n5JVN
    Docs: https://github.com/CodePhiliaX/Chat2DB/wiki
    Releases: https://github.com/CodePhiliaX/Chat2DB/releases
    License: Apache 2.0

Feature requests

Sign in to suggest features or vote on existing ones.

No feature requests yet.

Discussion

0 people marked this as worked·Sign in to mark your own.

Sign in to join the discussion.

No comments yet.