A sophisticated AI-powered text assistant built with Next.js 15 and React 19 that combines intelligent autocomplete, advanced spell checking, and smart feature coordination. Uses Ollama's Gemma 3 12B model for contextual text suggestions and typo-js with custom dictionaries for professional-grade spell checking.
- Context-aware suggestions using Ollama Gemma 3 12B model
- Smart triggering - activates after 5+ words with 500ms debouncing
- Inline suggestion display with layered textarea approach
- Tab key acceptance with intelligent spacing
- Vector database integration for enhanced contextual understanding
- typo-js integration with English Hunspell dictionaries
- Custom dictionary system with localStorage persistence
- Word mapping functionality - learns user corrections
- Contraction handling - automatically suggests 35+ common contractions
- Click-to-correct interface with intelligent popup positioning
- Performance optimized with 800ms debouncing and suggestion caching
- Text Feature Coordinator prevents conflicts between autocomplete and spellcheck
- Adaptive timing system with feature-specific lock durations
- Seamless multi-feature operation - autocomplete and spellcheck work together
- Memory management with proper cleanup and state handling
- Next.js 15 with App Router and Server Actions
- React 19 with advanced hooks and TypeScript
- Tailwind CSS v4 with responsive design
- Mobile-optimized UX with 16px fonts to prevent zoom
- Dynamic textarea resizing with smooth 300ms transitions
- Performance optimized with progressive debouncing and memoization
Before you begin, ensure you have the following installed:
- Node.js (version 18 or higher)
- npm or yarn
- Ollama (for running the Gemma 3 12B model locally)
-
Install Ollama on your system:
- Visit Ollama's official website and download the installer for your operating system
- Follow the installation instructions
-
Pull the Gemma 3 12B model:
ollama pull gemma3:12b
-
Start Ollama service:
ollama serve
-
Verify the installation:
ollama list
You should see
gemma3:12bin the list of available models.
-
Clone the repository:
git clone <your-repository-url> cd ai-autocomplete-spellcheck
-
Install dependencies:
npm install # or yarn install -
Set up environment variables: Create a
.env.localfile in the root directory:OLLAMA_PATH_API=http://127.0.0.1:11434/api
-
Set up spell check dictionaries: The application includes English dictionaries in the
public/dictionaries/en_US/folder:en_US.aff- Affix rules fileen_US.dic- Dictionary words file
-
Start the development server:
npm run dev # or yarn dev -
Open your browser and navigate to
http://localhost:3000 -
Start typing in the bio description field to experience:
- AI Autocomplete: After 5+ complete words, AI suggestions appear as gray inline text
- Spell Check: Misspelled words show red dotted underlines with click-to-correct
- Contraction Help: Type "dont" and see automatic "don't" suggestions
- Custom Dictionary: Add frequently used words to your personal dictionary
- Auto-capitalization: Smart sentence formatting applied in real-time
-
Advanced interactions:
- Press Tab to accept AI suggestions with proper spacing
- Click misspelled words for instant popup with corrections
- Right-click words to add them to your custom dictionary
- Type naturally - the Text Feature Coordinator prevents interference
- Mobile-friendly - all features work seamlessly on touch devices
The application uses a 4-hook system for optimal performance and feature coordination:
useFormAutocomplete- Main form logic with AI integrationuseSpellCheck- Core spell checking with typo-js and custom dictionariesuseDebouncedSpellCheck- Performance-optimized wrapper with cachinguseTextFeatureCoordinator- Prevents conflicts between features
The Text Feature Coordinator manages three text features:
- AUTOCOMPLETE - AI-powered text suggestions
- SPELLCHECK - Real-time spell checking
- CAPITALIZATION - Smart sentence formatting
Key Coordination Features:
- Feature locking with adaptive durations (200ms for autocomplete, configurable for others)
- Coexistence support - autocomplete and spellcheck can run simultaneously
- Memory management - automatic cleanup of timeouts and state
- Conflict prevention - ensures features don't interfere with each other
- Layered textarea approach for inline suggestion display
- Word completion detection - waits for complete words before suggesting
- Progressive debouncing - 500ms delay with smart triggering after 5+ words
- Vector database integration with Weaviate for enhanced context
- Server Actions communicate with Ollama Gemma 3 12B model
- Intelligent spacing - proper handling of tab acceptance and word boundaries
- typo-js integration with English Hunspell dictionaries (
en_US.aff,en_US.dic) - Custom dictionary service with localStorage persistence
- Add/remove custom words
- Word mapping system for learning corrections
- Persistent storage across browser sessions
- Contraction handling - automatic suggestions for 35+ common contractions:
dont→don't,do notyoure→you're,you arewont→won't,will not- And many more...
- Click-to-correct interface with intelligent popup positioning
- Performance optimizations:
- 800ms debounce delay
- Suggestion caching to prevent repeated lookups
- Memoization to prevent unnecessary re-renders
- Progressive debouncing based on text length
- Sentence boundary detection with proper punctuation handling
- Real-time processing without disrupting typing flow
- Context-aware rules:
- First letter of sentences
- After periods, exclamation marks, question marks
- Pronoun "I" capitalization
- Seamless integration with autocomplete and spell check features
ai-autocomplete-spellcheck/
├── actions/
│ └── ai-text.ts # Server actions for AI integration
├── app/
│ ├── layout.tsx # Root layout
│ ├── page.tsx # Main page component
│ ├── image-analyzer/ # Image analysis feature
│ └── globals.css # Global styles with Tailwind v4
├── components/
│ ├── Form.tsx # Main form with layered textarea
│ ├── SpellCheckPopup.tsx # Interactive spell suggestion popup
│ └── Navbar.tsx # Navigation component
├── hooks/ # Sophisticated 4-hook architecture
│ ├── useFormAutocomplete.tsx # Main form logic with AI integration
│ ├── useSpellCheck.tsx # Core spell check with contractions
│ ├── useDebouncedSpellCheck.tsx # Performance-optimized wrapper
│ └── useTextFeatureCoordinator.tsx # Feature conflict prevention
├── lib/
│ ├── customDictionary.ts # Custom dictionary service
│ ├── openai.ts # OpenAI integration
│ └── utils.ts # Utility functions
├── data/
│ └── bios.json # Bio examples for AI training
├── public/
│ ├── dictionaries/
│ │ └── en_US/ # Hunspell dictionaries
│ │ ├── en_US.aff # Affix rules
│ │ └── en_US.dic # Dictionary words
│ └── images/ # Static images
├── types/ # TypeScript type definitions
└── [Configuration Files]
├── next.config.js # Next.js configuration
├── tailwind.config.js # Tailwind CSS v4 config
└── tsconfig.json # TypeScript configuration
npm run dev- Start development server with Turbopacknpm run build- Build the application for productionnpm run start- Start the production servernpm run lint- Run ESLint for code quality
The application expects Ollama to be running on http://127.0.0.1:11434 by default. You can modify this in your .env.local file:
OLLAMA_PATH_API=http://your-ollama-host:port/apiSpell checking features advanced configuration options:
Core Settings:
- Debounce delay: 800ms for optimal performance
- Dictionary caching: Suggestions cached to prevent repeated lookups
- Custom dictionary: Persistent localStorage-based word storage
- Word mapping: Learn and remember user corrections
Contraction Handling: The system automatically handles 35+ common contractions:
// Examples of automatic contraction suggestions
dont → don't, do not
youre → you're, you are
wont → won't, will not
havent → haven't, have not
its → it's, it is, it hasCustom Dictionary Features:
- Add words: Right-click misspelled words to add to dictionary
- Word mappings: System learns your preferred corrections
- Persistent storage: Dictionary survives browser restarts
- Import/Export: Backup and restore custom words
Default Setup:
- Primary Model:
gemma3:12bvia Ollama (local inference) - Vector Database: Weaviate for contextual enhancement (optional)
- OpenAI Integration: Available as fallback option
Configuration Options:
// In actions/ai-text.ts - modify model settings
const model = "gemma3:12b"; // Change model here
const maxTokens = 50; // Adjust response length
const temperature = 0.7; // Control creativityPerformance Tuning:
- Progressive debouncing: Adapts timing based on text length
- Context window: Optimized for bio completion tasks
- Feature coordination: Automatic AI pause during spell check operations
-
Ollama not responding:
- Ensure Ollama service is running:
ollama serve - Check if the model is pulled:
ollama list - Verify the API endpoint in
.env.local
- Ensure Ollama service is running:
-
Model not found:
- Pull the model:
ollama pull gemma3:12b - Restart Ollama service
- Pull the model:
-
Slow responses:
- This is normal for local AI models
- Consider using a more powerful machine or adjusting the debounce delay
-
Spell check not working:
- Ensure dictionary files are present in
public/dictionaries/en_US/ - Check browser console for any dictionary loading errors
- Try refreshing the page to reinitialize the spell checker
- Clear localStorage if custom dictionary is corrupted:
localStorage.clear()
- Ensure dictionary files are present in
-
Performance issues while typing:
- The app uses sophisticated debouncing to prevent lag
- Text Feature Coordinator manages feature conflicts automatically
- If typing feels slow, check if other applications are using high CPU
- Progressive debouncing adapts timing based on text length
-
Features conflicting with each other:
- The Text Feature Coordinator should prevent this automatically
- If issues persist, try refreshing the page to reset coordinator state
- Check browser console for any coordination errors
- Next.js 15.3.3 - React framework with App Router and Server Actions
- React 19 - Latest UI library with advanced hooks
- React Hook Form 7.58.0 - Sophisticated form management
- typo-js 1.2.5 - Spell checking with Hunspell dictionary support
- use-debounce 10.0.5 - Performance optimization utility
- weaviate-client 3.6.2 - Vector database for contextual AI
- openai 5.5.0 - OpenAI API integration (optional)
- TypeScript 5 - Comprehensive type safety
- Tailwind CSS 4 - Latest version with PostCSS
- ESLint 9 - Advanced code linting with Next.js config
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Professional-grade accuracy using typo-js with Hunspell dictionaries
- Click-to-correct interface - no right-click needed, just click misspelled words
- Custom dictionary system with persistent localStorage storage
- Word mapping functionality - learns and remembers your corrections
- 35+ contraction suggestions - automatic handling of missing apostrophes
- Performance optimized with 800ms debouncing and intelligent caching
- Non-intrusive visual indicators - dotted red underlines without typing disruption
- Context-aware suggestions using Gemma 3 12B model for relevance
- Layered textarea approach for seamless inline suggestion display
- Smart triggering system - activates after 5+ complete words
- Vector database integration with Weaviate for enhanced understanding
- Intelligent spacing logic - proper tab acceptance and word boundaries
- Progressive debouncing - 500ms delay with adaptive timing
- Conflict prevention system - prevents autocomplete and spellcheck interference
- Adaptive feature locking with customizable durations per feature type
- Memory management - automatic cleanup of timeouts and state
- Coexistence support - allows multiple features to work simultaneously
- Performance monitoring - tracks and optimizes feature interactions
- 16px font sizes prevent unwanted mobile browser zoom
- Dynamic textarea resizing with smooth 300ms transitions
- Touch-friendly interface with properly sized click targets
- Responsive design adapts to all screen sizes
- Optimized debouncing for mobile keyboard behavior
- Battery-conscious processing with intelligent feature management
- Ollama for providing local AI model hosting
- Google Gemma for the powerful language model
- typo-js for excellent spell checking capabilities
- Hunspell for comprehensive dictionary support
- Next.js team for the excellent framework