Your AI Writing Assistant is ready to run. Here's what has been implemented:
- XState v5 state machine with 4 states: idle, generating, review, error
- Handles all state transitions and AI generation lifecycle
- Extensively commented for learning
- OpenAI GPT-4 integration
- Error handling and user-friendly messages
- API key validation
- Fully documented with examples
- ProseMirror rich text editor
- Keyboard shortcuts (Ctrl+Space for AI, Ctrl+Z for undo)
- AI content highlighting
- Disabled state during generation
- Comprehensive comments explaining React hooks and ProseMirror
- "Continue Writing" button with Radix UI
- Loading states and error handling
- Keyboard shortcut hints
- Platform-specific shortcuts (Cmd/Ctrl)
- Real-time state indicators
- Color-coded badges (green/yellow/blue/red)
- Word count display
- Error messages
- Floating action toolbar
- Accept/Clear/Discard buttons
- Only appears in review state
- Smooth animations
- Coordinates all components
- Manages state machine
- Radix UI Theme provider
- Complete event handling
All required packages are installed:
- React 18.2.0
- XState 5.0.0
- ProseMirror (state, view, model, keymap, history)
- Radix UI (themes, icons)
- OpenAI API client
Create a .env file in the project root:
cp .env.example .envEdit .env and add your OpenAI API key:
VITE_OPENAI_API_KEY=sk-your-key-here
Get your API key from: https://platform.openai.com/api-keys
npm run devThe app will start at: http://localhost:5173
- Type some text in the editor
- Click "Continue Writing" or press
Ctrl+Space(orCmd+Spaceon Mac) - Wait for AI to generate content (highlighted in blue)
- Choose an action:
- Accept All: Keep the AI content
- Clear All: Remove the AI content
- Discard Session: Revert to before AI generation
- README.md - Project overview and quick start
- IMPLEMENTATION_GUIDE.md - Detailed explanation of architecture, concepts, and patterns
- product_requirement_spec.md - Complete product requirements
Every file includes extensive comments explaining:
- What each function does
- Why certain approaches were chosen
- How components interact
- React and JavaScript concepts for beginners
Start with these files in order:
src/machines/editorMachine.js- Understand state managementsrc/App.jsx- See how components connectsrc/components/Editor.jsx- Learn ProseMirror basicssrc/services/aiService.js- Understand API integration
✅ AI-powered text continuation ✅ Keyboard shortcuts (Ctrl+Space, Ctrl+Z, Ctrl+Y) ✅ Rich text editing with ProseMirror ✅ State management with XState ✅ Content management (Accept/Clear/Discard) ✅ Visual feedback (loading, highlighting, status) ✅ Error handling ✅ Responsive design ✅ Accessible UI with Radix ✅ Comprehensive code comments
- Make sure
.envfile is in project root - Restart dev server after adding API key
- Check that key starts with
sk-
- Run
npm install --legacy-peer-depsif dependency issues - Clear cache:
rm -rf node_modules package-lock.json && npm install --legacy-peer-deps
- Check browser console for errors
- Ensure all files are saved
- Try hard refresh (Ctrl+Shift+R)
User Action → Event → State Machine → New State → UI Update
Example:
Click "Continue" → CONTINUE_CLICK → generating → isGenerating=true → Editor disabled
App (state machine)
├── Toolbar (triggers AI)
├── Editor (text editing)
├── AIToolbar (review actions)
└── StatusBar (state display)
User types → Editor → App → State Machine → Context updated → StatusBar shows word count
Try these modifications to learn:
- Change AI Model: In
aiService.js, changemodel: 'gpt-4'to'gpt-3.5-turbo' - Adjust Temperature: Change
temperature: 0.7to make AI more/less creative - Add Formatting: Add bold/italic buttons to Toolbar
- Change Colors: Modify Radix theme in
App.jsx - Add Sounds: Play sound when AI finishes generating
- API key stored in frontend (use backend in production)
- No offline mode yet (transformers.js not implemented)
- Single user only (no collaboration)
- No export feature yet
See README.md for full list of planned features:
- Local AI fallback
- Multiple AI models
- Export to Markdown/PDF
- Dark mode
- Collaborative editing
- Read comments first - Every file has detailed explanations
- Use React DevTools - Install browser extension to inspect components
- Console.log everything - Add logs to understand data flow
- Break things - Modify code and see what happens
- Read docs - Links provided in IMPLEMENTATION_GUIDE.md
By studying this codebase, you'll understand:
- React hooks (useState, useEffect, useRef)
- State machines with XState
- Rich text editing with ProseMirror
- API integration with OpenAI
- Component composition
- Props and callbacks
- Async/await patterns
- Event handling
- Conditional rendering
- CSS styling
Run npm run dev and start exploring. Happy coding! 🚀
Need Help?
- Check IMPLEMENTATION_GUIDE.md for detailed explanations
- Read code comments in each file
- Refer to official docs (links in README.md)