Skip to content

aadnesd/finance-agent

 
 

Repository files navigation

Next.js 14 and App Router-ready AI chatbot.

An Open-Source AI Chatbot Template Built With Next.js and the AI SDK by Vercel.

Features · Model Providers · Deploy Your Own · Running locally


Features

  • Next.js App Router
    • Advanced routing for seamless navigation and performance
    • React Server Components (RSCs) and Server Actions for server-side rendering and increased performance
  • AI SDK
    • Unified API for generating text, structured objects, and tool calls with LLMs
    • Hooks for building dynamic chat and generative user interfaces
    • Supports OpenAI (default), Anthropic, Cohere, and other model providers
  • shadcn/ui
  • Data Persistence
  • NextAuth.js
    • Simple and secure authentication
  • Analytics Database Integration
    • Built-in database query tool for business analytics and insights
    • Natural language interface for querying sales, user metrics, and marketing data
    • Advanced security measures preventing destructive operations
    • Sample analytics schema with realistic business data

Model Providers

This template ships with OpenAI gpt-4o as the default. However, with the AI SDK, you can switch LLM providers to OpenAI, Anthropic, Cohere, and many more with just a few lines of code.

Deploy Your Own

You can deploy your own version of the Next.js AI Chatbot to Vercel with one click:

Deploy with Vercel

Running locally

You will need to use the environment variables defined in .env.example to run Next.js AI Chatbot. It's recommended you use Vercel Environment Variables for this, but a .env file is all that is necessary.

Note: You should not commit your .env file or it will expose secrets that will allow others to control access to your various OpenAI and authentication provider accounts.

  1. Install Vercel CLI: npm i -g vercel
  2. Link local instance with Vercel and GitHub accounts (creates .vercel directory): vercel link
  3. Download your environment variables: vercel env pull
pnpm install
pnpm dev

Your app template should now be running on localhost:3000.

Analytics Database Tool

This chatbot includes a powerful database interaction tool that allows users to query business analytics data using natural language. The tool provides a secure interface for accessing sales metrics, user data, product performance, and marketing insights.

Features

  • Natural Language Queries: Ask questions like "How many sales did we have last month?" or "Show me our top performing products"
  • Multiple Data Sources: Access user analytics, sales transactions, product performance, marketing campaigns, and user events
  • Advanced Security: Built-in protection against SQL injection and destructive operations
  • Sample Data: Pre-loaded with realistic business data for immediate testing

Available Tables

The analytics database includes these tables with sample data:

  • analytics_users: User information and subscription tiers
  • sales: Sales transactions with product details and revenue
  • user_events: User interaction tracking and behavior analytics
  • product_performance: Product metrics including views, purchases, and ratings
  • marketing_campaigns: Campaign performance with budget, spend, and conversions

Setup

  1. Environment Configuration: Add ANALYTICS_DB_POSTGRES_URL to your environment variables

    # In .env.local
    ANALYTICS_DB_POSTGRES_URL=your_postgres_connection_string
  2. Initialize Database: The tool will automatically create tables and sample data on first use

  3. Test the Tool: Run validation tests to ensure everything is working

    pnpm test:db-tool

Usage Examples

Once running, you can ask the chatbot questions like:

  • "What's our total revenue this quarter?"
  • "Show me user signups by month"
  • "Which products have the highest conversion rates?"
  • "How are our marketing campaigns performing?"
  • "Add a new sale for $150 from user John Doe"

Security Features

  • Only SELECT, INSERT, UPDATE, and DELETE operations allowed
  • DELETE and UPDATE operations require WHERE clauses
  • No DDL operations (DROP, ALTER, TRUNCATE, etc.)
  • Query results limited to 100 rows maximum
  • Built-in SQL injection prevention

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 96.1%
  • JavaScript 2.9%
  • CSS 1.0%