How bribelli/authoreactpythonopenai works
Project Type and Purpose
• This is a full-stack web application (“BetAIPredict”) that offers AI-powered betting predictions.
• Frontend: React + TypeScript SPA, secured by Auth0.
• Backend: Python Flask REST API that integrates with OpenAI.
Main Components
• Frontend SPA
• React (Create React App) entry point (index.tsx) with Auth0Provider
• UI components (e.g., CustomLogin.tsx, App.tsx)
• openaiApi.ts service module calling the Flask API
• Backend API
• app.py: Flask server exposing prediction and profile endpoints
• openai_service.py: wraps OpenAI API calls
• Auth0 (External Identity Provider)
• Manages user login, JWT issuance, token verification
• OpenAI API (External AI Service)
• Provides the core prediction engine
• Environment & Deployment
• Frontend .env.local for Auth0 config
• Backend environment variables (OPENAI_API_KEY, AUTH0_SECRET)
Relationships and Data Flows
• User browser → React SPA (over HTTPS)
• React SPA → Auth0 (OAuth/OpenID Connect) → user JWT
• React SPA → Flask API (includes JWT in Authorization header)
• Flask API → verifies JWT via Auth0 secrets → secures endpoints
• Flask API → OpenAI Service → returns AI-generated predictions
• Flask API → responds to SPA with JSON payload
Architectural Patterns and Principles
• Single-Page Application (SPA) pattern for rich client interactivity
• RESTful API on the backend following separation of concerns
• Externalized secrets via environment variables for secure configuration
• Service abstractions (openai_service.py and openaiApi.ts) for API decoupling
• Auth0 middleware ensures stateless authentication and token validation