# bribelli/authoreactpythonopenai architecture

> Architecture diagram of the GitHub repository bribelli/authoreactpythonopenai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bribelli/authoreactpythonopenai
- Repository: https://github.com/bribelli/authoreactpythonopenai

## Overview

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

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        Browser["User Browser"]:::frontend
        subgraph "React SPA"
            Index["index.tsx"]:::frontend
            App["App.tsx"]:::frontend
            CustomLogin["CustomLogin.tsx"]:::frontend
            AuthCSS["AuthComponents.css"]:::frontend
            openaiApi["openaiApi.ts"]:::frontend
        end
    end

    %% Application Layer
    subgraph "Application Layer"
        FlaskAPI["Flask API (app.py)"]:::backend
        Auth0Validation["Auth0 JWT Validation"]:::backend
        openaiService["OpenAI Service (openai_service.py)"]:::backend
        Requirements["requirements.txt"]:::backend
    end

    %% External Services Layer
    subgraph "External Services"
        Auth0["Auth0"]:::external
        OpenAIAPI["OpenAI API"]:::external
    end

    %% Data Flows
    Browser -->|"loads SPA"| Index
    Browser -->|"Login request (OAuth)"| Auth0
    Auth0 -->|"JWT token"| Browser
    Browser -->|"uses token"| App
    App -->|"calls /predict (Bearer token)"| FlaskAPI
    FlaskAPI -->|"verify JWT"| Auth0Validation
    FlaskAPI -->|"requests prediction (REST)"| openaiService
    openaiService -->|"POST /v1/completions"| OpenAIAPI
    FlaskAPI -->|"JSON response"| App

    %% Click Events
    click Index "https://github.com/bribelli/authoreactpythonopenai/blob/main/frontend/src/index.tsx"
    click App "https://github.com/bribelli/authoreactpythonopenai/blob/main/frontend/src/App.tsx"
    click CustomLogin "https://github.com/bribelli/authoreactpythonopenai/blob/main/frontend/src/components/CustomLogin.tsx"
    click AuthCSS "https://github.com/bribelli/authoreactpythonopenai/blob/main/frontend/src/components/AuthComponents.css"
    click openaiApi "https://github.com/bribelli/authoreactpythonopenai/blob/main/frontend/src/services/openaiApi.ts"
    click FlaskAPI "https://github.com/bribelli/authoreactpythonopenai/blob/main/backend/app.py"
    click openaiService "https://github.com/bribelli/authoreactpythonopenai/blob/main/backend/openai_service.py"
    click Requirements "https://github.com/bribelli/authoreactpythonopenai/blob/main/backend/requirements.txt"
    click package "https://github.com/bribelli/authoreactpythonopenai/blob/main/frontend/package.json"
    click public "https://github.com/bribelli/authoreactpythonopenai/blob/main/frontend/public/index.html"

    %% Legend or Styles
    classDef frontend fill:#CCF,stroke:#333,stroke-width:1px
    classDef backend fill:#CFC,stroke:#333,stroke-width:1px
    classDef external fill:#EEE,stroke:#333,stroke-width:1px
```
