Skip to content

phuquoc81/phu-ai-revenue-automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Phu AI Revenue Automation Platform

A comprehensive, production-ready full-stack application for AI-powered revenue generation with subscriptions, payments, chat bot, and book publishing.

πŸš€ Features

πŸ’³ Flexible Subscription System

  • 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

πŸ€– AI Chat Assistant

  • 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

πŸ“š Publisher Book Store

  • Browse & search published books
  • 6 book categories
  • 5-star review system
  • Purchase books with Stripe
  • Publish your own books (publisher role)
  • Sales analytics dashboard

πŸ’° Multiple Payment Options

  • 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

πŸ” Enterprise Security

  • JWT token-based authentication
  • Bcrypt password hashing
  • Protected API endpoints
  • Role-based access control
  • CORS protection
  • Security headers (Helmet.js)
  • Webhook verification

πŸ‘₯ User Management

  • User registration with roles (user/publisher)
  • Profile management
  • Credit tracking
  • Activity logging
  • Subscription status

πŸ“‹ Requirements

  • Node.js v14+ (or v18+ recommended)
  • MongoDB local or Atlas connection
  • Stripe Account (for payments)
  • npm or yarn

⚑ Quick Start (5 Minutes)

1. Clone Repository

cd /workspaces/phu-ai-revenue-automation

2. Install Dependencies

# Install backend dependencies
npm install

# Install frontend dependencies
cd client && npm install && cd ..

3. Configure Environment

# Create .env file
cp .env.example .env

# Edit .env with your settings:
nano .env

Required 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 Trust

4. Start Servers

Terminal 1 - Backend:

npm run dev

Terminal 2 - Frontend:

cd client && npm start

5. Access Application

Frontend: http://localhost:3000
Backend:  http://localhost:5000/api

πŸ”§ Setup Guide

Stripe Configuration

  1. Create Stripe Account: https://stripe.com
  2. Get API Keys:
    • Go to Developers β†’ API Keys
    • Copy Secret Key (sk_test_...)
    • Copy Publishable Key (pk_test_...)
  3. Create Products:
    • Monthly: $8.99, 100 credits
    • Yearly: $49.99, 1,200 credits
  4. Set Up Webhook:
    • Endpoint: https://yourdomain.com/api/payments/webhook
    • Events: subscription updates, payment events
  5. Add Keys to .env

πŸ“– Detailed Stripe Setup Guide

MongoDB Configuration

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-revenue

Option 2: MongoDB Atlas (Cloud)

  1. Go to https://www.mongodb.com/cloud/atlas
  2. Create cluster
  3. Get connection string
  4. Update .env:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/phu-ai-revenue

πŸ“ Project Structure

phu-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

πŸ”Œ API Endpoints

Authentication

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)

Subscriptions

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)

Chat

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)

Payments (One-time)

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

Books

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)

πŸ“– Full API Documentation


πŸ’³ Subscription Plans

Monthly Subscription

  • Price: $8.99/month
  • Credits: 100 credits
  • Renewal: Automatic monthly
  • Perfect for: Testing & casual users

Yearly Subscription

  • Price: $49.99/year
  • Credits: 1,200 credits
  • Renewal: Automatic yearly
  • Savings: 42% vs monthly ($107.88)
  • Perfect for: Regular users & best value

Bank Transfer Option

  • Account Holder: Phu Quoc Nguyen
  • Bank: TD Bank Canada Trust
  • Account: 43821 004 6369582
  • Transit: 00000

πŸ§ͺ Testing

Test Stripe Cards

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)

Test Accounts

User Account:
  Email: user@test.com
  Password: test1234

Publisher Account:
  Email: publisher@test.com
  Password: test1234

πŸš€ Deployment

Backend Deployment (Heroku/Railway)

# 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 variables

Frontend Deployment (Vercel/Netlify)

cd client

# Deploy to Vercel
vercel

# Or Netlify
netlify deploy

Environment Setup for Production

NODE_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!

πŸ› οΈ Development

Run in Development Mode

# Backend with hot reload
npm run dev

# Frontend
cd client && npm start

Run Tests

npm test

Build for Production

# Backend
npm run build

# Frontend
cd client && npm run build

πŸ“š Documentation


πŸ”’ Security Features

βœ… 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

πŸ“Š Database Schemas

User Schema

{
  name, email, password (hashed),
  role (user/publisher/admin),
  avatar, credits, totalSpent,
  stripeCustomerId,
  subscription, subscriptionStatus,
  subscriptionPlan, subscriptionExpiry,
  publishedBooks[], chatHistory[],
  lastLogin, createdAt, updatedAt
}

Subscription Schema

{
  userId, plan (monthly/yearly), price,
  stripeSubscriptionId, status,
  currentPeriodStart, currentPeriodEnd,
  monthlyCredits, yearlyCredits,
  cancelledAt, autoRenewal,
  metadata, createdAt, updatedAt
}

Book Schema

{
  title, description, author, publisherId,
  price, category, coverImage, fileUrl,
  pages, rating, reviews[],
  totalSales, totalRevenue,
  isPublished, purchasedBy[],
  createdAt, updatedAt
}

Payment Schema

{
  userId, stripePaymentId, amount, status,
  type (credits/book_purchase/subscription),
  itemId, creditsAdded, paymentMethod,
  recipientName, recipientBankAccount,
  recipientBankName, metadata,
  createdAt, updatedAt
}

ChatMessage Schema

{
  userId, question, answer, category,
  conversationId, isUseful, creditUsed,
  createdAt, updatedAt
}

🚨 Troubleshooting

MongoDB Connection Failed

# Check MongoDB is running
sudo systemctl status mongodb

# Or for Homebrew
brew services list

# Start MongoDB
brew services start mongodb-community

Stripe Keys Not Working

  • Verify keys in .env file
  • Ensure keys are in correct format (sk_test_ or pk_test_)
  • Check Stripe dashboard for active API keys
  • Don't share keys publicly

Webhook Not Receiving Events

  • Verify webhook URL is publicly accessible
  • Check webhook secret in .env
  • Monitor webhook deliveries in Stripe dashboard
  • Look for error logs in server

Port Already in Use

# Kill process on port 5000
lsof -ti:5000 | xargs kill -9

# Or use different port
PORT=3001 npm run dev

πŸ“ž Support & Community

  • πŸ“§ Email: support@phuai.com
  • πŸ› Issue Tracker: GitHub Issues
  • πŸ’¬ Discussions: GitHub Discussions
  • πŸ“š Documentation: See docs/ folder

πŸ“„ License

MIT License - feel free to use for commercial projects


🎯 Roadmap

  • Email notifications
  • SMS alerts
  • Mobile app (React Native)
  • Advanced analytics
  • Team management
  • API quotas
  • Custom branding
  • White-label solution

πŸ™ Contributors

Built with ❀️ for Phu Quoc Nguyen


Version: 1.0.0
Last Updated: January 26, 2026
Status: Production Ready βœ…

About

The app phu ai revenue automation help user pushlisher book and stripe payments and chatbot ai

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors