# anilkumarbp/oauth2-react-intuit architecture

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

- Interactive diagram: https://gitdiagram.com/anilkumarbp/oauth2-react-intuit
- Repository: https://github.com/anilkumarbp/oauth2-react-intuit

## Overview

##### Project Type and Purpose
- This is a full-stack sample application demonstrating how to implement OAuth2.0 login with Intuit using a React single‐page-app (SPA) on the frontend and a small Node.js/Express backend acting as a proxy for OAuth calls.

##### File-Structure Analysis
- Top-level files:
- .env – environment variables for ports, OAuth client credentials, proxy URLs
- package.json – project dependencies (React, intuit-oauth, Express)
- public/ – static HTML, manifest, robots.txt
- src/ – React app:
- index.js, App.js – entry points
- components/ – UI components under App (Home.js, Login.js) and shared wrappers
- store/reducer/ – Redux reducer for client state management
- server/ – Node.js/Express server (index.js) exposing two endpoints: /authorizeUrl and /authenticate

##### README Insights
- Confirms CRA bootstrap, React ≥16, Node.js ≥8
- Environment variables configure OAuth client ID/secret, redirect URI, proxy endpoints
- Usage instructions for local HTTPS via ngrok

##### Main Components
a. Browser / Client
– Hosts the React SPA served by CRA dev server (port defined by PORT or default 3000)
– Renders Login and Home views, dispatches Redux actions
b. React Application
– App.js + components + Redux store
– Initiates OAuth flow by calling proxy endpoint /authorizeUrl
– Receives redirect at /login route with authorization code
– Calls proxy endpoint /authenticate to exchange code for tokens
c. Node.js/Express Backend
– Uses intuit-oauth library
– Endpoint /authorizeUrl builds Intuit authorization URL and redirects client
– Endpoint /authenticate exchanges code for access/refresh tokens
d. Intuit OAuth2.0 Authorization Server (External)
– Authorize endpoint (Intuit’s login screen)
– Token endpoint (issues access tokens)

##### Relationships and Data Flows
- 1. User clicks “Login” in React → 2. React calls GET /authorizeUrl on Node server → 3. Node server redirects browser to Intuit’s authorize endpoint → 4. User logs in on Intuit UI → 5. Intuit calls back to React SPA’s /login URL with code → 6. React makes POST /authenticate on Node server with code → 7. Node server exchanges code for tokens with Intuit token endpoint → 8. Node server returns tokens (or session) to React → 9. React updates Redux store → 10. User is authenticated

##### Architectural Patterns and Design Principles
- Single‐Page Application (SPA) pattern
- Unidirectional data flow via Redux store
- Proxy pattern for secret-safe OAuth exchanges
- Separation of concerns: UI layer vs. authentication service
- Environment‐driven configuration (12-factor principles)

##### Technologies and Libraries
- Frontend: React, React DOM, CRA dev server, Redux
- Backend: Node.js, Express, intuit-oauth NPM package
- Optional: ngrok for HTTPS tunneling

##### Diagramming Conventions
- Blue for frontend components
- Green for backend components
- Orange for external services

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration Layer
    subgraph "Configuration & Metadata"
        CFG_ENV[".env"]:::config
        CFG_PKG["package.json"]:::config
        CFG_README["README.md"]:::config
        CFG_GITIGNORE[".gitignore"]:::config
    end

    %% Presentation Layer
    subgraph "Presentation Layer" 
        BROWSER["User's Browser"]:::frontend
        SPA["React SPA (Port 3000)"]:::frontend
        subgraph "React App Files"
            IDX["src/index.js"]:::frontend
            APP["src/App.js"]:::frontend
            LOGIN_UI["Login.js"]:::frontend
            HOME_UI["Home.js"]:::frontend
            SHARED_LOGIN["LoginWrapper.js"]:::frontend
            SHARED_HOME["HomeWrapper.js"]:::frontend
            REDUCER["src/store/reducer/index.js"]:::frontend
        end
        PUBLIC_DIR["public/"]:::frontend
        HTML_TPL["public/index.html"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        SERVER["Express OAuth Proxy (Port 5000)"]:::backend
    end

    %% External Services
    subgraph "External OAuth2.0 Service"
        INTUIT_AUTH["Intuit Authorize Endpoint"]:::external
        INTUIT_TOKEN["Intuit Token Endpoint"]:::external
    end

    %% Data Flows
    BROWSER -->|loads SPA| SPA
    SPA -->|serves via CRA dev server| PUBLIC_DIR
    PUBLIC_DIR --> HTML_TPL

    SPA -->|dispatches| IDX
    IDX --> APP
    APP --> LOGIN_UI
    APP --> HOME_UI
    APP --> SHARED_LOGIN
    APP --> SHARED_HOME
    SPA --> REDUCER

    LOGIN_UI -->|GET /authorizeUrl| SERVER
    SERVER -->|302 Redirect| INTUIT_AUTH
    INTUIT_AUTH -->|callback to /login?code| BROWSER
    BROWSER -->|POST /authenticate| SERVER
    SERVER -->|POST code| INTUIT_TOKEN
    INTUIT_TOKEN -->|tokens| SERVER
    SERVER -->|200 tokens| BROWSER
    SEARCH_REDUCER_RED[Update Redux Store]:::frontend
    BROWSER -->|dispatch AUTH_SUCCESS| REDUCER

    %% Configuration usage
    CFG_ENV --> SPA
    CFG_ENV --> SERVER

    %% Click Events
    click CFG_ENV "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/.env"
    click CFG_PKG "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/package.json"
    click CFG_README "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/README.md"
    click CFG_GITIGNORE "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/.gitignore"
    click IDX "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/src/index.js"
    click APP "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/src/App.js"
    click PUBLIC_DIR "https://github.com/anilkumarbp/oauth2-react-intuit/tree/master/public/"
    click HTML_TPL "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/public/index.html"
    click LOGIN_UI "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/src/components/App/Login.js"
    click HOME_UI "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/src/components/App/Home.js"
    click SHARED_LOGIN "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/src/components/shared/LoginWrapper.js"
    click SHARED_HOME "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/src/components/shared/HomeWrapper.js"
    click REDUCER "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/src/store/reducer/index.js"
    click SERVER "https://github.com/anilkumarbp/oauth2-react-intuit/blob/master/server/index.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef backend fill:#DFF8D8,stroke:#228B22,color:#228B22
    classDef external fill:#FFE8B8,stroke:#FFA500,color:#FFA500
    classDef config fill:#F0F0F0,stroke:#888888,color:#333333
```
