|
| 1 | +# MoodChick Setup Guide |
| 2 | + |
| 3 | +This guide will help you set up MoodChick with HuggingFace AI integration for production use. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Node.js >= 18 |
| 8 | +- npm, yarn, or pnpm |
| 9 | +- HuggingFace account (for AI features) |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +### 1. Clone and Install |
| 14 | + |
| 15 | +```bash |
| 16 | +git clone <your-repo-url> |
| 17 | +cd mood-chick |
| 18 | +npm install |
| 19 | +``` |
| 20 | + |
| 21 | +### 2. Environment Configuration |
| 22 | + |
| 23 | +Create a `.env.local` file in the project root: |
| 24 | + |
| 25 | +```env |
| 26 | +# Required for AI features |
| 27 | +HUGGINGFACE_API_KEY=your_huggingface_api_key_here |
| 28 | +
|
| 29 | +# Optional: Custom configuration |
| 30 | +HUGGINGFACE_MODEL=google/flan-t5-small |
| 31 | +HUGGINGFACE_API_URL=https://api-inference.huggingface.co/models/google/flan-t5-small |
| 32 | +RATE_LIMIT_REQUESTS_PER_MINUTE=60 |
| 33 | +
|
| 34 | +# App configuration |
| 35 | +NEXT_PUBLIC_APP_NAME=MoodChick |
| 36 | +NEXT_PUBLIC_APP_DESCRIPTION=AI-Powered Caption Generator |
| 37 | +``` |
| 38 | + |
| 39 | +### 3. Get HuggingFace API Key |
| 40 | + |
| 41 | +1. Go to [HuggingFace Settings](https://huggingface.co/settings/tokens) |
| 42 | +2. Create a new token with "Read" permissions |
| 43 | +3. Copy the token to your `.env.local` file |
| 44 | + |
| 45 | +### 4. Run the Application |
| 46 | + |
| 47 | +```bash |
| 48 | +# Development |
| 49 | +npm run dev |
| 50 | + |
| 51 | +# Production build |
| 52 | +npm run build |
| 53 | +npm start |
| 54 | +``` |
| 55 | + |
| 56 | +## Features |
| 57 | + |
| 58 | +### ✅ Implemented Features |
| 59 | + |
| 60 | +- **AI-Powered Caption Generation**: Uses HuggingFace flan-t5-small model |
| 61 | +- **Mood Selection**: 5 different moods (Happy, Sad, Love, Motivational, Funny) |
| 62 | +- **Fallback System**: Curated captions when AI is unavailable |
| 63 | +- **Rate Limiting**: Prevents API abuse (60 requests/minute) |
| 64 | +- **Copy to Clipboard**: One-click copy functionality |
| 65 | +- **Responsive Design**: Works on all devices |
| 66 | +- **Dark Mode**: Automatic theme switching |
| 67 | +- **Error Handling**: Graceful degradation and retry logic |
| 68 | + |
| 69 | +### 🎨 UI Features |
| 70 | + |
| 71 | +- Modern gradient design with purple/pink theme |
| 72 | +- Smooth animations and hover effects |
| 73 | +- Interactive mood selection with visual feedback |
| 74 | +- Loading states and progress indicators |
| 75 | +- Success/error notifications |
| 76 | + |
| 77 | +### 🛡️ Production Features |
| 78 | + |
| 79 | +- **Rate Limiting**: Built-in protection against abuse |
| 80 | +- **Error Handling**: Comprehensive error management |
| 81 | +- **Fallback System**: Always works, even without API key |
| 82 | +- **TypeScript**: Full type safety |
| 83 | +- **ESLint**: Code quality enforcement |
| 84 | +- **Responsive**: Mobile-first design |
| 85 | + |
| 86 | +## API Endpoints |
| 87 | + |
| 88 | +### POST /api/generate-caption |
| 89 | + |
| 90 | +Generates AI-powered captions based on mood. |
| 91 | + |
| 92 | +**Request:** |
| 93 | +```json |
| 94 | +{ |
| 95 | + "mood": "happy", |
| 96 | + "prompt": "Write a happy, uplifting social media caption" |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +**Response:** |
| 101 | +```json |
| 102 | +{ |
| 103 | + "caption": "Sunshine and smiles make everything better! ☀️✨", |
| 104 | + "mood": "happy", |
| 105 | + "source": "huggingface", |
| 106 | + "timestamp": "2024-01-15T10:30:00.000Z" |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +## Testing |
| 111 | + |
| 112 | +### Test HuggingFace Integration |
| 113 | + |
| 114 | +```bash |
| 115 | +# Set your API key first |
| 116 | +export HUGGINGFACE_API_KEY=your_key_here |
| 117 | + |
| 118 | +# Run the test |
| 119 | +npm run test:huggingface |
| 120 | +``` |
| 121 | + |
| 122 | +### Manual Testing |
| 123 | + |
| 124 | +1. Start the development server: `npm run dev` |
| 125 | +2. Open http://localhost:3000 |
| 126 | +3. Select a mood and click "Generate Caption" |
| 127 | +4. Test copy functionality |
| 128 | +5. Test "Generate Again" feature |
| 129 | + |
| 130 | +## Deployment |
| 131 | + |
| 132 | +### Vercel (Recommended) |
| 133 | + |
| 134 | +1. Push your code to GitHub |
| 135 | +2. Connect your repository to Vercel |
| 136 | +3. Add environment variables in Vercel dashboard |
| 137 | +4. Deploy automatically |
| 138 | + |
| 139 | +### Other Platforms |
| 140 | + |
| 141 | +The app works on any platform that supports Next.js: |
| 142 | +- Netlify |
| 143 | +- Railway |
| 144 | +- DigitalOcean App Platform |
| 145 | +- AWS Amplify |
| 146 | + |
| 147 | +## Configuration |
| 148 | + |
| 149 | +### Environment Variables |
| 150 | + |
| 151 | +| Variable | Required | Default | Description | |
| 152 | +|----------|----------|---------|-------------| |
| 153 | +| `HUGGINGFACE_API_KEY` | Yes* | - | HuggingFace API key for AI features | |
| 154 | +| `HUGGINGFACE_MODEL` | No | `google/flan-t5-small` | Model to use | |
| 155 | +| `HUGGINGFACE_API_URL` | No | Auto-generated | Custom API URL | |
| 156 | +| `RATE_LIMIT_REQUESTS_PER_MINUTE` | No | `60` | Rate limit per minute | |
| 157 | +| `NEXT_PUBLIC_APP_NAME` | No | `MoodChick` | App name | |
| 158 | +| `NEXT_PUBLIC_APP_DESCRIPTION` | No | Auto-generated | App description | |
| 159 | + |
| 160 | +*Required for AI features, app works with fallback captions without it |
| 161 | + |
| 162 | +### Customization |
| 163 | + |
| 164 | +#### Adding New Moods |
| 165 | + |
| 166 | +1. Edit `src/app/page.tsx` - Add new mood to `moods` array |
| 167 | +2. Edit `src/lib/config.ts` - Add prompt to `moodPrompts` |
| 168 | +3. Edit `src/lib/huggingface.ts` - Add fallback captions |
| 169 | + |
| 170 | +#### Styling |
| 171 | + |
| 172 | +The app uses Tailwind CSS. Customize colors in: |
| 173 | +- `src/app/globals.css` - Global styles |
| 174 | +- `src/app/page.tsx` - Component styles |
| 175 | + |
| 176 | +## Troubleshooting |
| 177 | + |
| 178 | +### Common Issues |
| 179 | + |
| 180 | +1. **"HuggingFace API key is not configured"** |
| 181 | + - Add `HUGGINGFACE_API_KEY` to `.env.local` |
| 182 | + - Restart the development server |
| 183 | + |
| 184 | +2. **"Rate limit exceeded"** |
| 185 | + - Wait for the rate limit window to reset |
| 186 | + - Increase `RATE_LIMIT_REQUESTS_PER_MINUTE` if needed |
| 187 | + |
| 188 | +3. **"Model is loading"** |
| 189 | + - Wait 10-30 seconds and try again |
| 190 | + - The model needs to warm up on first request |
| 191 | + |
| 192 | +4. **Build errors** |
| 193 | + - Run `npm run lint` to check for issues |
| 194 | + - Run `npm run type-check` for TypeScript errors |
| 195 | + |
| 196 | +### Debug Mode |
| 197 | + |
| 198 | +Enable detailed logging: |
| 199 | +```env |
| 200 | +NODE_ENV=development |
| 201 | +``` |
| 202 | + |
| 203 | +## Performance |
| 204 | + |
| 205 | +### Optimization Features |
| 206 | + |
| 207 | +- **Client-side caching**: Reduces API calls |
| 208 | +- **Rate limiting**: Prevents abuse |
| 209 | +- **Fallback system**: Always responsive |
| 210 | +- **Lazy loading**: Optimized bundle size |
| 211 | +- **Image optimization**: Next.js automatic optimization |
| 212 | + |
| 213 | +### Monitoring |
| 214 | + |
| 215 | +- All API calls are logged |
| 216 | +- Error rates are tracked |
| 217 | +- Response times are monitored |
| 218 | +- Rate limit status is visible |
| 219 | + |
| 220 | +## Security |
| 221 | + |
| 222 | +### Built-in Protections |
| 223 | + |
| 224 | +- **Rate limiting**: Prevents DDoS attacks |
| 225 | +- **Input validation**: Prevents injection attacks |
| 226 | +- **Environment variables**: Secure API key storage |
| 227 | +- **CORS protection**: Secure cross-origin requests |
| 228 | + |
| 229 | +### Best Practices |
| 230 | + |
| 231 | +- Never commit API keys to version control |
| 232 | +- Use environment variables for sensitive data |
| 233 | +- Regularly rotate API keys |
| 234 | +- Monitor usage and costs |
| 235 | + |
| 236 | +## Support |
| 237 | + |
| 238 | +### Documentation |
| 239 | + |
| 240 | +- [HuggingFace Integration Guide](docs/HUGGINGFACE_INTEGRATION.md) |
| 241 | +- [API Documentation](docs/API.md) |
| 242 | +- [Deployment Guide](docs/DEPLOYMENT.md) |
| 243 | + |
| 244 | +### Getting Help |
| 245 | + |
| 246 | +1. Check the troubleshooting section |
| 247 | +2. Review the documentation |
| 248 | +3. Check GitHub issues |
| 249 | +4. Create a new issue if needed |
| 250 | + |
| 251 | +## Contributing |
| 252 | + |
| 253 | +1. Fork the repository |
| 254 | +2. Create a feature branch |
| 255 | +3. Make your changes |
| 256 | +4. Run tests and linting |
| 257 | +5. Submit a pull request |
| 258 | + |
| 259 | +## License |
| 260 | + |
| 261 | +This project is open source and available under the MIT License. |
0 commit comments