Agency CRM Full System Documentation

Agency CRM lead generation, email outreach, reply tracking, meeting automation, AI email coordination, landing page, login, and profile settings ka complete system hai.

Node.js + Express Login Protected CRM Encrypted Profile Settings Apollo + LeadGorilla Gemini Email AI Mobile Responsive

Table of Contents

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. Features

Landing Page + Login

Public landing page modules show karta hai. Dashboard login ke baghair hidden rehta hai.

Profile Settings

Portal name, slogan, logo, super admin ID/password aur API settings manage hoti hain.

Encrypted API Settings

Apollo, LeadGorilla, Gemini, Gmail, SMTP, IMAP values encrypted portal_secrets.json mein save hoti hain.

Apollo Fetch

Job title, country, company size aur keywords ke base par Apollo API se leads fetch hoti hain.

LeadGorilla

Business/local lead search ke liye LeadGorilla API integration ready hai.

CSV Import / Export

Leads CSV se import/export hoti hain. Import common headers auto-map karta hai: full name, company, phone/WhatsApp, email, website, source aur service required.

Manual Lead Add

Name, email, phone, website, company, source, service aur requirements/comments ke sath lead add hoti hai.

Pipeline

Stages: New Lead, Contacted, Replied, Meeting, Proposal, Won. Forward/backward stage movement available hai.

Meeting Calendar

Meeting stage mein schedule/reschedule button se manual date/time set kar sakte hain.

Gemini Coordination

AI client reply samajh kar email draft, intent aur next action suggest/send kar sakta hai.

Fallback Safe

Gemini fail ho to old template/keyword system automatically chalta rehta hai.

3. Lead Workflow

Automation ko development ke liye 5 simple lanes mein rakha gaya hai. Har lane ka rule clear hai, taake bugs trace karna easy ho.

LaneAutomatic RuleManual Rule
Lead IntakeApollo, LeadGorilla, CSV ya manual lead save hoti 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 OutreachFirst 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.
RepliesIMAP reply timeline mein save hota hai. AI intent + keyword fallback stage decide karta hai.Confusing reply par AI draft/manual stage buttons use karein.
MeetingsMeeting/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/WonPricing/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.

4. Profile Settings

Profile Settings dashboard ke sidebar mein available hai. Is section mein portal branding, login credentials aur encrypted integrations manage hoti hain.

SectionFieldsNotes
Portal ProfilePortal Name, Slogan, Logo Text, Logo Upload, Favicon/PDF Icon UploadLanding page, sidebar, browser icon aur proposal PDF branding update hoti hai.
Super Admin LoginAdmin ID, current password, new passwordPassword change ke liye current password required hai.
Lead APIsApollo, LeadGorillaSecret values masked hoti hain; blank chorne se old value keep rehti hai.
AI AutomationGemini On/Off, Gemini API Key, Gemini Model, AI Auto Send RepliesGemini key encrypted save hoti hai. Off mode mein normal templates chalte rehte hain.
EmailGmail, custom SMTP, TLS settings, From/Reply-ToGmail ya company SMTP dono supported hain.
RepliesIMAP host, port, user, passClient replies read karne ke liye.
AutomationFirst Email Auto Send, cron, daily limit, delayFirst email on/off yahin se control hoti hai.
MeetingsMeeting base URLUnique 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.

5. Gemini Automation

Gemini integration emails ko client context aur reply ke mutabiq coordinate karta hai. API key Google AI Studio se milti hai.

SettingRecommendedPurpose
GEMINI_API_KEYYour Gemini keyGemini API access.
GEMINI_MODELgemini-2.5-flash-liteEmail drafting and reply classification.
AI_EMAIL_AUTOMATIONtrue or Profile toggle OnOn par first/follow-up emails AI personalize karega. Off par normal saved templates use honge.
AI_AUTO_SEND_REPLIESfalseFalse par AI draft banata hai; true par non-meeting replies auto-send kar sakta hai.

AI Flow

Safe mode ke liye AI_AUTO_SEND_REPLIES=false rakhein. Is mode mein AI sirf draft banayega, email aap button se send karenge.

6. Email System

AI Decision Engine

Chosen AngleEmail TypeAttachment
Website DesignLanding page design concept outreach{company}-website-layout-concept.pdf
SEOWebsite SEO audit report outreach{company}-seo-audit-report.pdf
General website contextWebsite audit outreach{company}-website-seo-audit.pdf
Social / 360 / EcommerceService-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; warna screenshot status show hota hai. Smart first attachment proposal/company profile se alag hoti hai.

First Email Auto Send + Gemini Rule

First Email Auto SendGemini AutomationResult
OnOnSmart first email automatically send hoti hai. Content Gemini personalize karta hai, attachment system choose karta hai.
OnOff/failSmart first email automatically send hoti hai. Built-in audit/layout body aur PDF use hota hai.
OffOnFirst email automatically nahi jati. Manual send par Gemini content/draft generate kar sakta hai.
OffOffFirst email automatically nahi jati. Manual send par saved template use hota hai.
Final gatekeeper First Email Auto Send hai. Ye off ho to Gemini on hone ke bawajood new lead par first email khud se nahi jati.
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, lekin production mein valid certificate better hai.

7. Reply + Meeting Automation

Reply processor IMAP inbox se replies read karta hai, lead email se match karta hai, aur timeline mein body/subject/from/date save karta hai.

Reply IntentSystem Action
Meeting, call, schedule, availableStage Meeting, requested time parse, conflict check. Free slot par meeting link + confirmation email.
Same time already bookedClient ko multiple available slots email. Link tabhi send hota hai jab client option select/done/confirmed reply kare.
RescheduleStage Meeting, pending/manual schedule option.
Pricing/proposalStage Proposal, proposal dropdown se PDF send.
Proposal approved/go ahead/onboardingStage Won, sent proposal PDF timeline/card se view ho sakti hai.
Question/interestedStage Replied, AI draft can be created.
Unsubscribe/not interestedLead unsubscribed, follow-up stops.

Meeting stage mein pipeline card par confirmed meeting time/link show hota hai. Pending multiple time options ke liye timeline mein reschedule proposal record save hota hai.

8. API Routes

RouteMethodPurpose
/api/public-settingsGETLanding/login branding.
/api/auth/loginPOSTSuper admin login.
/api/auth/logoutPOSTLogout session.
/api/settingsGET/PUTPortal profile and login settings.
/api/settings/secretsGET/PUTEncrypted API/SMTP/Gemini settings.
/api/statusGETServer, Apollo, SMTP, schedulers, reply poller status.
/api/leadsGET/POSTList/add leads.
/api/leads/:idPUT/DELETEUpdate/delete one lead.
/api/leads/import-csvPOSTCSV leads import.
/api/leads/:id/send-emailPOSTSelected lead ko next email send.
/api/leads/:id/ai-draftPOSTLatest client reply ke mutabiq AI draft create.
/api/leads/:id/send-ai-draftPOSTSaved AI draft send.
/api/leads/:id/schedule-meetingPOSTManual meeting schedule/reschedule.
/api/apollo/fetchPOSTApollo leads fetch.
/api/leadgorilla/searchPOSTLeadGorilla search.
/api/sources/runPOSTAll lead sources run.
/api/replies/runPOSTReplies manually sync.
/api/templatesGET/PUTEmail templates load/save.

9. Deployment

npm install
node server.js

Production mein PM2 recommended hai:

npm install -g pm2
pm2 start server.js --name agency-crm
pm2 save

10. Troubleshooting

IssueReasonSolution
Cannot POST /api/auth/loginOld server process running.Latest files upload karein aur node server.js/PM2 restart karein.
Gemini email nahi ban rahiGemini toggle off, key/model/quota/network issue.Profile > AI Automation mein toggle/key check karein. Off/fail ho to normal template email automatically send hoti rahegi.
First email nahi jatiFirst Email Auto Send off, email missing, SMTP issue.Profile Automation mein setting on karein, SMTP verify karein.
Apollo errorAPI key missing/invalid.Profile Lead APIs mein Apollo key save karein.
Email certificate mismatchHosting SMTP proxy/cert mismatch.Company SMTP host use karein ya hosting support se outbound Gmail SMTP allow karwayen.
Replies update nahi hotiIMAP missing/wrong, reply from different email.Profile Replies settings check karein aur Sync Replies run karein.
Meeting conflict ignoredOld process or missing booked meeting times.Server restart karein, existing leads mein meetingAtIso records check karein.
Conflict par direct link chali gaiOld code running.Latest replyProcessor.js upload karke Node/PM2 restart karein. New flow pehle alternate time approval email bhejta hai.

11. Important Files

index.html

Landing, login, dashboard layout and tab containers.

css/style.css

Responsive styling for landing, dashboard, tables, pipeline and modals.

js/app.js

Frontend API calls, rendering, settings UI, AI draft buttons, modals.

server.js

Express API, auth, settings, routes, source/email/reply startup.

openaiService.js

Gemini API wrapper, email draft and reply intent logic.

emailService.js

Gmail/custom SMTP transporter and send email logic.

emailScheduler.js

Scheduled follow-up batch emails with AI fallback.

replyProcessor.js

IMAP reply sync, AI reply analysis, meeting automation.

leads_data.json

Lead database.

templates_custom.json

Editable email templates.

portal_settings.json

Portal branding and login settings.

portal_secrets.json + portal_secret.key

Encrypted API/SMTP/Gemini settings and encryption key.

12. Notes