একটি আধুনিক এবং সুন্দর AI চ্যাট অ্যাপ্লিকেশন যা React এবং Firebase দিয়ে তৈরি
এই প্রজেক্টটি Create React App দিয়ে তৈরি করা হয়েছে।
- Node.js (v14 বা তার উপরে)
- npm বা yarn
- Firebase account
npm installRoute: src/pages/HomePage.jsx
এটি অ্যাপ্লিকেশনের মূল পেজ। ব্যবহারকারীর লগইন স্ট্যাটাস অনুযায়ী দুটি ভিন্ন ভিউ দেখায়:
- যখন ব্যবহারকারী লগইন থাকে
- সম্পূর্ণ চ্যাট ইন্টারফেস
- সাইডবার, হেডার এবং চ্যাট বক্স
- নতুন চ্যাট শুরু করার অপশন
- যখন ব্যবহারকারী লগইন থাকে না
- লিমিটেড চ্যাট ফিচার
- রেজিস্টার/লগইন বাটন
- গেস্ট হিসেবে চ্যাট করার সুবিধা
Route: src/pages/ChatPage.jsx
এটি অ্যাপ্লিকেশনের মূল চ্যাট পেজ যেখানে AI এর সাথে কথোপকথন হয়।
- AI Models: Auto (Gemini) এবং Image Generation
- Real-time Chat: Firebase Firestore ব্যবহার করে
- Message History: পূর্বের কথোপকথন সংরক্ষণ
- Model Selection: Auto বা Images মডেল বেছে নেওয়ার সুবিধা
- Responsive Design: মোবাইল এবং ডেস্কটপে সমানভাবে কাজ করে
- ব্যবহারকারী মেসেজ টাইপ করে
- মেসেজ Firebase এ সংরক্ষিত হয়
- AI রেসপন্স তৈরি করে
- AI রেসপন্স ইউজারকে দেখানো হয়
- পুরো কথোপকথন সংরক্ষিত থাকে
Route: src/pages/Auth/LogIn.jsx
- Email/Password Login: সাধারণ লগইন
- Google Authentication: Google OAuth সুবিধা
- Responsive Layout: ডেস্কটপে ইমেজ সেকশন, মোবাইলে শুধু ফর্ম
- Auto Redirect: লগইন থাকলে হোম পেজে রিডাইরেক্ট
Route: src/pages/Auth/Register.jsx
- Multi-step Registration: ধাপে ধাপে রেজিস্ট্রেশন
- Form Validation: ইমেইল এবং পাসওয়ার্ড ভ্যালিডেশন
- Profile Setup: নাম, ইমেইল, পাসওয়ার্ড সেটআপ
- Email Verification: ইমেইল ভেরিফিকেশন প্রসেস
src/
├── pages/ # 🏠 Main Application Pages
│ ├── HomePage.jsx # Main landing page
│ ├── ChatPage.jsx # AI chat interface
│ ├── AccountPage.jsx # Account management
│ └── Auth/ # 🔐 Authentication Pages
│ ├── LogIn.jsx # User login
│ └── Register.jsx # User registration
├── components/ # 🧩 Reusable Components
│ ├── Auth/ # Authentication components
│ ├── Chat/ # Chat interface components
│ ├── Home/ # Home page components
│ └── GuestHome/ # Guest user components
├── context/ # 🔄 React Context
│ ├── AppContext.jsx # Main app state
│ └── firebase/ # Firebase configuration
├── hooks/ # 🎣 Custom Hooks
└── utils/ # 🛠️ Utility Functions
// User types message in ChatBox component
const handleSubmit = (e) => {
e.preventDefault();
if (!text.trim()) return;
onSend(text); // Calls ChatPage's onSend function
};// ChatPage.jsx - Main chat logic
function onSend(text) {
// 1. Save user message to Firebase
const userChat = {
type: "user",
text: text.trim(),
model: modelInfo.title, // "Auto" or "Images"
createdAt: Timestamp.now(),
imgLink: ""
};
// 2. Update Firestore with user message
await updateDoc(chatDataRef, {
chats: arrayUnion(userChat)
});
// 3. Generate AI response based on model
if (modelInfo.title === "Auto") {
// Text generation using Gemini AI
const aiResponse = await AI.geminiText(prompt, contextMsgs);
} else if (modelInfo.title === "Images") {
// Image generation using AI
const aiResponse = await AI.genImage(text);
}
}// src/context/AI.js
geminiText: async (prompt, msgs = []) => {
const chat = ai.chats.create({
name: "Lonas",
model: "gemini-2.5-flash", // Google's latest model
history: [...msgs], // Conversation context
});
const response = await chat.sendMessage({ message: prompt });
return {
type: "data",
role: "model",
content: response.text,
};
};// Uses external API for image generation
genImage: async (prompt) => {
const imgURL = `https://api.a0.dev/assets/image?text=${encodeURIComponent(
prompt
)}&aspect=1:1&seed=${Date.now()}`;
const res = await fetch(imgURL);
return {
type: "data",
role: "model",
link: res.url,
};
};// Firestore Structure
chats/
{userId}/
msg/
{chatId}/
- title: "Chat title (first 30 chars)"
- chats: [
{
type: "user" | "ai",
text: "message content",
model: "Auto" | "Images",
createdAt: Timestamp,
imgLink: "image URL or empty string"
}
]- Auto-growing textarea: Dynamically adjusts height based on content
- Model selector: Dropdown for choosing AI model (Auto/Images)
- Send button: Disabled during AI processing
- Responsive design: Adapts to different screen sizes
- Message rendering: Displays user and AI messages differently
- Auto-scroll: Automatically scrolls to latest message
- Loading states: Shows different loading animations for text/image generation
- Typewriter effect: Text appears word by word for better UX
- Markdown support: Full markdown rendering with syntax highlighting
- Copy functionality: Users can copy AI responses
- Image display: Shows generated images with download option
- Right-aligned: User messages appear on the right side
- Image support: Can display attached images
- Copy functionality: Users can copy their own messages
const [text, setText] = useState(""); // Current input text
const [msgs, setmsgs] = useState([]); // All messages in chat
const [lodingMsg, setLodingMsg] = useState(false); // Loading state
const [AiMsgLoading, setAiMsgLoading] = useState(false); // AI text loading
const [AiImageLoading, setAiImageLoading] = useState(false); // AI image loading
const [modelInfo, setModelInfo] = useState({
title: "Auto",
icon: <ModelIcon size={16} />,
}); // Selected AI model- Lazy loading: Messages loaded only when chat is accessed
- Context preservation: AI maintains conversation context
- Error handling: Graceful fallbacks for API failures
- Loading indicators: Clear feedback during AI processing
- Firebase listeners: Automatic UI updates when messages change
- Optimistic updates: UI updates immediately, then syncs with database
- Auto-scroll management: Smooth scrolling to new messages
- Use case: General conversations, questions, text generation
- Features: Context-aware responses, code generation, explanations
- Processing: Text-based input/output
- Use case: Image generation from text descriptions
- Features: Creative image creation, visual content
- Processing: Text input → Image output
- Text sanitization: Prevents XSS attacks
- Length limits: Prevents excessive API usage
- Rate limiting: Built-in protection against spam
- API fallbacks: Alternative responses when AI fails
- User notifications: Clear error messages via toast
- Graceful degradation: App continues working even if some features fail
- Gemini AI: Google's Gemini model for text generation
- Image Generation: AI-powered image creation
- Auto Model Selection: Intelligent model switching
- Authentication: Google Auth + Email/Password
- Firestore Database: Real-time chat storage
- User Management: Profile and chat history
- Dark Theme: Beautiful dark mode interface
- Responsive Design: Works on all devices
- Smooth Animations: Enhanced user experience
- Toast Notifications: Real-time feedback
- Route Protection: Authenticated routes
- Input Validation: Secure form handling
- Error Handling: Graceful error management
- Frontend: React 18, React Router v6
- Styling: Tailwind CSS
- Backend: Firebase (Auth, Firestore)
- AI: Google Gemini API
- State Management: React Context API
- Icons: Custom SVG Components
Made with ❤️ using React and Firebase