Skip to content

CodedGrimoire/ChartGenie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

This is a Next.js project bootstrapped with create-next-app.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying app/page.js. The page auto-updates as you edit the file.

This project uses next/font to automatically optimize and load Geist, a new font family for Vercel.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

ChartGenie Conversational Server

A modular Node.js server for generating database diagrams using conversational AI (Groq API). The server maintains conversation context and can intelligently modify existing diagrams based on user requests.

πŸ“ Project Structure

β”œβ”€β”€ server.js           # Main Express server and route handlers
β”œβ”€β”€ config.js           # Configuration constants and environment variables
β”œβ”€β”€ groqService.js      # Groq API integration and communication
β”œβ”€β”€ diagramGenerator.js # Core diagram generation logic and conversation handling
β”œβ”€β”€ templates.js        # Fallback diagram templates and patterns
β”œβ”€β”€ trimmer.js          # Diagram code cleaning and validation utilities
β”œβ”€β”€ utils.js            # General utility functions and helpers
β”œβ”€β”€ package.json        # Dependencies and project metadata
└── README.md          # This file

πŸ—οΈ Module Breakdown

config.js

  • Environment variable management
  • Application constants (ports, timeouts, etc.)
  • Output format definitions
  • Groq API configuration

groqService.js

  • Groq API communication
  • Error handling for API calls
  • Connection testing utilities

diagramGenerator.js

  • Main diagram generation orchestration
  • Conversational prompt creation
  • Context-aware diagram modification
  • Fallback handling when AI fails

templates.js

  • Pre-built diagram templates (Hospital, E-commerce, Generic)
  • Entity field definitions by type
  • Relationship mapping rules
  • Template selection logic

trimmer.js

  • Raw AI response cleaning
  • Diagram code validation
  • Structure normalization
  • Duplicate removal

utils.js

  • Input validation
  • Entity extraction and parsing
  • Modification intent detection
  • Table name extraction
  • Relationship building utilities

server.js

  • Express app setup and middleware
  • Route definitions and handlers
  • Session management
  • Cache management
  • Graceful shutdown handling

πŸš€ Setup and Installation

  1. Clone and install dependencies:

    npm install
  2. Set up environment variables: Create a .env file in the root directory:

    GROQ_API_KEY=your_groq_api_key_here
    PORT=3003
  3. Get Groq API Key:

  4. Start the server:

    # Production
    npm start
    
    # Development (with auto-reload)
    npm run dev

πŸ“‘ API Endpoints

Health & Testing

  • GET /api/ping - Health check and server status
  • GET /api/test-groq - Test Groq API connection

Diagram Generation

  • POST /api/diagram - Generate or modify diagrams
    {
      "message": "Create an e-commerce database",
      "format": "mermaid",
      "sessionId": "optional-session-id",
      "currentDiagram": "optional-existing-diagram"
    }

Session Management

  • GET /api/conversation/:sessionId - Get conversation history
  • DELETE /api/conversation/:sessionId - Clear conversation
  • GET /api/sessions - List all active sessions

System

  • GET /api/formats - List supported output formats
  • DELETE /api/cache - Clear server cache

πŸ”„ Conversational Features

Context Awareness

  • Maintains conversation history per session
  • Understands modification requests ("add reviews table")
  • Preserves existing entities when modifying diagrams

Intelligent Modifications

  • Detects when user wants to modify vs. create new
  • Automatically creates relationships between new and existing entities
  • Validates that modifications preserve original structure

Fallback System

  • Uses templates when AI fails
  • Smart table generation based on context
  • Preserves user intent even when API is unavailable

πŸ§ͺ Example Usage

Creating a New Diagram

curl -X POST http://localhost:3003/api/diagram \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Create a hospital management system",
    "format": "mermaid"
  }'

Modifying Existing Diagram

curl -X POST http://localhost:3003/api/diagram \
  -H "Content-Type: application/json" \
  -d '{
    "message": "add a pharmacy table",
    "format": "mermaid",
    "sessionId": "existing-session-id",
    "currentDiagram": "erDiagram..."
  }'

πŸ› οΈ Development

Adding New Templates

  1. Add template to templates.js
  2. Update getTemplateByKeywords() function
  3. Add field definitions to TABLE_TYPE_FIELDS

Adding New Output Formats

  1. Add format to OUTPUT_FORMATS in config.js
  2. Update validation in utils.js
  3. Add cleaning logic in trimmer.js

Extending Utilities

  • Add new utility functions to utils.js
  • Update validation logic as needed
  • Add tests for new functionality

πŸ” Debugging

Enable Detailed Logging

The server includes extensive console logging:

  • πŸ”₯ - Main operations
  • βœ… - Successful operations
  • ❌ - Errors
  • ⚠️ - Warnings
  • πŸ” - Analysis/validation
  • πŸ“Š - Data processing

Common Issues

  1. Missing Groq API Key: Check .env file configuration
  2. Invalid Diagrams: Check trimmer.js validation logic
  3. Session Issues: Monitor session cleanup in server logs

πŸ“ˆ Performance Considerations

  • Caching: Results are cached with conversation context
  • Session Cleanup: Old sessions auto-cleanup after 24 hours
  • Memory Management: History limited to last 10 exchanges per session
  • Context Size: Only last 3 exchanges used for AI context

πŸ”§ Configuration Options

Modify config.js to adjust:

  • Cache TTL (time-to-live)
  • Maximum input length
  • Conversation history limits
  • Context history size
  • Groq API parameters

πŸ“ License

MIT License - feel free to use and modify as needed.

About

**ChartGenie is a conversational AI-powered web application that transforms natural language descriptions into interactive diagrams through a chat interface, built with Next.js/Tailwind frontend and Express.js backend using Groq API for intelligent diagram generation.**

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors