A modern, full-stack stock trading application built with Next.js 15, featuring real-time market data, personalized watchlists, AI-powered email automation, and comprehensive stock analytics. Deployed on Cloudflare Workers for global edge performance.
Deployed URL: https://ai-trading-app.bhaskarg.workers.dev/
The homepage features:
- Market Overview with interactive charts and real-time stock data
- Stock Heatmap showing market performance by industry
- Top Stories with latest financial news
- Market Data Widget displaying key financial metrics
The stock detail page provides:
- Real-time Price Data with candlestick charts
- Technical Analysis with AI-powered insights
- Company Profile and financial metrics
- Watchlist Management with one-click add/remove
- Comprehensive Financials including P/E ratios, market cap, and more
- Secure authentication with Better Auth
- Email/password sign-up and sign-in
- User profile management with investment preferences
- Session management with Cloudflare D1
- Live stock prices and market data via Finnhub API
- Interactive TradingView widgets for charts and analysis
- Market overview with heatmaps and sector performance
- Real-time price updates and percentage changes
- Create and manage personalized stock watchlists
- Add/remove stocks with one-click functionality
- Real-time price tracking for watchlisted stocks
- Market cap and performance metrics
- Advanced stock search with autocomplete
- Quick access to stock details
- Filter by industry and sector
- Search command palette for power users
- Welcome Emails: Personalized welcome messages using Gemini AI based on user investment profile
- Daily News Summaries: Automated daily email digests with AI-summarized market news
- Personalized content based on user watchlist and preferences
- Scheduled cron jobs for automated delivery
- Dark theme optimized for financial data
- Responsive design for all devices
- Shadcn UI components for consistent design
- Toast notifications for user feedback
- Smooth animations and transitions
- Next.js 15 - React framework with App Router
- React 19 - UI library
- TypeScript - Type-safe development
- Tailwind CSS 4 - Utility-first styling
- Shadcn UI - Component library
- TradingView Widgets - Financial charts and data visualization
- React Hook Form - Form management
- Lucide React - Icon library
- Cloudflare Workers - Edge computing platform
- Cloudflare D1 - SQLite database at the edge
- Better Auth - Authentication framework
- Drizzle ORM - Type-safe database queries
- OpenNext.js - Next.js adapter for Cloudflare
- Finnhub API - Real-time stock market data
- Inngest - Background job processing and automation
- Google Gemini AI - AI-powered content generation
- Nodemailer - Email delivery service
- TradingView - Financial widgets and charts
- Bun - Fast JavaScript runtime and package manager
- Wrangler - Cloudflare Workers CLI
- TypeScript - Static type checking
- ESLint - Code linting
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER JOURNEY β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. SIGN UP / SIGN IN
β
βββΊ Better Auth (Cloudflare D1)
β βββΊ User Session Management
β
βββΊ Inngest Event: app/user.created
β
βββΊ sendSignUpEmail Function
β
βββΊ Step 1: Get User Profile
β βββΊ Country, Investment Goals, Risk Tolerance
β
βββΊ Step 2: AI Content Generation
β βββΊ Gemini AI generates personalized welcome message
β
βββΊ Step 3: Send Welcome Email
βββΊ Nodemailer delivers personalized email
2. DASHBOARD INTERACTION
β
βββΊ Market Overview Widget
β βββΊ TradingView Widget (Real-time data)
β
βββΊ Stock Heatmap
β βββΊ TradingView Widget (Sector performance)
β
βββΊ Top Stories
β βββΊ Finnhub API (Market news)
β
βββΊ Market Data Table
βββΊ Finnhub API (Stock quotes)
3. STOCK SEARCH & DETAILS
β
βββΊ Search Command
β βββΊ Finnhub API (Symbol search)
β
βββΊ Stock Detail Page
β
βββΊ Symbol Info Widget
βββΊ Candlestick Chart
βββΊ Technical Analysis
βββΊ Company Profile
βββΊ Financials Data
βββΊ All via TradingView & Finnhub APIs
4. WATCHLIST MANAGEMENT
β
βββΊ Add to Watchlist
β βββΊ Cloudflare D1 (Store watchlist item)
β
βββΊ Remove from Watchlist
βββΊ Cloudflare D1 (Delete watchlist item)
5. AUTOMATED DAILY NEWS (Cron: 12:00 PM Daily)
β
βββΊ sendDailyNewsSummary Function
β
βββΊ Step 1: Get All Users
β βββΊ Query Cloudflare D1
β
βββΊ Step 2: Fetch User Watchlists
β βββΊ Get symbols for each user
β
βββΊ Step 3: Fetch News Articles
β βββΊ For each user:
β β βββΊ Get news for watchlist symbols
β β βββΊ Fallback to general market news
β βββΊ Limit to 6 articles per user
β
βββΊ Step 4: AI News Summarization
β βββΊ Gemini AI summarizes articles per user
β
βββΊ Step 5: Send Email Digests
βββΊ Nodemailer sends personalized summaries
User Sign Up
β
βΌ
Inngest Event Triggered
β
βΌ
βββββββββββββββββββββββββββββββββββββββ
β sendSignUpEmail Function β
βββββββββββββββββββββββββββββββββββββββ€
β β’ Extract user profile data β
β β’ Generate AI prompt β
β β’ Call Gemini AI API β
β β’ Generate personalized intro β
β β’ Send welcome email via Nodemailerβ
βββββββββββββββββββββββββββββββββββββββ
Cron Schedule: 0 12 * * * (12:00 PM Daily)
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β sendDailyNewsSummary Function β
ββββββββββββββββββββββββββββββββββββββββββββββββ€
β Step 1: Get All Users β
β βββΊ Query D1 database β
β β
β Step 2: Fetch User-Specific News β
β βββΊ For each user: β
β β βββΊ Get watchlist symbols β
β β βββΊ Fetch news for symbols β
β β βββΊ Fallback to general news β
β βββΊ Limit to 6 articles β
β β
β Step 3: AI Summarization β
β βββΊ For each user's articles: β
β β βββΊ Generate summary prompt β
β β βββΊ Call Gemini AI API β
β β βββΊ Generate news summary β
β βββΊ Store summaries β
β β
β Step 4: Send Email Digests β
β βββΊ Send personalized emails via β
β Nodemailer β
ββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββ
β Browser β
ββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β Cloudflare Workers (Edge) β
β βββββββββββββββββββββββββββ β
β β Next.js App Router β β
β β β’ Server Components β β
β β β’ Server Actions β β
β β β’ API Routes β β
β βββββββββββββββββββββββββββ β
ββββββββ¬ββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββ
β β
βΌ βΌ
ββββββββββββββββ ββββββββββββββββββββ
β Cloudflare D1β β External APIs β
β (SQLite DB) β ββββββββββββββββββββ€
β β β β’ Finnhub API β
β β’ Users β β β’ TradingView β
β β’ Sessions β β β’ Gemini AI β
β β’ Watchlist β ββββββββββββββββββββ
ββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
β Inngest β
β (Background β
β Jobs) β
β β
β β’ Email Jobs β
β β’ Cron Jobs β
β β’ AI Processing β
ββββββββββββββββββββ
- Node.js 20+ or Bun
- Cloudflare account
- Finnhub API key
- Google Gemini API key
- Inngest account
Create a .dev.vars file:
BETTER_AUTH_SECRET=your-secret-key
BETTER_AUTH_URL=http://localhost:3000
FINNHUB_API_KEY=your-finnhub-key
GEMINI_API_KEY=your-gemini-key
INNGEST_EVENT_KEY=your-inngest-key
INNGEST_SIGNING_KEY=your-signing-key
NODEMAILER_EMAIL=your-email
NODEMAILER_PASSWORD=your-app-password# Install dependencies
bun install
# Set up Cloudflare D1 database
npx wrangler d1 create ticker_d1
# Run migrations
npx wrangler d1 execute ticker_d1 --local --file=./migrations/0001_better-auth-tables.sql
npx wrangler d1 execute ticker_d1 --local --file=./migrations/0002_watchlist-table.sql
# Start development server
bun run dev
# In another terminal, start Inngest dev server
npx inngest-cli dev# Build and deploy to Cloudflare
bun run deploy- User authentication and profile data
- Investment preferences (goals, risk tolerance, industry)
- User session management
- Token-based authentication
- User watchlist items
- Stock symbols and company names
- Timestamps for tracking
- Real-time stock quotes
- Company profiles
- Market news
- Symbol search
- Interactive charts
- Technical analysis
- Market overview
- Stock heatmaps
- Personalized email content generation
- News summarization
- User preference analysis
ai-trading-app/
βββ app/ # Next.js App Router
β βββ (auth)/ # Authentication routes
β βββ (root)/ # Protected routes
β βββ api/ # API routes
βββ components/ # React components
β βββ ui/ # Shadcn UI components
β βββ forms/ # Form components
βββ lib/
β βββ actions/ # Server actions
β βββ better-auth/ # Auth configuration
β βββ inngest/ # Background jobs
β βββ nodemailer/ # Email service
βββ hooks/ # React hooks
βββ schemas/ # Drizzle schemas
βββ migrations/ # Database migrations
βββ public/ # Static assets
- β Edge Deployment: Full-stack app deployed on Cloudflare Workers for global edge performance
- β Real-Time Data: Live stock prices and market data integration
- β AI Automation: Automated email system with AI-powered personalization
- β Type Safety: End-to-end TypeScript with Drizzle ORM
- β Modern Auth: Secure authentication with Better Auth
- β Responsive Design: Mobile-first responsive UI
- β Performance: Optimized with Next.js 15 and edge computing
This project is licensed under the MIT License - see the LICENSE file for details.
Bhaskar Guthula
- Portfolio: https://bhaskar.guthula.cc
- GitHub: @BhaskarGuthula
- TradingView for financial widgets
- Finnhub for market data API
- Cloudflare for edge infrastructure
- Inngest for background job processing
- Shadcn UI for component library
Built with β€οΈ using Next.js, Cloudflare Workers, and modern web technologies

