A comprehensive, production-ready full-stack application for AI-powered revenue generation with subscriptions, payments, chat bot, and book publishing.
- Monthly Plan: $8.99/month with 100 credits
- Yearly Plan: $49.99/year with 1,200 credits (42% savings!)
- Automatic renewal
- Easy cancellation
- Plan upgrades with proration
- Real-time chat interface
- 5 categories: Math, Puzzles, General, Problem-solving, Knowledge
- Credit-based system (1 credit per message)
- Chat history & search
- Ready for OpenAI integration
- Browse & search published books
- 6 book categories
- 5-star review system
- Purchase books with Stripe
- Publish your own books (publisher role)
- Sales analytics dashboard
- Stripe Card Payments: Instant & secure
- Bank Transfer: Direct to Phu Quoc Nguyen (TD Bank)
- Credit Packages: One-time purchases
- Subscriptions: Recurring monthly or yearly
- Automatic invoice generation
- JWT token-based authentication
- Bcrypt password hashing
- Protected API endpoints
- Role-based access control
- CORS protection
- Security headers (Helmet.js)
- Webhook verification
- User registration with roles (user/publisher)
- Profile management
- Credit tracking
- Activity logging
- Subscription status
- Node.js v14+ (or v18+ recommended)
- MongoDB local or Atlas connection
- Stripe Account (for payments)
- npm or yarn
cd /workspaces/phu-ai-revenue-automation# Install backend dependencies
npm install
# Install frontend dependencies
cd client && npm install && cd ..# Create .env file
cp .env.example .env
# Edit .env with your settings:
nano .envRequired Environment Variables:
# Server
PORT=5000
NODE_ENV=development
# Database
MONGODB_URI=mongodb://localhost:27017/phu-ai-revenue
# Stripe (Get from https://dashboard.stripe.com)
STRIPE_SECRET_KEY=sk_test_your_key
STRIPE_PUBLISHABLE_KEY=pk_test_your_key
STRIPE_WEBHOOK_SECRET=whsec_your_secret
STRIPE_MONTHLY_PRICE_ID=price_your_monthly_id
STRIPE_YEARLY_PRICE_ID=price_your_yearly_id
# JWT
JWT_SECRET=your_jwt_secret_here
JWT_EXPIRE=7d
# Payment Recipient
BANK_ACCOUNT_NAME=Phu Quoc Nguyen
BANK_ACCOUNT_NUMBER=43821 004 6369582
BANK_NAME=TD Bank Canada TrustTerminal 1 - Backend:
npm run devTerminal 2 - Frontend:
cd client && npm startFrontend: http://localhost:3000
Backend: http://localhost:5000/api
- Create Stripe Account: https://stripe.com
- Get API Keys:
- Go to Developers β API Keys
- Copy Secret Key (sk_test_...)
- Copy Publishable Key (pk_test_...)
- Create Products:
- Monthly: $8.99, 100 credits
- Yearly: $49.99, 1,200 credits
- Set Up Webhook:
- Endpoint:
https://yourdomain.com/api/payments/webhook - Events: subscription updates, payment events
- Endpoint:
- Add Keys to
.env
π Detailed Stripe Setup Guide
Option 1: Local MongoDB
# Install MongoDB (macOS)
brew install mongodb-community
# Start MongoDB
brew services start mongodb-community
# Connection string
MONGODB_URI=mongodb://localhost:27017/phu-ai-revenueOption 2: MongoDB Atlas (Cloud)
- Go to https://www.mongodb.com/cloud/atlas
- Create cluster
- Get connection string
- Update
.env:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/phu-ai-revenuephu-ai-revenue-automation/
βββ server.js # Express entry point
βββ package.json # Backend dependencies
βββ .env.example # Environment template
βββ .gitignore
β
βββ src/
β βββ config/
β β βββ database.js # MongoDB connection
β β βββ stripe.js # Stripe client
β β
β βββ models/
β β βββ User.js # User authentication
β β βββ Subscription.js # Recurring subscriptions
β β βββ ChatMessage.js # Chat history
β β βββ Book.js # Book catalog
β β βββ Payment.js # Payment tracking
β β
β βββ controllers/
β β βββ authController.js # Login/register
β β βββ chatController.js # AI chat logic
β β βββ subscriptionController.js # Subscriptions
β β βββ paymentController.js # One-time payments
β β βββ bookController.js # Book management
β β
β βββ routes/
β β βββ auth.js # Auth endpoints
β β βββ chat.js # Chat endpoints
β β βββ subscriptions.js # Subscription endpoints
β β βββ payments.js # Payment endpoints
β β βββ books.js # Book endpoints
β β
β βββ middleware/
β βββ auth.js # JWT verification
β βββ errorHandler.js # Error handling
β
βββ client/
β βββ package.json # Frontend dependencies
β βββ public/
β β βββ index.html
β βββ src/
β βββ App.js # Main app with routing
β βββ index.js # React entry
β β
β βββ components/
β β βββ Navbar.js # Navigation
β β
β βββ pages/
β βββ Login.js # Auth
β βββ Register.js # Registration
β βββ Dashboard.js # User dashboard
β βββ ChatBot.js # Chat interface
β βββ Books.js # Book listing
β βββ BookDetail.js # Book view
β βββ Subscription.js # Subscription page
β βββ Payment.js # Payment page
β βββ PublishBook.js # Publisher form
β
βββ Documentation/
βββ README.md # This file
βββ SUBSCRIPTION.md # Subscription docs
βββ STRIPE_SETUP.sh # Stripe guide
βββ API.md # API reference
βββ SETUP.md # Detailed setup
βββ DEVELOPMENT.md # Dev guide
βββ PROJECT_SUMMARY.md # Tech details
POST /api/auth/register # Create account
POST /api/auth/login # Login
GET /api/auth/me # Get profile (protected)
PUT /api/auth/update # Update profile (protected)
GET /api/subscriptions/plans # View plans
POST /api/subscriptions/create # Subscribe (protected)
GET /api/subscriptions/current # Get current sub (protected)
POST /api/subscriptions/cancel # Cancel (protected)
POST /api/subscriptions/resume # Resume (protected)
PUT /api/subscriptions/update-plan # Change plan (protected)
GET /api/subscriptions/history # History (protected)
POST /api/chat/send # Send message (protected)
GET /api/chat/history # Get history (protected)
DELETE /api/chat/clear # Clear history (protected)
PUT /api/chat/:messageId/useful # Mark useful (protected)
POST /api/payments/create-intent # Create payment (protected)
POST /api/payments/confirm # Confirm payment (protected)
GET /api/payments/history # Payment history (protected)
GET /api/payments/packages # Credit packages
GET /api/payments/bank-details # Bank info
POST /api/payments/webhook # Stripe webhook
GET /api/books # List books
GET /api/books/:bookId # Book details
POST /api/books/create # Create (protected)
PUT /api/books/:bookId # Edit (protected)
PUT /api/books/:bookId/publish # Publish (protected)
POST /api/books/:bookId/purchase # Buy (protected)
POST /api/books/:bookId/review # Review (protected)
GET /api/books/publisher/:publisherId/books
DELETE /api/books/:bookId # Delete (protected)
- Price: $8.99/month
- Credits: 100 credits
- Renewal: Automatic monthly
- Perfect for: Testing & casual users
- Price: $49.99/year
- Credits: 1,200 credits
- Renewal: Automatic yearly
- Savings: 42% vs monthly ($107.88)
- Perfect for: Regular users & best value
- Account Holder: Phu Quoc Nguyen
- Bank: TD Bank Canada Trust
- Account: 43821 004 6369582
- Transit: 00000
Successful Payment:
Card: 4242 4242 4242 4242
Expiry: 12/25 (any future)
CVC: 123 (any 3 digits)
Failed Payment:
Card: 4000 0000 0000 0002
Expiry: 12/25 (any future)
CVC: 123 (any 3 digits)
User Account:
Email: user@test.com
Password: test1234
Publisher Account:
Email: publisher@test.com
Password: test1234
# Create Procfile
echo "web: node server.js" > Procfile
# Deploy to Heroku
heroku create phu-ai-backend
git push heroku main
# Set environment variables
heroku config:set MONGODB_URI=your_uri
heroku config:set STRIPE_SECRET_KEY=your_key
# ... more variablescd client
# Deploy to Vercel
vercel
# Or Netlify
netlify deployNODE_ENV=production
STRIPE_SECRET_KEY=sk_live_your_live_key
STRIPE_PUBLISHABLE_KEY=pk_live_your_live_key
# Use live API keys, not test keys!# Backend with hot reload
npm run dev
# Frontend
cd client && npm startnpm test# Backend
npm run build
# Frontend
cd client && npm run build- π§ Setup Guide
- π API Reference
- π³ Subscription Guide
- π΄ Stripe Setup
- π¨βπ» Development Guide
- ποΈ Project Summary
- β‘ Quick Index
β Authentication & Authorization
- JWT token-based auth
- Bcrypt password hashing (10 rounds)
- Protected API routes
- Role-based access control
β Data Protection
- CORS enabled
- Security headers (Helmet.js)
- Input validation
- Error handling
β Payment Security
- Stripe PCI compliance
- Webhook signature verification
- Secure payment processing
- Transaction logging
β Database Security
- MongoDB connection pooling
- Index optimization
- Data encryption at rest
{
name, email, password (hashed),
role (user/publisher/admin),
avatar, credits, totalSpent,
stripeCustomerId,
subscription, subscriptionStatus,
subscriptionPlan, subscriptionExpiry,
publishedBooks[], chatHistory[],
lastLogin, createdAt, updatedAt
}{
userId, plan (monthly/yearly), price,
stripeSubscriptionId, status,
currentPeriodStart, currentPeriodEnd,
monthlyCredits, yearlyCredits,
cancelledAt, autoRenewal,
metadata, createdAt, updatedAt
}{
title, description, author, publisherId,
price, category, coverImage, fileUrl,
pages, rating, reviews[],
totalSales, totalRevenue,
isPublished, purchasedBy[],
createdAt, updatedAt
}{
userId, stripePaymentId, amount, status,
type (credits/book_purchase/subscription),
itemId, creditsAdded, paymentMethod,
recipientName, recipientBankAccount,
recipientBankName, metadata,
createdAt, updatedAt
}{
userId, question, answer, category,
conversationId, isUseful, creditUsed,
createdAt, updatedAt
}# Check MongoDB is running
sudo systemctl status mongodb
# Or for Homebrew
brew services list
# Start MongoDB
brew services start mongodb-community- Verify keys in
.envfile - Ensure keys are in correct format (sk_test_ or pk_test_)
- Check Stripe dashboard for active API keys
- Don't share keys publicly
- Verify webhook URL is publicly accessible
- Check webhook secret in
.env - Monitor webhook deliveries in Stripe dashboard
- Look for error logs in server
# Kill process on port 5000
lsof -ti:5000 | xargs kill -9
# Or use different port
PORT=3001 npm run dev- π§ Email: support@phuai.com
- π Issue Tracker: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π Documentation: See docs/ folder
MIT License - feel free to use for commercial projects
- Email notifications
- SMS alerts
- Mobile app (React Native)
- Advanced analytics
- Team management
- API quotas
- Custom branding
- White-label solution
Built with β€οΈ for Phu Quoc Nguyen
Version: 1.0.0
Last Updated: January 26, 2026
Status: Production Ready β