# gururock007/otpfiy architecture

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

- Interactive diagram: https://gitdiagram.com/gururock007/otpfiy
- Repository: https://github.com/gururock007/otpfiy

## Overview

##### Project type and purpose
- This is a full-stack web application offering an OTP (One-Time Password) service via Gmail.
- Frontend: React JS + TailWind CSS + Framer Motion, served as a SPA via Vite.
- Backend: Flask REST API with JWT-based authentication, exposing endpoints to register users, issue API keys, generate and verify OTPs, and send emails through Gmail’s SMTP using app passwords.

##### File structure
- Top-level:
- README.md – overview and tech stack
- backend/ – Python Flask application
- forntend/ – React SPA (note typo “forntend”)
- backend/:
- class_user.py, class_otp.py, class_conn.py, class_info.py – core business logic for user management, OTP generation and storage, Gmail connection, and metadata
- otpify_frontend.py – likely the Flask app’s main entrypoint serving APIs
- requirements.txt – Python dependencies
- forntend/:
- package.json, vite.config.js, tailwind.config.js – build & styling config
- public/ – static assets (fonts, images)
- src/:
– api/axios.js – HTTP client configured for JWT
– components/, routes/ – React components & pages (Login, Signup, Dashboard, etc.)
– context/ – React Context for Auth, User, Error state
– hooks/ – custom React hooks for auth, token refresh
– main.jsx – app bootstrap

##### README for additional insights
- Features: secure OTP generation, Gmail integration, API access, user accounts
- Technology call-outs: Flask, JWT, React, TailWind, Framer Motion
- Usage flow: user signs up → obtains API key → calls /generateOTP → email sent via Gmail → calls /verifyOTP

##### Diagramming guidance
a. Main components
- Frontend (React SPA)
- Backend (Flask REST API)
- Database (e.g., SQL or key-value store for users, API keys, OTP records)
- External Email Service (Gmail SMTP)
- JWT Authentication Service (part of Flask)
b. Relationships & interactions
1. User’s browser loads React SPA from the Web Server (or CDN).
2. SPA invokes Auth endpoints: /signup, /login → Flask → Database → returns JWT & API key.
3. SPA uses axios instances (public & private) to call protected endpoints with JWT header.
4. On OTP request, Flask generates OTP, stores hash/expiry in DB, then calls Gmail SMTP with app password to send email.
5. For OTP verification, the SPA or external client calls /verifyOTP → Flask validates stored OTP → returns success/failure.
c. Architectural patterns & design principles
- RESTful API pattern in Flask
- JWT-based stateless authentication
- Single-page application (SPA) architecture
- Separation of concerns: business logic classes (class_user, class_otp, etc.) decoupled from routing layer
- Environment-based configuration for Gmail credentials
d. Key technologies & libraries
- Flask + flask_jwt_extended
- SMTP lib or flask-mail for Gmail
- React with Context API and custom hooks
- Axios for HTTP calls
- TailWind CSS & Framer Motion for styling & animation
- Vite for frontend build

##### Elements
- Clear component labels (e.g., “React SPA”, “Flask API Server”, “MySQL/PostgreSQL”, “Gmail SMTP”)
- Browser → React SPA → API server → DB
- API server → Gmail SMTP
- Gmail SMTP → User’s email inbox
- Ports or protocols (e.g., HTTPS 443, SMTP 587) if relevant.
- JWT generation & validation steps.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["User's Browser"]:::external
        ReactSPA["React SPA"]:::frontend
        MainJS["main.jsx"]:::frontend
        ViteConfig["vite.config.js"]:::frontend
        TailwindConfig["tailwind.config.js"]:::frontend
        AxiosClient["Axios HTTP Client"]:::frontend
        AuthProvider["AuthProvider Context"]:::frontend
        UserProvider["UserProvider Context"]:::frontend
        ErrorProvider["ErrorProvider Context"]:::frontend
        Hooks["Custom Hooks"]:::frontend
        Routes["React Routes"]:::frontend
        Components["UI Components"]:::frontend
        PublicAssets["Static Assets"]:::frontend

        Browser -->|"Loads SPA over HTTPS 443"| ReactSPA
        ReactSPA --> MainJS
        ReactSPA --> ViteConfig
        ReactSPA --> TailwindConfig
        ReactSPA --> AxiosClient
        ReactSPA --> AuthProvider
        ReactSPA --> UserProvider
        ReactSPA --> ErrorProvider
        ReactSPA --> Hooks
        ReactSPA --> Routes
        ReactSPA --> Components
        ReactSPA --> PublicAssets
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        FlaskAPI["Flask API Server"]:::backend
        ClassUser["User Management (class_user)"]:::backend
        ClassOTP["OTP Logic (class_otp)"]:::backend
        ClassConn["DB Connection (class_conn)"]:::backend
        ClassInfo["Config & Metadata (class_info)"]:::backend
        Requirements["requirements.txt"]:::backend

        ReactSPA -->|"/signup, /login, /generateOTP, /verifyOTP"| FlaskAPI
        FlaskAPI --> ClassUser
        FlaskAPI --> ClassOTP
        FlaskAPI --> ClassConn
        FlaskAPI --> ClassInfo
        FlaskAPI --> Requirements
    end

    %% Database
    Database["MySQL/PostgreSQL"]:::database
    ClassConn -->|Reads/Writes| Database
    ClassUser -->|Stores Users & API Keys| Database
    ClassOTP -->|Stores OTP Hash/Expiry| Database

    %% External Email Service
    GmailSMTP["Gmail SMTP (SMTP 587)"]:::external
    EmailInbox["User Email Inbox"]:::external

    ClassOTP -->|Sends Email via SMTP| GmailSMTP
    GmailSMTP -->|Delivers OTP Email| EmailInbox

    %% Click Events
    click ReactSPA "https://github.com/gururock007/otpfiy/tree/main/forntend/"
    click MainJS "https://github.com/gururock007/otpfiy/blob/main/forntend/src/main.jsx"
    click ViteConfig "https://github.com/gururock007/otpfiy/blob/main/forntend/vite.config.js"
    click TailwindConfig "https://github.com/gururock007/otpfiy/blob/main/forntend/tailwind.config.js"
    click AxiosClient "https://github.com/gururock007/otpfiy/blob/main/forntend/src/api/axios.js"
    click AuthProvider "https://github.com/gururock007/otpfiy/blob/main/forntend/src/context/AuthProvider.jsx"
    click UserProvider "https://github.com/gururock007/otpfiy/blob/main/forntend/src/context/UserProvider.jsx"
    click ErrorProvider "https://github.com/gururock007/otpfiy/blob/main/forntend/src/context/ErrorProvider.jsx"
    click Hooks "https://github.com/gururock007/otpfiy/tree/main/forntend/src/hooks/"
    click Routes "https://github.com/gururock007/otpfiy/tree/main/forntend/src/routes/"
    click Components "https://github.com/gururock007/otpfiy/tree/main/forntend/src/components/"
    click PublicAssets "https://github.com/gururock007/otpfiy/tree/main/forntend/public/"
    click FlaskAPI "https://github.com/gururock007/otpfiy/blob/main/backend/otpify_frontend.py"
    click ClassUser "https://github.com/gururock007/otpfiy/blob/main/backend/class_user.py"
    click ClassOTP "https://github.com/gururock007/otpfiy/blob/main/backend/class_otp.py"
    click ClassConn "https://github.com/gururock007/otpfiy/blob/main/backend/class_conn.py"
    click ClassInfo "https://github.com/gururock007/otpfiy/blob/main/backend/class_info.py"
    click Requirements "https://github.com/gururock007/otpfiy/blob/main/backend/requirements.txt"
    click Database "https://github.com/gururock007/otpfiy/tree/main/backend/" "Note: Database schema located in backend migrations"
    click GmailSMTP "https://github.com/gururock007/otpfiy/tree/main/N/A"
    click EmailInbox "https://github.com/gururock007/otpfiy/tree/main/N/A"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef database fill:#FFFACD,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
