Full System Documentation
1. Overview
Backend server.js Express par run hota hai, frontend index.html, css/style.css, aur js/app.js se browser mein chalta hai. Data JSON files mein store hota hai.
System public landing page show karta hai. Dashboard access sirf login ke baad milta hai. Default login pehli dafa admin / admin123 hai, jise Profile Settings se change karna chahiye.
Latest system mobile responsive hai: dashboard, pipeline, tables, settings, modals aur landing page mobile par adjust hote hain.
2. Lead Workflow Lanes
| Lane | Automatic Rule | Manual Rule |
| Lead Intake | Apollo, LeadGorilla, CSV ya manual lead save hoti hai. Manual form category save karta hai. CSV import common headers auto-map karta hai: full name, company, phone/WhatsApp, email, website, source aur service required. Duplicate email/API id skip hota hai. | Missing/incorrect fields All Leads se edit honge. |
| First Outreach | First Email Auto Send on ho to new valid-email lead par AI Decision Engine lead/source/service/website analyze karta hai aur best angle choose karta hai: website audit, website layout, social media audit/planning, SEO strategy, 360 marketing ya ecommerce development. Stage Contacted hota hai. | First Email Auto Send off ho to Outreach/All Leads se manual send. |
| Replies | IMAP reply timeline mein save hota hai. WhatsApp QR inbound queries bhi lead timeline mein save hoti hain. AI intent + keyword fallback stage decide karta hai. Agar client pooche ke Media Feathers ko project kyun dein, system company benefits, case studies link aur portfolio link ke sath profile reply bhejta hai. | Confusing reply par AI draft/manual stage buttons use karein. |
| Meetings | Meeting/call intent par stage Meeting. Time missing ho to availability ask email. Time booked ho to options email. Confirmed option par final meeting link. | Pipeline Meeting card se schedule/reschedule manually. |
| Proposals/Won | Pricing/proposal reply par stage Proposal. Client approval only after sent proposal moves to Won. | Proposal PDF hamesha manually send hota hai. |
Development safety: run npm run test:automation after automation changes. Ye reply intent, proposal-to-won guard, meeting conflict slots, pending option selection aur reply cleanup verify karta hai.
3. Profile Settings
| Section | Fields | Notes |
| Portal Profile | Portal Name, Slogan, Logo Text, Logo Upload, Favicon/PDF Icon Upload | Landing page, sidebar, browser icon aur proposal PDF branding update hoti hai. |
| Super Admin Login | Admin ID, current password, new password | Password change ke liye current password required hai. |
| Lead APIs | Apollo, LeadGorilla | Secret values masked hoti hain; blank chorne se old value keep rehti hai. |
| AI Automation | Gemini On/Off, Gemini API Key, Gemini Model, AI Auto Send Replies | Gemini key encrypted save hoti hai. Off mode mein normal templates chalte rehte hain. |
| Email | Gmail, custom SMTP, TLS settings, From/Reply-To | Gmail ya company SMTP dono supported hain. |
| Replies | IMAP host, port, user, pass | Client replies read karne ke liye. |
| Automation | First Email Auto Send, cron, daily limit, delay | First email on/off yahin se control hoti hai. |
| Meetings | Meeting base URL | Unique meeting links ke liye. |
Encrypted files portal_secrets.json aur portal_secret.key ko server par safe rakhna hai. portal_secret.key delete ho gaya to old encrypted values decrypt nahi hongi.
4. Gemini Automation Setup
| Setting | Recommended | Purpose |
GEMINI_API_KEY | Your Gemini key | Gemini API access. |
GEMINI_MODEL | gemini-2.5-flash-lite | Email drafting and reply classification. |
AI_EMAIL_AUTOMATION | true or Profile toggle On | On par first/follow-up emails AI personalize karega. Off par normal saved templates use honge. |
AI_AUTO_SEND_REPLIES | false | False par AI draft banata hai; true par non-meeting replies auto-send kar sakta hai. |
AI Processing Flow:
- New lead email: AI Decision Engine lead context se service angle choose karta hai aur usi angle ka email/PDF send karta hai. Web design lead ko business category ke mutabiq landing page design concept PDF milta hai. SEO lead ko website SEO audit report PDF milti hai. Ye proposal ya company profile nahi hota.
- Follow-up email: scheduler saved
aiServiceAngle aur aiFollowupPlan ke mutabiq contextual follow-up generate karta hai.
- Client reply: AI intent classify karta hai: meeting, reschedule, pricing/proposal, approved/onboarding/won, interested, company/profile/why Media Feathers question, not interested, unsubscribe.
- AI draft: lead modal/timeline mein
Send AI Draft button ke sath show hoti hai.
- Gemini off/fail: normal template email aur keyword classifier automatically use hota hai.
Safe mode ke liye AI_AUTO_SEND_REPLIES=false rakhein. Is mode mein AI sirf draft banayega, email aap button se send karenge.
5. Reporting
- Reporting menu: email sent, opener/opened email, bounced email, replies aur proposal sent metrics one place par show hoti hain.
- Recent events:
email_log.json aur lead timelines merge hote hain.
- WhatsApp separate: WhatsApp reporting aur QR login separate WhatsApp menu mein hain.
6. WhatsApp QR
- WhatsApp QR Login: WhatsApp menu se QR start/refresh/stop hota hai. Session local
whatsapp-web-session/ folder mein save hota hai.
- 6 minute interval: QR session connected ho to outbound WhatsApp queue default
WHATSAPP_QR_MESSAGE_INTERVAL_MS=360000 use karti hai.
- New QR / Relink: Mobile se device unlink ho jaye ya status stale lage to local session clear karke fresh QR generate hota hai.
- WhatsApp Chats: WhatsApp menu mein QR linked phone account ki real chat list aur selected conversation ka thread show hota hai.
- Proposal follow-up: Proposal wali WhatsApp chats analyze karke next follow-up QR/Cloud sender se queue/send hota hai.
7. Email System Config
AI Decision Engine
| Chosen Angle | Email Type | Attachment |
| Website Design | Landing page design concept outreach | {company}-website-layout-concept.pdf |
| SEO | Website SEO audit report outreach | {company}-seo-audit-report.pdf |
| General website context | Website audit outreach | {company}-website-seo-audit.pdf |
| Social / 360 / Ecommerce | Service-specific pitch and follow-up lane | {company}-social-media-audit.pdf, {company}-social-media-strategy-design.pdf, {company}-360-marketing-plan.pdf, {company}-ecommerce-development-plan.pdf |
Decision saved fields: websiteAudit, websiteAuditSummary, websiteAuditIssues, websiteSocialLinks, aiServiceAngle, aiOfferType, aiReason, aiConfidence, aiFollowupPlan. Website ho to system page open karke status, speed signal, title, meta description, headings, canonical, viewport, schema, image alt issues aur social links scan karta hai. PDF mein actual findings, priority issues aur business-category strategy include hoti hai. Screenshot Playwright available ho to capture hota hai to PDF mein actual screenshot page embed hota hai; warna screenshot status show hota hai. Smart first attachment proposal/company profile se alag hoti hai.
| First Email Auto Send | Gemini Automation | Result |
| On | On | Smart first email automatically send hoti hai. Content Gemini personalize karta hai, attachment system audit/design PDF choose karta hai; proposal/company profile nahi. |
| On | Off/fail | Smart first email automatically send hoti hai. Built-in landing concept/SEO audit/body aur PDF use hota hai. |
| Off | On | First email automatically nahi jati. Manual send par Gemini content/draft generate kar sakta hai. |
| Off | Off | First email automatically nahi jati. Manual send par saved template use hota hai. |
Gmail SMTP blocked/proxy ho to company SMTP use karein: EMAIL_PROVIDER=smtp, SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS.
Certificate mismatch aaye to hosting SMTP settings check karein. Temporary bypass SMTP_TLS_REJECT_UNAUTHORIZED=false hai.
6. Troubleshooting Quick Reference
| Issue | Reason | Solution |
| Cannot POST /api/auth/login | Old server process running. | Restart server: pm2 restart agency-crm or node server.js. |
| Gemini email nahi ban rahi | Gemini key or quota issue. | Verify key in Profile settings. Falls back to static template automatically. |
| First email nahi jati | First Email Auto Send is disabled. | Enable First Email Auto Send in Profile Automation settings. |
| Email certificate mismatch | SMTP reject unauthorized enabled. | Set SMTP_TLS_REJECT_UNAUTHORIZED=false in .env as a temp bypass. |
| Replies update nahi hoti | IMAP connection details invalid. | Verify IMAP details and check connection logs on server. |