# reporange/googleoauth architecture

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

- Interactive diagram: https://gitdiagram.com/reporange/googleoauth
- Repository: https://github.com/reporange/googleoauth

## Overview

##### Project type and purpose
- Type: Full‑stack web application (Node.js + Express + EJS)
- Purpose: Provide Single‑Sign‑On (SSO) via Google OAuth 2.0 to authenticate users across multiple services.

##### File structure
- Top‑level:
– app.js: application entry point, Express setup
– config/: environment and middleware configuration
– controllers/: request handlers (authController, dashboardController, mainController)
– middleware/: custom Express middleware (authMiddleware)
– models/: data models (user.js)
– routes/: Express routers (authRoutes, dashboardRoutes, mainRoutes)
– views/: EJS templates (index.ejs, dashboard.ejs)
- Patterns:
– MVC style: models ↔ controllers ↔ views
– Passport.js integration for OAuth flows
– Session management via express‑session

##### README for additional insights
- Core feature: Google OAuth 2.0 SSO
- Deployed URL hints at the need for OAuth callback endpoints

##### Elements
- Clear labels:
– Browser, Express Server, Session Store, User DB, Google OAuth
– Components inside Express: Routes, Controllers, Middleware, View Engine
– Persistence layers (DB, Session) in another
– App internals (routes/controllers) grouped and shaded

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Browser["User's Web Browser"]:::external

    %% External Services
    GoogleOAuth["Google OAuth 2.0 Authorization Server"]:::external
    SessionStore["Session Store"]:::persistence
    UserDB["User Database"]:::persistence

    %% Express Server
    subgraph "Express Server" 
        direction TB
        App["app.js"]:::backend

        subgraph "Configuration"
            direction TB
            ConfigDB["database.js"]:::config
            ConfigPassport["passport.js"]:::config
            ConfigSession["sessionConfig.js"]:::config
        end

        subgraph "Middleware"
            direction TB
            MiddlewareAuth["authMiddleware.js"]:::middleware
        end

        subgraph "Routes"
            direction TB
            RoutesAuth["authRoutes.js"]:::route
            RoutesMain["mainRoutes.js"]:::route
            RoutesDash["dashboardRoutes.js"]:::route
        end

        subgraph "Controllers"
            direction TB
            CtrlAuth["authController.js"]:::controller
            CtrlMain["mainController.js"]:::controller
            CtrlDash["dashboardController.js"]:::controller
        end

        subgraph "Models"
            direction TB
            ModelUser["user.js"]:::model
        end

        subgraph "Views & Engine"
            direction TB
            ViewEngine["EJS View Engine"]:::view
            ViewIndex["index.ejs"]:::view
            ViewDash["dashboard.ejs"]:::view
        end
    end

    %% Flows
    Browser -->|HTTP Request| App
    App -->|loads config| ConfigDB
    App -->|loads config| ConfigPassport
    App -->|loads config| ConfigSession
    App -->|uses middleware| MiddlewareAuth
    App -->|routes| RoutesAuth
    App -->|routes| RoutesMain
    App -->|routes| RoutesDash

    RoutesAuth -->|handles auth| CtrlAuth
    RoutesMain -->|handles main| CtrlMain
    RoutesDash -->|handles dashboard| CtrlDash

    CtrlAuth -->|reads/writes| SessionStore
    CtrlAuth -->|lookup/create| UserDB
    CtrlAuth -->|redirects to| GoogleOAuth
    GoogleOAuth -->|callback to| RoutesAuth

    CtrlMain -->|renders| ViewIndex
    CtrlDash -->|renders| ViewDash

    CtrlAuth -->|uses model| ModelUser
    CtrlMain -->|uses model| ModelUser
    CtrlDash -->|uses model| ModelUser

    CtrlAuth -->|renders via| ViewEngine
    CtrlMain -->|renders via| ViewEngine
    CtrlDash -->|renders via| ViewEngine

    App -->|connects to| SessionStore
    App -->|connects to| UserDB

    %% Click Events
    click App "https://github.com/reporange/googleoauth/blob/main/app.js"
    click ConfigDB "https://github.com/reporange/googleoauth/blob/main/config/database.js"
    click ConfigPassport "https://github.com/reporange/googleoauth/blob/main/config/passport.js"
    click ConfigSession "https://github.com/reporange/googleoauth/blob/main/config/sessionConfig.js"
    click MiddlewareAuth "https://github.com/reporange/googleoauth/blob/main/middleware/authMiddleware.js"
    click RoutesAuth "https://github.com/reporange/googleoauth/blob/main/routes/authRoutes.js"
    click RoutesMain "https://github.com/reporange/googleoauth/blob/main/routes/mainRoutes.js"
    click RoutesDash "https://github.com/reporange/googleoauth/blob/main/routes/dashboardRoutes.js"
    click CtrlAuth "https://github.com/reporange/googleoauth/blob/main/controllers/authController.js"
    click CtrlMain "https://github.com/reporange/googleoauth/blob/main/controllers/mainController.js"
    click CtrlDash "https://github.com/reporange/googleoauth/blob/main/controllers/dashboardController.js"
    click ModelUser "https://github.com/reporange/googleoauth/blob/main/models/user.js"
    click ViewIndex "https://github.com/reporange/googleoauth/blob/main/views/index.ejs"
    click ViewDash "https://github.com/reporange/googleoauth/blob/main/views/dashboard.ejs"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef persistence fill:#afa,stroke:#333,stroke-width:1px
    classDef backend fill:#ccf,stroke:#333,stroke-width:1px
    classDef config fill:#fcf,stroke:#333,stroke-width:1px
    classDef middleware fill:#cff,stroke:#333,stroke-width:1px
    classDef route fill:#ffb,stroke:#333,stroke-width:1px
    classDef controller fill:#fbc,stroke:#333,stroke-width:1px
    classDef model fill:#bdf,stroke:#333,stroke-width:1px
    classDef view fill:#dfb,stroke:#333,stroke-width:1px
```
