An advanced web application that uses AI to analyze your emotions and provide contextually relevant Quranic verses, authentic supplications, and personalized support messages.
sakina.mp4
- AI-powered analysis using GPT-4o-mini
- Understands Arabic with various dialects
- 8 emotion categories with multi-level analysis
- Fallback local analysis when AI is unavailable
- Confidence scoring for accuracy measurement
- 50 carefully selected Quranic verses
- 30 authentic duas from Quran and Sunnah
- Verified tafsir based on Al-Tafsir Al-Muyassar and Ibn Kathir
- Professional English translations of meanings
- Documented sources for every dua (Sahih Bukhari, Muslim, etc.)
- Score-based selection (not purely random)
- User history tracking to avoid repetition
- Multi-emotion support (detects multiple feelings)
- 15-20 verse variety before repeating for same user
- Weighted categories for better matching
- AI-generated messages tailored to specific emotions
- Islamic perspective with encouragement
- Simple, clear Arabic (Fusha) language
- 2-3 sentences for easy reading
Node.js v18 or higher
npm or yarn
OpenAI API Key
# 1. Clone the repository
git clone https://github.com/yourusername/quran-emotions.git
cd quran-emotions
# 2. Install backend dependencies
npm install
# 3. Create environment file
touch .env
# 4. Add your OpenAI API key to .env
echo "OPENAI_API_KEY=sk-your-actual-key-here" >> .env
echo "PORT=3001" >> .env
# 5. Start the server
npm startServer will run on http://localhost:3001
The React component is provided as a standalone file that can be:
- Used with Claude.ai Artifacts
- Integrated into your React application
- Deployed separately
- Visit: https://platform.openai.com/api-keys
- Click "Create new secret key"
- Copy the key (starts with
sk-) - Add it to
.envfile
Important: Use a regular Secret Key (sk-...), NOT a Project Key (sk-proj-...)
- Per search: ~$0.001 - $0.002 (less than a penny!)
- 100 searches: ~$0.10 - $0.20 (very affordable)
- 1,000 searches: ~$1 - $2 (highly economical)
- Emotion analysis: ~$0.0005 (short text input)
- Support message generation: ~$0.0008 (150-200 words output)
- Total per complete search: ~$0.0013
Note: GPT-4o-mini is 60x cheaper than GPT-4!
User submits their emotional expression in Arabic. The system analyzes and classifies into 8 categories:
- gratitude - thankfulness, joy, happiness
- sadness - grief, sorrow, depression
- anxiety - worry, fear, stress
- anger - rage, frustration, annoyance
- despair - hopelessness, severe discouragement
- guidance - confusion, need for direction
- weak_faith - spiritual weakness, distance from Allah
- illness - physical pain, sickness
// Example: User feels sadness and anxiety
Primary emotion: sadness (score: 100)
Secondary emotions: anxiety (score: 50)
// Each verse is scored based on category match
Verse 1 (categories: [sadness, despair]) โ score: 100 ร 10 = 1000
Verse 2 (categories: [anxiety, sadness]) โ score: 100 ร 10 + 50 ร 10 = 1500
Verse 3 (categories: [gratitude]) โ score: 0
// Top 5 verses selected, then random pick from them
// This ensures relevance while maintaining variety- System tracks last 15 verses shown to each user
- Excludes them from next selection
- After 15 different verses, oldest ones become available again
GPT-4o-mini generates a compassionate message that:
- Acknowledges the specific feeling
- Provides Islamic comfort and hope
- Encourages trust in Allah
- Offers practical spiritual guidance
quran-emotions/
โโโ server.js # Main Express server
โโโ QuranEmotions.jsx # React frontend component
โโโ package.json # Dependencies
โโโ .env # Environment variables (not in git)
โโโ .env.example # Environment template
โโโ README.md # This file
server.js contains:
โโโ verses[] # 50 Quranic verses with tafsir
โโโ duas[] # 30 authentic supplications
โโโ emotionCategories{} # 8 categories with keywords
โโโ analyzeWithAI() # GPT-4o-mini emotion analysis
โโโ analyzeEmotionLocally() # Fallback keyword analysis
โโโ selectBestVerse() # Smart verse selection
โโโ selectBestDua() # Smart dua selection
โโโ generateSupportMessage() # AI support message
โโโ POST /api/analyze # Main API endpoint
Request:
{
"emotionText": "ุฃุดุนุฑ ุจุงูุญุฒู ูุงูุถูู"
}Response:
{
"analysis": {
"category": "sadness",
"categories": ["sadness", "anxiety"],
"intensity": "high",
"confidence": 85
},
"verse": {
"arabic": "ููุฅูููู ู
ูุนู ุงููุนูุณูุฑู ููุณูุฑูุง",
"english": "Indeed, with hardship comes ease.",
"tafsir": "ุงููู ูุทู
ุฆู ุนุจุงุฏู...",
"surah": "ุงูุดุฑุญ",
"verse": "5-6"
},
"dua": {
"arabic": "ุงููููููู
ูู ุฅููููู ุฃูุนููุฐู ุจููู...",
"english": "O Allah, I seek refuge...",
"source": "ุตุญูุญ ุงูุจุฎุงุฑู (6363)"
},
"supportMessage": "ูุณุฃู ุงููู ุฃู ููุฑุฌ ูู
ู...",
"meta": {
"processingTime": "1250ms",
"timestamp": "2024-01-15T10:30:00Z"
}
}Returns server status:
{
"status": "healthy",
"verses": 50,
"duas": 30
}Returns database statistics:
{
"verses": 50,
"duas": 30,
"categories": ["sadness", "anxiety", ...]
}- โ
OpenAI API key stored in
.env(never exposed to client) - โ Server-side API calls only
- โ No user data stored or logged
- โ No cookies or tracking
- โ CORS enabled for specified domains only
- โ Input validation and sanitization
- โ Rate limiting (can be configured)
- Node.js - JavaScript runtime
- Express - Web framework
- OpenAI API - GPT-4o-mini for AI analysis
- CORS - Cross-origin resource sharing
- dotenv - Environment variable management
- React 18+ - UI library with hooks
- Lucide React - Icon library
- Tailwind CSS - Utility-first styling
- Google Fonts - Amiri & Cairo Arabic fonts
- GPT-4o-mini - Emotion analysis & support messages
- Structured JSON outputs - Reliable response format
- Fallback local analysis - Regex-based keyword matching
- Multi-emotion detection - Primary + secondary categories
// In server.js, add to verses array:
{
id: 51,
arabic: "...",
english: "...",
tafsir: "...",
surah: "...",
verse: "...",
categories: ["sadness", "hope"],
weight: 9
}// In server.js, add to duas array:
{
id: 31,
arabic: "...",
english: "...",
source: "ุตุญูุญ ุงูุจุฎุงุฑู (1234)",
categories: ["anxiety", "trust"],
weight: 10
}// In emotionCategories object:
sadness: {
keywords: ["ุญุฒู", "ุญุฒูู", "add-more-keywords"],
weight: 1.2 // Higher = more importance
}# Test emotion analysis endpoint
curl -X POST http://localhost:3001/api/analyze \
-H "Content-Type: application/json" \
-d '{"emotionText": "ุฃุดุนุฑ ุจุงูุญุฒู"}'
# Check server health
curl http://localhost:3001/api/health
# View statistics
curl http://localhost:3001/api/stats// Test cases:
"ูุฒุช ูู ุงูู
ุณุงุจูุฉ ูุงูุญู
ุฏ ููู"; // โ gratitude
"ุฃุดุนุฑ ุจุงูุญุฒู ุงูุดุฏูุฏ"; // โ sadness
"ูููุงู ู
ู ุงูู
ุณุชูุจู"; // โ anxiety
"ุบุถุจุงู ุฌุฏุงู ู
ู ูุฐุง ุงูู
ููู"; // โ anger
"ูุฆุณุช ู
ู ูู ุดูุก"; // โ despair
"ูุง ุฃุนุฑู ู
ุงุฐุง ุฃูุนู"; // โ guidance
"ุจุนุฏุช ุนู ุงููู ูุถุนู ุฅูู
ุงูู"; // โ weak_faith
"ู
ุฑูุถ ูุฃุดุนุฑ ุจุฃูู
"; // โ illness- Quranic verses from authentic Islamic sources
- Tafsir based on Al-Tafsir Al-Muyassar and Ibn Kathir
- Hadiths from Sahih Bukhari and Sahih Muslim
- OpenAI for GPT-4o-mini API
- Islamic scholars for their invaluable work
- GitHub Issues: For bugs and feature requests
- Discussions: For questions and ideas
- Email: your-email@example.com
- Al-Tafsir Al-Muyassar (ุงูุชูุณูุฑ ุงูู ูุณุฑ)
- Tafsir Ibn Kathir (ุชูุณูุฑ ุงุจู ูุซูุฑ)
- English translations reviewed by Islamic scholars
- Sahih al-Bukhari (ุตุญูุญ ุงูุจุฎุงุฑู)
- Sahih Muslim (ุตุญูุญ ู ุณูู )
- Sunan Abu Dawud (ุณูู ุฃุจู ุฏุงูุฏ)
- Sunan al-Tirmidhi (ุณูู ุงูุชุฑู ุฐู)
- Sunan an-Nasa'i (ุณูู ุงููุณุงุฆู)
- Sunan Ibn Majah (ุณูู ุงุจู ู ุงุฌู)
- Quranic duas
This application is designed to provide spiritual comfort and Islamic guidance. It is not a substitute for:
- Professional mental health counseling
- Medical advice for physical or mental conditions
- Islamic scholarly consultation for complex religious matters
If you're experiencing severe emotional distress or mental health issues, please seek help from qualified professionals.
- 50 Quranic Verses carefully selected
- 30 Authentic Duas with sources
- 8 Emotion Categories with 150+ keywords
- Smart Selection Algorithm with scoring
- No Repetition System (15-verse buffer)
- AI + Local Fallback for reliability
- Multi-language Support (Arabic + English)
