Directory Overview
The GIMA AI Chatbot follows Next.js 16 App Router conventions with a feature-based organization pattern.Core Directories
/app - Application Root
The main application directory following Next.js App Router structure.
Key Files
/app/actions - Server Actions
Next.js Server Actions for server-side operations.
analyzeImage(): Vision analysis for industrial partstranscribeAudio(): Speech-to-text transcriptionextractPDFContent(): PDF text extraction and analysisgenerateChecklist(): AI-powered maintenance checklistgenerateActivitySummary(): Professional activity reports
/app/api - API Routes
Next.js API Routes for backend endpoints.
/api/chat Route (app/api/chat/route.ts:83)
- POST endpoint for chat messages
- Streams AI responses using Vercel AI SDK
- Handles tool calls and authentication
- Rate limiting and IP validation
/app/components - React Components
Organized by type and feature:
Component Categories
- ai-elements/
- features/
- ui/
AI-Specific ComponentsPre-built components for AI interactions from the Vercel AI SDK ecosystem.
artifact.tsx: Display AI-generated artifactscode-block.tsx: Syntax-highlighted code displaymessage.tsx: Chat message renderingreasoning.tsx: AI reasoning visualizationtool.tsx: Tool call result display- And 25+ more specialized components
/app/config - Configuration
Centralized application configuration:
env.ts(app/config/env.ts:1): Validates environment variables with Zodserver.ts(app/config/server.ts:40): Contains the main SYSTEM_PROMPT and glossarymodels.ts: AI model selection and configuration
/app/lib - Core Libraries
Core business logic, services, and utilities:
Key Services
ChatService
ChatService
lib/services/chat-service.tsMain orchestrator for chat functionality:- Validates incoming messages
- Manages rate limiting
- Coordinates AI streaming
- Handles tool execution
- Error handling and logging
BackendAPIService
BackendAPIService
lib/services/backend-api-service.tsHTTP client for Laravel backend:- Bearer token authentication
- Automatic retry with exponential backoff
- Timeout handling (8s default)
- Response unwrapping and validation
- Type-safe API methods
getActivos(): Fetch assetsgetMantenimientos(): Fetch maintenance ordersgetReportes(): Fetch reportsgetInventario(): Fetch inventorygetProveedores(): Fetch suppliers
Chat Tools
Chat Tools
lib/ai/tools/chat-tools.tsDefines AI tools using Vercel AI SDK:consultar_activos: Query assetsconsultar_mantenimientos: Query maintenanceconsultar_calendario: View calendarconsultar_reportes: Query reportsconsultar_inventario: Search inventoryconsultar_proveedores: List suppliersgenerar_checklist: Generate maintenance checklistgenerar_resumen_actividad: Generate activity summarycrear_orden_trabajo: Create work order (client-side)
/app/hooks - Custom Hooks
Reusable React hooks:
usePersistentChat(app/hooks/use-persistent-chat.ts:1): WrapsuseChatwith localStorage persistenceuseVoiceInput(app/hooks/use-voice-input.ts:1): Dual voice system (Gemini + Web Speech API)useWorkOrderCommands(app/hooks/use-work-order-commands.ts:1): Execute voice commands
/app/types - TypeScript Types
Shared type definitions:
/app/tools - Tool Pages
Standalone tool interfaces (routes):
Configuration Files
Root Configuration
Import Aliases
The project uses TypeScript path aliases for cleaner imports:@/*→./app/*@components/*→./app/components/*
File Naming Conventions
Components
kebab-case.tsxfor filesPascalCasefor component names- Example:
chat-message.tsxexportsChatMessage
Services
kebab-case.tsfor filesPascalCasefor class names- Example:
chat-service.tsexportsChatService
Hooks
use-feature-name.tspattern- Example:
use-persistent-chat.ts
Types
feature.types.tspattern- Example:
chat.types.ts
Next Steps
Component Architecture
Understand the component hierarchy and patterns
Development Guide
Set up your development environment