Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions backend/controllers/assistant.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const User = require('../models/User');

// Placeholder for future LLM integration
// You can replace this function with a call to OpenAI/Gemini, etc.
async function generateAssistantReply(prompt, context) {
// Simple rules-based responses using available context until LLM is integrated
const lines = [];
if (context?.streak != null) {
lines.push(`Your current streak is ${context.streak} day${context.streak === 1 ? '' : 's'}.`);
if (context.streak >= 7) {
lines.push('🔥 Great job keeping a 7+ day streak! Keep it going!');
}
}
if (Array.isArray(context?.goals) && context.goals.length) {
lines.push(`You have ${context.goals.length} active goal${context.goals.length === 1 ? '' : 's'}.`);
}
if (Array.isArray(context?.activity)) {
const last7 = context.activity.slice(-7);
lines.push(`Last 7 entries recorded: ${last7.length}.`);
}
if (context?.timeSpent) {
lines.push(`Time spent: ${context.timeSpent}.`);
}
if (lines.length === 0) {
lines.push('I can summarize your DevSync activity once you start logging!');
}
lines.push('\nTip: Ask me things like "What is my current streak?" or "Summarize my week."');
return lines.join(' ');
}

exports.postAssistantMessage = async (req, res) => {
try {
const { message } = req.body;
if (!message || typeof message !== 'string') {
return res.status(400).json({ errors: [{ msg: 'Message is required' }] });
}

// Load user activity context
const user = await User.findById(req.user.id).select('-password');
if (!user) {
return res.status(404).json({ errors: [{ msg: 'User not found' }] });
}

const context = {
streak: user.streak,
timeSpent: user.timeSpent,
activity: user.activity,
goals: user.goals,
// Extend with commits/problemsSolved when available
};

const reply = await generateAssistantReply(message, context);

return res.json({
reply,
insights: {
streak: user.streak,
timeSpent: user.timeSpent,
goalsCount: Array.isArray(user.goals) ? user.goals.length : 0,
recentActivityCount: Array.isArray(user.activity) ? user.activity.slice(-7).length : 0
}
});
} catch (err) {
console.error('Assistant error:', err.message);
return res.status(500).json({ errors: [{ msg: 'Server Error' }] });
}
};

// GET health/check + sample nudge
exports.getAssistantNudge = async (req, res) => {
try {
const user = await User.findById(req.user.id).select('-password');
if (!user) {
return res.status(404).json({ errors: [{ msg: 'User not found' }] });
}
const msg = user.streak >= 1
? `🔥 You maintained a ${user.streak}-day streak, keep it going!`
: 'Let’s kick off your first activity today!';
res.json({ message: msg });
} catch (err) {
console.error('Assistant nudge error:', err.message);
res.status(500).json({ errors: [{ msg: 'Server Error' }] });
}
};


15 changes: 15 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
"devDependencies": {
"nodemon": "^3.1.7"
}
}
}
14 changes: 14 additions & 0 deletions backend/routes/assistant.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const express = require('express');
const router = express.Router();
const auth = require('../middleware/auth');
const { postAssistantMessage, getAssistantNudge } = require('../controllers/assistant.controller');

// POST /api/assistant/message -> returns assistant reply
router.post('/message', auth, postAssistantMessage);

// GET /api/assistant/nudge -> small tip/motivation
router.get('/nudge', auth, getAssistantNudge);

module.exports = router;


12 changes: 12 additions & 0 deletions backend/services/emailService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ const transporter = nodemailer.createTransport({

// Verification email
const sendVerificationEmail = async (email, verificationCode) => {

//Email Verifer GET Request being sent
const {data} = await axios.get(`https://api.hunter.io/v2/email-verifier?email=${email}&api_key=${process.env.EMAIL_VERIFIER_API_KEY}`);
//Verfying the response type
if(data.data.status === 'invalid')
{
//Invalid Email hence Sending a Error Message
console.log('Invalid Email ID')
//Sending the Invalid Email Id Error
throw new Error('Invalid Email ID');
}

const mailOptions = {
from: process.env.EMAIL_USER,
to: email,
Expand Down
2 changes: 1 addition & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import FloatingSupportButton from "./Components/ui/Support";

function Home() {
const [showTop, setShowTop] = useState(false);
const [assistantOpen, setAssistantOpen] = useState(false);

useEffect(() => {
const handleScroll = () => {
Expand Down
97 changes: 97 additions & 0 deletions frontend/src/Components/ui/ChatAssistant.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React, { useEffect, useRef, useState } from 'react';

const ChatAssistant = ({ open, onClose }) => {
const [messages, setMessages] = useState([
{ role: 'assistant', content: 'Hi! I can summarize your DevSync activity and nudge your productivity. Ask me anything.' }
]);
const [input, setInput] = useState('');
const [loading, setLoading] = useState(false);
const scrollRef = useRef(null);

useEffect(() => {
if (open) {
// Optionally fetch a nudge
const token = localStorage.getItem('token');
if (!token) return;
fetch(`${import.meta.env.VITE_API_URL}/api/assistant/nudge`, {
headers: { 'x-auth-token': token }
}).then(async (res) => {
if (!res.ok) return;
const data = await res.json();
setMessages((prev) => [...prev, { role: 'assistant', content: data.message }]);
}).catch(() => {});
}
}, [open]);

useEffect(() => {
if (scrollRef.current) {
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
}
}, [messages, open]);

const send = async () => {
const text = input.trim();
if (!text) return;
setInput('');
setMessages((prev) => [...prev, { role: 'user', content: text }]);

const token = localStorage.getItem('token');
if (!token) {
setMessages((prev) => [...prev, { role: 'assistant', content: 'Please log in to use the assistant.' }]);
return;
}

setLoading(true);
try {
const res = await fetch(`${import.meta.env.VITE_API_URL}/api/assistant/message`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-auth-token': token
},
body: JSON.stringify({ message: text })
});
const data = await res.json();
if (!res.ok) throw new Error(data?.errors?.[0]?.msg || 'Request failed');
setMessages((prev) => [...prev, { role: 'assistant', content: data.reply }]);
} catch (e) {
setMessages((prev) => [...prev, { role: 'assistant', content: e.message || 'Something went wrong.' }]);
} finally {
setLoading(false);
}
};

if (!open) return null;

return (
<div className="fixed inset-0 z-50 flex items-center justify-center">
<div className="absolute inset-0 bg-black/40" onClick={onClose} />
<div className="relative bg-[var(--card)] text-[var(--card-foreground)] w-full max-w-lg h-[70vh] rounded-2xl shadow-xl border border-[var(--border)] flex flex-col">
<div className="flex items-center justify-between px-4 py-3 border-b border-[var(--border)]">
<div className="font-semibold">DevSync Assistant</div>
<button onClick={onClose} className="text-[var(--muted-foreground)] hover:text-[var(--primary)]">✕</button>
</div>
<div ref={scrollRef} className="flex-1 overflow-y-auto p-4 space-y-3">
{messages.map((m, i) => (
<div key={i} className={`max-w-[85%] ${m.role === 'user' ? 'ml-auto bg-[var(--primary)] text-[var(--primary-foreground)]' : 'mr-auto bg-[var(--muted)] text-[var(--muted-foreground)]'} px-3 py-2 rounded-xl whitespace-pre-wrap`}>{m.content}</div>
))}
{loading && <div className="mr-auto bg-[var(--muted)] text-[var(--muted-foreground)] px-3 py-2 rounded-xl">Thinking…</div>}
</div>
<div className="p-3 border-t border-[var(--border)] flex gap-2">
<input
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && send()}
placeholder="Ask about streaks, activity, goals…"
className="flex-1 px-3 py-2 rounded-lg bg-[var(--card)] border border-[var(--input)] focus:outline-none focus:ring-2 focus:ring-[var(--primary)]"
/>
<button onClick={send} className="px-4 py-2 rounded-lg bg-[var(--primary)] text-[var(--primary-foreground)] hover:bg-[var(--accent)]">Send</button>
</div>
</div>
</div>
);
};

export default ChatAssistant;


20 changes: 20 additions & 0 deletions frontend/src/Components/ui/ChatBubble.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';

const ChatBubble = ({ onClick }) => {
return (
<button
onClick={onClick}
aria-label="Open chat assistant"
className="fixed top-24 right-6 z-50 h-12 w-12 rounded-full shadow-lg flex items-center justify-center bg-[var(--primary)] text-[var(--primary-foreground)] hover:bg-[var(--accent)] transition-colors"
>
{/* Simple chat icon */}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" className="h-6 w-6" fill="currentColor">
<path d="M12 3C6.477 3 2 6.94 2 11.8c0 2.3 1.111 4.383 2.92 5.914-.083.77-.36 1.86-1.096 2.915-.16.224-.038.543.23.586 1.71.279 3.105-.26 4.018-.856A11.31 11.31 0 0 0 12 20.6c5.523 0 10-3.94 10-8.8S17.523 3 12 3z" />
</svg>
</button>
);
};

export default ChatBubble;