# sid-thephysicskid/microsaas-example architecture

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

- Interactive diagram: https://gitdiagram.com/sid-thephysicskid/microsaas-example
- Repository: https://github.com/sid-thephysicskid/microsaas-example

## Overview

##### Main Components

a. Client Layer:
- Streamlit Frontend (Main UI component)
- PDF Upload Interface
- Authentication UI (Google Login)
- Subscription Management UI

b. Authentication & Payment Layer:
- Google OAuth 2.0 Service
- Stripe Payment Processing
- Buy Me A Coffee Integration (alternative payment system)
- Aggregate Authentication Handler

c. Core Application Layer:
- PDF Processing Engine
- Question Generation Service
- Answer Generation Service

d. External Services:
- OpenAI API
- Google Cloud Platform
- Stripe API
- Buy Me A Coffee API

##### Component Relationships

- User → Streamlit Frontend
- Streamlit Frontend → Authentication Layer
- Authentication Layer → External Auth Services
- Streamlit Frontend → Payment Layer
- Payment Layer → External Payment Services
- Streamlit Frontend → Core Application Layer
- Core Application Layer → OpenAI API

##### Specific Implementation Details

- main.py (Entry point)
- st_paywall/ directory components:
- aggregate_auth.py (Authentication orchestrator)
- google_auth.py (Google OAuth handler)
- stripe_auth.py (Stripe integration)
- buymeacoffee_auth.py (Alternative payment handler)

##### Data Flow Indicators

Following flows:
1. User Authentication Flow:
User → Google Login → OAuth Verification → Application Access

2. Payment Flow:
User → Subscription Button → Stripe/BMC → Payment Confirmation → Access Grant

3. Core Application Flow:
PDF Upload → Text Processing → OpenAI Integration → Question Generation → Answer Generation

##### Configuration Elements

A section showing configuration dependencies:
- .streamlit/secrets.toml (API keys and credentials)
- Environment variables
- External service configurations

##### Technical Stack Indicators

Technology badges or labels for:
- Python
- Streamlit
- Langchain
- OpenAI
- Chroma
- PyPDF2
- Google OAuth
- Stripe

##### External Services Layer

- Maintain clear separation of concerns between authentication, payment, and core functionality
- Modular nature of the payment system (Stripe/BMC)
- Security boundaries between components
- Error handling and fallback paths
- Monitoring and logging points

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef auth fill:#2ecc71,stroke:#27ae60,color:white
    classDef payment fill:#e67e22,stroke:#d35400,color:white
    classDef core fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef config fill:#f1c40f,stroke:#f39c12,color:black

    %% User Interface Layer
    subgraph UI
        User(("User"))
        Frontend["Streamlit Frontend"]:::frontend
        PDFUpload["PDF Upload Interface"]:::frontend
        AuthUI["Authentication UI"]:::frontend
        SubUI["Subscription UI"]:::frontend
    end

    %% Authentication & Payment Layer
    subgraph AuthPayment
        AuthHandler["Aggregate Auth Handler"]:::auth
        GoogleAuth["Google OAuth Service"]:::auth
        StripeHandler["Stripe Payment Processing"]:::payment
        BMCHandler["Buy Me A Coffee Handler"]:::payment
    end

    %% Core Application Layer
    subgraph CoreApp
        PDFProcessor["PDF Processing Engine"]:::core
        QGenerator["Question Generation Service"]:::core
        AGenerator["Answer Generation Service"]:::core
        MainApp["Main Application"]:::core
    end

    %% External Services Layer
    subgraph External
        OpenAI["OpenAI API"]:::external
        GCP["Google Cloud Platform"]:::external
        StripeAPI["Stripe API"]:::external
        BMCAPI["Buy Me A Coffee API"]:::external
    end

    %% Configuration
    subgraph Config
        Secrets["Secrets & Config"]:::config
    end

    %% Relationships
    User --> Frontend
    Frontend --> PDFUpload
    Frontend --> AuthUI
    Frontend --> SubUI
    
    AuthUI --> AuthHandler
    AuthHandler --> GoogleAuth
    GoogleAuth --> GCP
    
    SubUI --> StripeHandler
    SubUI --> BMCHandler
    StripeHandler --> StripeAPI
    BMCHandler --> BMCAPI
    
    PDFUpload --> PDFProcessor
    PDFProcessor --> QGenerator
    QGenerator --> OpenAI
    QGenerator --> AGenerator
    AGenerator --> OpenAI
    
    MainApp --> PDFProcessor
    MainApp --> AuthHandler
    
    AuthHandler --> Secrets
    StripeHandler --> Secrets
    BMCHandler --> Secrets

    %% Click Events
    click MainApp "https://github.com/sid-thephysicskid/microsaas-example/blob/master/main.py"
    click GoogleAuth "https://github.com/sid-thephysicskid/microsaas-example/blob/master/st_paywall/google_auth.py"
    click StripeHandler "https://github.com/sid-thephysicskid/microsaas-example/blob/master/st_paywall/stripe_auth.py"
    click BMCHandler "https://github.com/sid-thephysicskid/microsaas-example/blob/master/st_paywall/buymeacoffee_auth.py"
    click AuthHandler "https://github.com/sid-thephysicskid/microsaas-example/blob/master/st_paywall/aggregate_auth.py"
    click Secrets "https://github.com/sid-thephysicskid/microsaas-example/blob/master/.streamlit/secrets.toml.example"
```
