Skip to main content

System Requirements

Before you begin, ensure your system meets these requirements:

Node.js

Version 20 or higherCheck your version:
node --version

Package Manager

npm, yarn, or pnpmAny modern package manager works:
  • npm (comes with Node.js)
  • yarn 1.22+
  • pnpm 8+
Recommended: Use Node.js 20 LTS for best compatibility and performance.

Installation Methods

Choose your preferred installation method:

Install with npm

1

Clone Repository

git clone https://github.com/jose-miserol/gima-ai-chatbot.git
cd gima-ai-chatbot
2

Install Dependencies

npm install
This installs all required packages:
  • Next.js 16.0: React framework
  • React 19: UI library
  • Vercel AI SDK v5: AI integration
  • Tailwind CSS 4: Styling
  • Zod 4: Schema validation
  • And more (see package.json)
3

Setup Environment

cp .env.example .env.local
Edit .env.local with your configuration (see Environment Variables below)
4

Start Development Server

npm run dev
Server starts at http://localhost:3000

Environment Variables

GIMA uses environment variables for configuration. All variables are validated at startup using Zod schemas.

Required Variables

These API keys are required for the chatbot to function:
GROQ_API_KEY
string
required
GROQ API key for LLaMA 3.3 language model (main chat functionality)
GROQ_API_KEY=gsk_your_api_key_here
GOOGLE_GENERATIVE_AI_API_KEY
string
required
Google Gemini API key for voice transcription and image analysis
GOOGLE_GENERATIVE_AI_API_KEY=AIzaYourAPIKeyHere

Optional Variables

NODE_ENV
string
default:"development"
Runtime environment
  • Values: development, production, test
  • Effect: Changes logging, error handling, and security headers
NODE_ENV=development
NEXT_PUBLIC_APP_URL
string
default:"http://localhost:3000"
Base URL of the application (for production deployments)
NEXT_PUBLIC_APP_URL=https://your-domain.com

Feature Flags

Control optional features using these environment variables:
NEXT_PUBLIC_ENABLE_CHAT_PERSISTENCE
boolean
default:"false"
Enable localStorage persistence for chat history
NEXT_PUBLIC_ENABLE_CHAT_PERSISTENCE=true
When enabled:
  • Messages persist across page refreshes
  • Stored in browser localStorage with key gima_chat_history
  • Users can clear history manually
When disabled:
  • Chat history only exists in memory
  • Cleared on page refresh
NEXT_PUBLIC_FEATURE_VOICE_COMMANDS
boolean
default:"false"
Enable voice-activated work order commands
NEXT_PUBLIC_FEATURE_VOICE_COMMANDS=true
NEXT_PUBLIC_FEATURE_PDF_READER
boolean
default:"false"
Enable PDF upload and analysis
NEXT_PUBLIC_FEATURE_PDF_READER=true

Complete .env.local Example

.env.local
# ========================================
# Required API Keys
# ========================================
GROQ_API_KEY=gsk_your_groq_api_key_here
GOOGLE_GENERATIVE_AI_API_KEY=AIzaYourGoogleAPIKeyHere

# ========================================
# Environment Configuration
# ========================================
NODE_ENV=development
NEXT_PUBLIC_APP_URL=http://localhost:3000

# ========================================
# Feature Flags
# ========================================
NEXT_PUBLIC_ENABLE_CHAT_PERSISTENCE=true
NEXT_PUBLIC_FEATURE_VOICE_COMMANDS=true
NEXT_PUBLIC_FEATURE_PDF_READER=true
Security: Never commit .env.local to version control. It’s already in .gitignore.

Key Technologies

GIMA is built with modern, production-ready technologies:

Next.js 16

App Router with server components
  • File-based routing
  • Server Actions for API calls
  • Built-in optimization

React 19

Latest React with concurrent features
  • Improved performance
  • Better Suspense
  • Enhanced hooks

Vercel AI SDK v5

AI framework for chat and streaming
  • useChat hook
  • Streaming responses
  • Tool calling support

Tailwind CSS 4

Utility-first CSS framework
  • Responsive design
  • Dark mode support
  • Custom theme

TypeScript 5

Type safety throughout
  • Strict mode enabled
  • Full IDE support
  • Runtime validation

Zod 4

Schema validation for data
  • Type inference
  • Runtime safety
  • Error handling

Available Scripts

The project includes several npm scripts for development and testing:
# Start development server with hot reload
npm run dev

# Open at http://localhost:3000

Project Structure

Understanding the project layout:
gima-ai-chatbot/
├── app/
│   ├── api/                    # API routes
│   │   └── chat/
│   │       └── route.ts       # Main chat endpoint
│   ├── actions/               # Server Actions
│   │   ├── voice.ts          # Voice transcription
│   │   ├── vision.ts         # Image analysis
│   │   └── files.ts          # PDF processing
│   ├── components/           # React components
│   │   ├── features/         # Feature components
│   │   │   ├── chat/        # Chat UI
│   │   │   └── voice/       # Voice components
│   │   ├── ai-elements/     # AI-generated UI
│   │   └── ui/              # Base UI (shadcn/ui)
│   ├── config/              # Configuration
│   │   └── env.ts          # Environment validation
│   ├── hooks/              # Custom React hooks
│   │   ├── use-persistent-chat.ts
│   │   ├── use-voice-input.ts
│   │   └── use-file-submission.ts
│   ├── lib/                # Libraries and utilities
│   │   ├── ai/            # AI configuration
│   │   │   └── chat-tools.ts  # Tool definitions
│   │   ├── services/      # Business logic
│   │   │   ├── chat-service.ts
│   │   │   └── backend-api.ts
│   │   └── schemas/       # Zod schemas
│   ├── types/             # TypeScript types
│   └── page.tsx          # Main page
├── public/               # Static assets
├── tests/               # Test files
├── .env.example        # Environment template
└── package.json       # Dependencies
Key files to explore:
  • app/components/features/chat/chat.tsx - Main chat component
  • app/api/chat/route.ts - Chat API endpoint
  • app/lib/ai/chat-tools.ts - AI tool definitions

Verification Steps

After installation, verify everything works:
1

Check Server Status

Server should start without errors:
npm run dev
Expected output:
✓ Ready in 2.5s
○ Local:   http://localhost:3000
2

Test Basic Chat

  1. Open http://localhost:3000
  2. Type: “Hola, ¿qué puedes hacer?”
  3. Press Enter
You should see a streaming response from the AI.
3

Test Voice Input (Optional)

  1. Click the microphone icon
  2. Allow browser microphone access
  3. Say something like “Prueba de voz”
  4. Text should appear in the input box
4

Test Image Analysis (Optional)

  1. Click the image upload icon
  2. Upload a photo of equipment or machinery
  3. The AI should analyze and describe the image
5

Run Tests

Ensure all tests pass:
npm test
All tests should pass with green checkmarks.

Troubleshooting

Common issues and solutions:
Symptoms:
Error: Cannot find module '@ai-sdk/react'
Solution:
  1. Delete node_modules and lock file:
    rm -rf node_modules package-lock.json
    npm install
    
  2. Ensure you’re using Node.js 20+:
    node --version
    
Symptoms: Server crashes on startup with Zod validation errors for environment variables.Cause: Missing or incorrectly formatted API keys in .env.local.Solution:
  1. Verify .env.local exists and has correct keys
  2. Check key formats:
    • GROQ: starts with gsk_
    • Google: starts with AIza
  3. On Windows, ensure UTF-8 encoding (not UTF-16):
    $content = Get-Content .env.local -Raw -Encoding Unicode
    [System.IO.File]::WriteAllText((Resolve-Path .env.local), $content, [System.Text.UTF8Encoding]::new($false))
    
Symptoms: Messages don’t appear, or chat shows error state.Solution:
  1. Check browser console (F12) for errors
  2. Verify API keys are valid:
  3. Check rate limits (GROQ: 30 req/min)
  4. Restart dev server: npm run dev
Symptoms: Microphone button does nothing or shows error.Solution:
  1. Grant browser microphone permission
  2. Check if HTTPS or localhost (WebRTC requires secure context)
  3. Verify GOOGLE_GENERATIVE_AI_API_KEY is set
  4. Try fallback: Voice should work with Web Speech API if Gemini fails
Symptoms: Uploading images shows error or no response.Solution:
  1. Check image size (max 10MB by default)
  2. Verify GOOGLE_GENERATIVE_AI_API_KEY is set
  3. Check supported formats: JPEG, PNG, WebP
  4. Check Gemini quota at AI Studio
Symptoms:
Error: Port 3000 is already in use
Solution: Use a different port:
PORT=3001 npm run dev
Or kill the process using port 3000:
# macOS/Linux
lsof -ti:3000 | xargs kill

# Windows
netstat -ano | findstr :3000
taskkill /PID <PID> /F
Symptoms: Red squiggly lines in VS Code but code runs fine.Solution:
  1. Restart TypeScript server in VS Code:
    • Cmd/Ctrl + Shift + P
    • “TypeScript: Restart TS Server”
  2. Ensure you opened the project root (not a parent folder)
  3. Check .vscode/settings.json for TypeScript config
Symptoms: npm run dev works but npm run build fails.Solution:
  1. Run type-check to find issues:
    npm run type-check
    
  2. Fix any TypeScript errors
  3. Check for environment variables used in build (must be set)
  4. Clear Next.js cache:
    rm -rf .next
    npm run build
    

Development Workflow

Recommended workflow for contributing to GIMA:
1

Setup Git Hooks

Husky automatically installs Git hooks for:
  • Pre-commit: Lints and formats staged files
  • Commit-msg: Validates commit message format
npm run prepare
2

Create Feature Branch

git checkout -b feature/your-feature-name
3

Make Changes

  • Write code
  • Add tests in tests/ directory
  • Update documentation if needed
4

Run Quality Checks

# Lint and format
npm run lint:fix
npm run format

# Type check
npm run type-check

# Run tests
npm test
5

Commit with Conventional Commits

git add .
git commit -m "feat: add new feature"
Allowed types: feat, fix, docs, style, refactor, perf, test, build, ci, chore
6

Push and Create PR

git push origin feature/your-feature-name
Then create a Pull Request on GitHub.
Commit Message Format: type(scope): descriptionExamples:
  • feat(chat): add message reactions
  • fix(voice): resolve transcription timeout
  • docs(readme): update installation steps

Next Steps

Now that you have GIMA installed:

Configuration Guide

Learn about advanced configuration options

Core Features

Explore multimodal chat capabilities

AI Tools

Discover AI-powered maintenance tools

Architecture

Understand the system architecture

Getting Help

If you encounter issues not covered here:

GitHub Issues

Report bugs or request features

View Source Code

Browse the full source code

Build docs developers (and LLMs) love