# howard115/phrasal-verb-app-v2 architecture

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

- Interactive diagram: https://gitdiagram.com/howard115/phrasal-verb-app-v2
- Repository: https://github.com/howard115/phrasal-verb-app-v2

## Overview

##### Main Components

A. Frontend Layer (Streamlit):
- Three sub-components for the main pages:
- Story Generator
- Favorite Stories
- API Key Configuration
- Use blue coloring to distinguish frontend components

B. Backend Layer (FastAPI):
- Four main router components:
- Auth Router
- API Keys Router
- Phrasal Verbs Router
- Numbers Router
- Use green coloring for backend components

C. External Services:
- Google SSO (Authentication)
- OpenAI GPT-4 (AI Integration)
- Use purple coloring for external services

D. Database Layer:
- SQLite Database with tables for:
- Users
- API Keys
- Saved Stories
- Use orange coloring for database components

##### Connection Flows to Illustrate

A. Authentication Flow:
- JWT token flow from Backend → Frontend

B. Data Flow:
- Frontend → Backend API endpoints
- Backend → Database (CRUD operations)
- Backend → OpenAI (story generation)
- Database → Backend (data retrieval)

##### Key Technical Elements to Highlight

A. Security Components:
- JWT token validation
- Fernet encryption for API keys
- As security layers between components

B. Integration Points:
- LangChain integration with OpenAI
- Google SSO integration
- Database ORM (SQLAlchemy)

##### Specific Implementation Details

**[User Interface Layer]**
- ↓
**[Authentication Layer]**
- ↓
**[Application Layer]**
- ↓
**[Data Access Layer]**

##### Critical Flows to Emphasize

A. Story Generation Flow:
**User → Frontend → Backend → OpenAI → Backend → Frontend**

B. Authentication Flow:
**User → Frontend → Google SSO → Backend → JWT → Frontend**

C. Data Persistence Flow:
**Backend → SQLAlchemy → SQLite**

Remember to:
- Keep components proportional to their importance
- Use consistent styling for similar components
- Version information for major components
- Clear labels for all interfaces and connections
- Document any rate limits or scaling considerations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "User Interface Layer"
        UI_SG["Story Generator"]:::frontend
        UI_FS["Favorite Stories"]:::frontend
        UI_AK["API Key Config"]:::frontend
        UI_MA["Main App"]:::frontend
    end

    subgraph "Authentication Layer"
        GSSO["Google SSO"]:::external
        JWT["JWT Handler"]:::security
        AUTH["Auth Router"]:::backend
        DEPS["Dependencies"]:::security
    end

    subgraph "Application Layer"
        MAIN["Main App"]:::backend
        AKR["API Keys Router"]:::backend
        PVR["Phrasal Verbs Router"]:::backend
        NR["Numbers Router"]:::backend
        ENC["Encryption Utils"]:::security
        PVU["Phrasal Verbs Utils"]:::backend
    end

    subgraph "External Services"
        OPENAI["OpenAI GPT-4"]:::external
    end

    subgraph "Data Layer"
        DB[(SQLite Database)]:::database
        DBCONF["Database Config"]:::database
        MODELS["Data Models"]:::database
        PVD["Phrasal Verbs Data"]:::data
    end

    %% Connections
    UI_MA --> UI_SG
    UI_MA --> UI_FS
    UI_MA --> UI_AK
    
    UI_MA --> GSSO
    GSSO --> AUTH
    AUTH --> JWT
    JWT --> UI_MA
    
    UI_SG --> MAIN
    UI_FS --> MAIN
    UI_AK --> MAIN
    
    MAIN --> AKR
    MAIN --> PVR
    MAIN --> NR
    MAIN --> AUTH
    
    PVR --> PVU
    PVU --> PVD
    
    AKR --> ENC
    AUTH --> DEPS
    
    MAIN --> OPENAI
    
    PVR --> DBCONF
    AKR --> DBCONF
    AUTH --> DBCONF
    DBCONF --> DB
    MODELS --> DB

    %% Click Events
    click UI_SG "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/frontend/pages/0_story_generator.py"
    click UI_FS "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/frontend/pages/1_favorite_story.py"
    click UI_AK "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/frontend/pages/2_api_key_config.py"
    click UI_MA "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/frontend/app.py"
    click AUTH "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/backend/app/routers/auth.py"
    click AKR "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/backend/app/routers/api_keys.py"
    click PVR "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/backend/app/routers/phrasal_verbs.py"
    click NR "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/backend/app/routers/numbers.py"
    click DBCONF "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/backend/app/database.py"
    click MODELS "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/backend/app/models.py"
    click ENC "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/backend/app/utils/encryption.py"
    click DEPS "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/backend/app/dependencies.py"
    click MAIN "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/backend/app/main.py"
    click PVU "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/backend/app/utils/phrasal_verbs.py"
    click PVD "https://github.com/Howard115/phrasal-verb-app-v2/blob/main/backend/phrasal-verbs.csv"

    %% Styling
    classDef frontend fill:#2374AB
    classDef backend fill:#57A773
    classDef external fill:#9067C6
    classDef database fill:#F79824
    classDef security fill:#C41E3A
    classDef data fill:#FFB6C1

    %% Legend
    subgraph Legend
        F[Frontend]:::frontend
        B[Backend]:::backend
        E[External Services]:::external
        D[Database]:::database
        S[Security]:::security
        DA[Data]:::data
    end
```
