Component Hierarchy
The GIMA AI Chatbot uses a layered component architecture with clear separation of concerns.Component Layers
Layer 1: UI Primitives (components/ui/)
Base components built on Radix UI. These are unstyled, accessible, and reusable.
- Overview
- Card Component
Characteristics:
- Based on Radix UI primitives
- Styled with Tailwind CSS
- Fully accessible (ARIA)
- Keyboard navigable
- Theme-aware (dark/light mode)
- Button, Card, Dialog
- Input, Select, Textarea
- Toast, Tooltip, Progress
Layer 2: AI Elements (components/ai-elements/)
Specialized components for AI interactions, adapted from Vercel AI SDK ecosystem.
Message Display
Message Display
message.tsx - Renders chat messages with rich contentFeatures:- Markdown rendering with syntax highlighting
- Code block display with copy functionality
- Image and file attachment support
- User/assistant differentiation
- Timestamp and metadata
Code Blocks
Code Blocks
code-block.tsx - Syntax-highlighted code displayFeatures:- Syntax highlighting with Shiki
- Language detection
- Copy to clipboard
- Line numbers
- Theme-aware colors
Tool Results
Tool Results
tool.tsx - Displays AI tool execution resultsFeatures:- Loading states during execution
- Success/error indicators
- Structured data display
- Expandable details
- Asset query results
- Maintenance order lists
- Inventory searches
- Calendar views
Other Elements
Other Elements
artifact.tsx: Display generated artifactsreasoning.tsx: Show AI reasoning processloader.tsx: Loading animationssuggestion.tsx: AI suggestionssources.tsx: Source citationsconfirmation.tsx: User confirmation prompts
Layer 3: Feature Components (components/features/)
Domain-specific components with business logic.
Main Features
Chat Feature (features/chat/)
The core chat interface with multi-modal capabilities.
Component Structure
Chat Component (chat.tsx)
Responsibilities:
-
State Management
- Message history with
usePersistentChat - Voice recording state
- File upload state
- Command mode state
- Message history with
-
Event Orchestration
- User input submission
- Voice command detection
- Quick action execution
- Tool approval handling
-
Integration Points
- AI streaming responses
- Backend API calls via tools
- File upload (images, PDFs)
- Voice transcription
Chat Input Area (chat-input-area.tsx)
Features:
- Auto-resizing textarea
- File upload (images, PDFs)
- Voice recording button
- Send button with loading state
- Quick action suggestions
- Character count (optional)
Chat Message (chat-message.tsx)
Rendering Logic:
- Role-based styling: User messages on right, assistant on left
- Content type detection: Text, code, images, tool results
- Markdown processing: Using
react-markdown - Action buttons: Copy, regenerate, delete
AI Tools Feature (features/ai-tools/)
Standalone AI-powered tools for maintenance tasks.
Activity Summary Tool
Location:features/ai-tools/activity-summary/
Purpose: Generate professional summaries of maintenance activities.
Components:
activity-summary.tsx: Main containeractivity-summary-form.tsx: Input formactivity-summary-preview.tsx: Result displayactivity-summary-list.tsx: History list
Checklist Builder Tool
Location:features/ai-tools/checklist-builder/
Purpose: Generate maintenance checklists tailored to equipment types.
Generated Checklist Structure:
Sample HVAC Preventive Maintenance Checklist
Sample HVAC Preventive Maintenance Checklist
Voice Feature (features/voice/)
Dual-mode voice system for dictation and commands.
Architecture
Two Voice Modes:-
Dictation Mode (Default)
- Transcribes speech to text in input box
- Uses Gemini API or Web Speech API
- Low friction for general chat
- Auto-detects high-confidence commands
-
Command Mode (Explicit)
- Dedicated UI for work order creation
- Parses structured commands
- Requires user confirmation
- Higher confidence threshold (0.7+)
Voice Button Component
States:- Idle: Ready to record
- Listening: Recording audio (red pulse)
- Processing: Transcribing (spinner)
- Error: Failed (error icon)
Theme Feature (features/theme/)
Dark/light mode toggle with system preference detection.
Implementation:
- Uses
next-themesfor theme management - Persists preference in localStorage
- Supports system preference
- No flash on page load (SSR compatible)
Component Patterns
Pattern 1: Compound Components
Components that work together as a cohesive unit.Pattern 2: Render Props
Components that accept functions as children for flexible rendering.Pattern 3: Custom Hooks
Extract component logic into reusable hooks.Pattern 4: Error Boundaries
Graceful error handling at component boundaries.Styling Approach
Tailwind CSS Utility-First
Benefits:- No CSS file management
- Consistent spacing/colors
- Responsive by default
- Dark mode built-in
CSS Variables for Theming
Defined inglobals.css:
Testing Components
Unit Tests with Vitest
Example Test:Integration Tests
Testing chat flow:Best Practices
Composition
Prefer composition over inheritance. Build complex UIs from simple components.
Single Responsibility
Each component should do one thing well. Split large components into smaller ones.
Type Safety
Define explicit prop types. Use TypeScript discriminated unions for variants.
Accessibility
Use semantic HTML. Add ARIA labels. Test keyboard navigation.
Next Steps
Development Setup
Get started with local development
API Reference
Explore the API documentation