Skip to content

Unknown27s/Astro_CRM

Repository files navigation

πŸš€ AstroCRM v3.0 β€” AI-Powered Customer Relationship Management

React TypeScript Vite TailwindCSS Node.js Express PostgreSQL AI License

A full-stack, AI-powered retail CRM with ML analytics, sales pipeline, real-time dashboards, and an intelligent chatbot β€” built with React, Node.js, PostgreSQL, and ASI:One AI.

Created by AH AH Coders Γ— Claude AI 🀝


✨ Key Features

🧠 AI-Powered Intelligence

  • DB-Aware AI Chatbot β€” Ask natural language questions like "Who is my top customer?" and get answers from your real database
  • AI Description Helper β€” ✨ AI Suggest button auto-writes professional descriptions for activities, deals, and notes
  • AI Dashboard Summary β€” One-click executive briefing of your business health
  • AI Segment Explainer β€” Plain-English explanations of your customer clusters
  • AI Campaign Generator β€” Generates SMS marketing copy tailored to your audience
  • AI Customer Risk Assessment β€” Predicts individual customer churn probability
  • AI Sales Forecasting β€” Revenue projection with confidence scoring
  • AI Report Summaries β€” Executive-level automated report narratives

πŸ“Š 7 ML Analytics Modules

Module What It Does
K-Means Segmentation Groups customers into behavioral clusters (Champions, Loyal, At-Risk, Lost)
RFM Analysis Scores every customer on Recency, Frequency, and Monetary value (1-5 scale)
Churn Risk Prediction Identifies at-risk customers with risk scores and recommended actions
Customer LTV Predicts 3-year Customer Lifetime Value with tier classification
Product Affinity Discovers which products are frequently purchased together
Revenue Forecasting 90-day trend analysis with 7-day moving average and projections
Cohort Analysis Monthly acquisition cohorts with retention rates and revenue tracking

🀝 Sales Pipeline (Deals)

  • Visual Kanban-style pipeline with drag-and-drop stage changes
  • Stages: Lead β†’ Qualified β†’ Proposal β†’ Negotiation β†’ Closed Won / Closed Lost
  • Auto-sync: When a deal is won/lost, customer's total_spent and total_purchases are automatically updated
  • Deal stats visible on Customer detail page (Won / Active / Lost counts with values)

πŸ‘₯ Customer 360Β° View

  • Contact information with phone, email, location
  • Purchase History with itemized breakdowns
  • Deals & Pipeline section showing deal stats and list
  • Notes & Interactions β€” Add, pin, delete notes by type (General, Call, Meeting, Complaint, Feedback, Internal)
  • Activities & Follow-Ups β€” View linked tasks, calls, meetings with overdue alerts

πŸ“‹ Tasks & Activities

  • Stats dashboard (Total / Pending / Completed / Overdue)
  • Filter by type (Call, Meeting, Email, Task, Follow-up, Note)
  • Filter by priority and completion status
  • Toggle completion, CRUD operations via modals
  • Associate activities with customers

πŸ“ˆ Dashboard & Insights

  • Real-time KPIs: Total Customers, Active, Revenue, VIP count
  • Revenue trend charts and growth metrics
  • AI-powered dashboard summary with one click

πŸ“£ Campaigns

  • SMS/Email campaign management
  • Audience targeting by customer segment
  • AI-generated campaign messages
  • Send tracking per customer

πŸ“„ Reports

  • PDF and Excel export
  • Sales, Customer, and Segment reports
  • AI-generated executive summaries
  • Monthly business reports with date filtering

πŸ›’ Online Store

  • Public storefront with product display
  • Cart, checkout, and order management
  • Coupon/discount code system
  • QR code generation for products

πŸ“¦ Inventory / Stock Management

  • Product catalog with SKU tracking
  • Stock in/out transactions with audit trail
  • Low stock alerts
  • Barcode scanning support

πŸ“€ Data Import

  • CSV and XLSX file import for customers and products
  • Google Sheets auto-sync (every 60 seconds)
  • Smart field mapping

πŸ‘€ User Roles

  • Admin / Manager / Viewer role-based access
  • JWT authentication with token refresh

πŸ›  Technology Stack

Backend

Technology Purpose
Node.js + TypeScript Server runtime
Express.js 4 REST API framework
PostgreSQL 17 Relational database
pg (node-postgres) Database driver with connection pooling
ASI:One (OpenAI-compatible) AI/ML inference engine
pdfkit PDF report generation
exceljs Excel report generation
jsonwebtoken JWT authentication
multer File upload handling
csv-parser CSV file parsing
node-cron Scheduled tasks

Frontend

Technology Purpose
React 19 + TypeScript UI framework
Vite 7 Build tool and dev server
React Router v7 Client-side routing
Tailwind CSS 3 Utility-first CSS framework
Recharts Charts and data visualization
Lucide React Icon library (200+ icons)
Axios HTTP client with interceptors
react-hot-toast Toast notifications
Radix UI Headless UI primitives (Dialog, Dropdown)
html2canvas + jspdf Client-side PDF generation

Database

Table Purpose
users User accounts and authentication
customers Customer contact information and aggregates
purchases Purchase/order records with itemized details
products Product catalog with prices and stock
inventory_transactions Stock movement audit trail
campaigns Email/SMS marketing campaigns
campaign_sends Individual campaign message records
customer_segments K-means clustering results
store_settings Online store configuration
online_orders Orders from online storefront
coupons Discount codes and promotions
deals Sales pipeline deals
activities CRM activity tracking (calls, meetings, tasks)
notes Customer interaction notes

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • PostgreSQL 17
  • Git

Setup

# 1. Clone the project
git clone <your-repo-url>
cd Astro_CRM

# 2. Create PostgreSQL database
psql -U postgres -c "CREATE DATABASE astrocrm;"

# 3. Configure backend
cd backend
cp .env.example .env   # Edit with your DB credentials
npm install

# 4. Configure frontend
cd ../frontend
npm install

# 5. Start backend (Terminal 1)
cd backend
npm run dev
# β†’ Listening on port 3001

# 6. Start frontend (Terminal 2)
cd frontend
npm run dev
# β†’ http://localhost:5173

Environment Variables (backend/.env)

PORT=3001
JWT_SECRET=your-secret-key
PG_USER=postgres
PG_PASSWORD=postgres
PG_HOST=localhost
PG_PORT=5432
PG_DATABASE=astrocrm
ASI_ONE_API_KEY=your-asi-one-api-key  # For AI features

πŸ“ Project Structure

Astro_CRM/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ database/
β”‚   β”‚   β”‚   β”œβ”€β”€ db.ts                # PostgreSQL connection & helpers
β”‚   β”‚   β”‚   └── schema-pg.sql        # Database schema
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   β”œβ”€β”€ ai.ts                # AI endpoints (chat, summary, forecast)
β”‚   β”‚   β”‚   β”œβ”€β”€ aihelper.ts          # ASI:One integration + DB query templates
β”‚   β”‚   β”‚   β”œβ”€β”€ analytics.ts         # ML analytics (K-means, RFM, Churn, LTV, etc.)
β”‚   β”‚   β”‚   β”œβ”€β”€ activities.ts        # Activity/task tracking
β”‚   β”‚   β”‚   β”œβ”€β”€ campaigns.ts         # Marketing campaigns
β”‚   β”‚   β”‚   β”œβ”€β”€ customers.ts         # Customer CRUD + deal sync
β”‚   β”‚   β”‚   β”œβ”€β”€ deals.ts             # Sales pipeline + customer sync
β”‚   β”‚   β”‚   β”œβ”€β”€ insights.ts          # Business insights/metrics
β”‚   β”‚   β”‚   β”œβ”€β”€ notes.ts             # Customer notes/interactions
β”‚   β”‚   β”‚   β”œβ”€β”€ products.ts          # Product catalog
β”‚   β”‚   β”‚   β”œβ”€β”€ purchases.ts         # Purchase tracking
β”‚   β”‚   β”‚   └── reports.ts           # PDF/Excel report generation
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── mlService.ts         # K-means clustering implementation
β”‚   β”‚   └── server.ts                # Express server entry point
β”‚   └── package.json
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ ui/                  # Reusable UI components (Button, Card, Modal, etc.)
β”‚   β”‚   β”‚   β”œβ”€β”€ AIAssistant.tsx      # Floating AI chatbot panel
β”‚   β”‚   β”‚   └── Layout.tsx           # App layout with sidebar navigation
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.tsx        # Main dashboard with KPIs
β”‚   β”‚   β”‚   β”œβ”€β”€ Customers.tsx        # Customer 360Β° (Notes, Deals, Activities, Purchases)
β”‚   β”‚   β”‚   β”œβ”€β”€ Deals.tsx            # Sales pipeline Kanban board
β”‚   β”‚   β”‚   β”œβ”€β”€ Activities.tsx       # Task & activity management
β”‚   β”‚   β”‚   β”œβ”€β”€ Analytics.tsx        # 7 ML analytics modules (tabbed)
β”‚   β”‚   β”‚   β”œβ”€β”€ Campaigns.tsx        # Campaign management
β”‚   β”‚   β”‚   β”œβ”€β”€ Insights.tsx         # Business insights & trends
β”‚   β”‚   β”‚   β”œβ”€β”€ Reports.tsx          # Report generation
β”‚   β”‚   β”‚   └── ...                  # Stock, Store, Import, Users pages
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── api.ts               # Centralized API service layer
β”‚   β”‚   └── App.tsx                  # Root component with routing
β”‚   └── package.json
β”œβ”€β”€ sample-data/                     # Sample CSV/XLSX files for testing
└── README.md                        # This file

πŸ“‘ API Endpoints

Authentication

Method Endpoint Description
POST /api/auth/register Register new user
POST /api/auth/login Login and get JWT
GET /api/auth/me Get current user

Customers

Method Endpoint Description
GET /api/customers List all customers
GET /api/customers/:id Get customer + deals + purchases
POST /api/customers Create customer
PUT /api/customers/:id Update customer
DELETE /api/customers/:id Delete customer

Deals Pipeline

Method Endpoint Description
GET /api/deals List all deals
POST /api/deals Create deal
PUT /api/deals/:id Update deal (auto-syncs customer)
PATCH /api/deals/:id/stage Change deal stage (Kanban drag)
DELETE /api/deals/:id Delete deal

AI Intelligence

Method Endpoint Description
POST /api/ai/chat DB-aware AI chatbot
POST /api/ai/autocomplete AI description helper
POST /api/ai/dashboard-summary AI dashboard briefing
POST /api/ai/explain-analytics AI segment explanation
POST /api/ai/generate-campaign AI campaign copy
POST /api/ai/customer-risk AI churn assessment
POST /api/ai/sales-forecast AI revenue prediction
POST /api/ai/report-summary AI report narrative

ML Analytics

Method Endpoint Description
POST /api/analytics/segment-customers Run K-means clustering
GET /api/analytics/segments Get segment results
GET /api/analytics/rfm-analysis RFM scoring
GET /api/analytics/churn-risk Churn prediction
GET /api/analytics/customer-ltv Customer LTV
GET /api/analytics/product-affinity Product affinity
GET /api/analytics/revenue-forecast Revenue forecasting
GET /api/analytics/cohort-analysis Cohort analysis

πŸ§ͺ Sample Data

Sample data files in sample-data/ folder:

  • sample-customers-large.csv β€” 550 realistic customer records
  • sample-products-large.csv β€” 550 product records with inventory

Import via the Import Data page.


πŸ”’ Security

  • JWT-based authentication with token expiry
  • Password hashing with bcrypt
  • Role-based access control (Admin / Manager / Viewer)
  • API route protection via middleware

πŸ“œ License

MIT License


πŸ‘¨β€πŸ’» Authors

Created by AH AH Coders Γ— Claude AI 🀝

Built with ❀️ using React, Node.js, PostgreSQL, TypeScript, ASI:One AI, and Machine Learning


πŸ†˜ Support

  1. Check the Troubleshooting section in the old README
  2. Check backend logs: cd backend && npm run dev
  3. Check frontend console: Browser β†’ F12 β†’ Console tab
  4. Check database: psql -U postgres -d astrocrm

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors