# honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github architecture

> Architecture diagram of the GitHub repository honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github
- Repository: https://github.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github

## Overview

##### Project type and purpose
- This is a standalone backend service built with Node.js and Express.
- Its sole responsibility is user management and authentication, exposing a RESTful API.
- It uses JWT for token‐based authentication, bcrypt for password hashing, and OAuth2 strategies (Google, GitHub) via Passport.

##### File structure
Top-level overview:
– server.js
– config/
– controllers/
– models/
– routes/
– middlewares/
Details:
- config/db.js: sets up the database connection (likely MongoDB via Mongoose).
- config/passport-*.js: three Passport strategies (JWT, GitHub, Google).
- routes/auth.js & routes/userRoutes.js: HTTP endpoints.
- middlewares/authMiddleware.js: protects routes, extracts and validates JWT.
- middlewares/validationMiddleware.js: request body/schema validation.
- controllers/userController.js: business logic for signup, login, profile, OAuth callbacks.
- models/User.js: user schema/model.

##### README for additional insights
- Title confirms core functionality: “BACKEND-USERS-PASSPORT-JWT-BCRYPT-OAUTH2-GOOGLE-GITHUB.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "API Consumer"
        style APIConsumer fill:#E8F0FE,stroke:#1A73E8,stroke-width:2px
        APIConsumer["Client"]:::external
    end

    subgraph "Express Server"
        style ExpressLayer fill:#FFF3E0,stroke:#FB8C00,stroke-width:2px
        Server["server.js"]:::internal
    end

    subgraph "Configuration"
        style ConfigLayer fill:#E0F7FA,stroke:#00796B,stroke-width:2px
        DBConfig["db.js"]:::database
        PassportJWT["passport-jwt.js"]:::oauth
        PassportGoogle["passport-google.js"]:::oauth
        PassportGitHub["passport-github.js"]:::oauth
    end

    subgraph "Routes"
        style RoutesLayer fill:#F3E5F5,stroke:#8E24AA,stroke-width:2px
        AuthRoutes["auth.js"]:::internal
        UserRoutes["userRoutes.js"]:::internal
    end

    subgraph "Middleware"
        style MiddlewareLayer fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px
        ValidationMW["validationMiddleware.js"]:::internal
        AuthMW["authMiddleware.js"]:::internal
    end

    subgraph "Controllers"
        style ControllerLayer fill:#E1F5FE,stroke:#0288D1,stroke-width:2px
        UserController["userController.js"]:::internal
    end

    subgraph "Models & Database"
        style ModelLayer fill:#F1F8E9,stroke:#558B2F,stroke-width:2px
        UserModel["User.js"]:::internal
        MongoDB["MongoDB"]:::database
    end

    subgraph "External OAuth Providers"
        style OAuthLayer fill:#FFEBEE,stroke:#C62828,stroke-width:2px
        Google["Google OAuth"]:::external
        GitHub["GitHub OAuth"]:::external
    end

    %% Connections
    APIConsumer -->|"HTTPS Request"| Server
    Server -->|delegates to| AuthRoutes
    Server -->|delegates to| UserRoutes

    AuthRoutes -->|validate| ValidationMW
    UserRoutes -->|validate| ValidationMW

    ValidationMW -->|authenticate if needed| AuthMW
    AuthMW --> UserController
    ValidationMW --> UserController

    AuthRoutes --> UserController
    UserRoutes --> UserController

    UserController -->|CRUD operations| UserModel
    UserModel -->|Mongoose ORM| MongoDB
    DBConfig --> MongoDB

    UserController -->|redirect/authorize| PassportGoogle
    UserController -->|redirect/authorize| PassportGitHub
    PassportGoogle -->|external redirect| Google
    PassportGitHub -->|external redirect| GitHub
    Google -->|callback| PassportGoogle
    GitHub -->|callback| PassportGitHub
    PassportGoogle -->|issue JWT| UserController
    PassportGitHub -->|issue JWT| UserController
    PassportJWT -->|JWT Strategy| AuthMW

    %% Click Events
    click Server "https://github.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github/blob/main/server.js"
    click DBConfig "https://github.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github/blob/main/config/db.js"
    click PassportJWT "https://github.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github/blob/main/config/passport-jwt.js"
    click PassportGoogle "https://github.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github/blob/main/config/passport-google.js"
    click PassportGitHub "https://github.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github/blob/main/config/passport-github.js"
    click AuthMW "https://github.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github/blob/main/middlewares/authMiddleware.js"
    click ValidationMW "https://github.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github/blob/main/middlewares/validationMiddleware.js"
    click AuthRoutes "https://github.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github/blob/main/routes/auth.js"
    click UserRoutes "https://github.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github/blob/main/routes/userRoutes.js"
    click UserController "https://github.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github/blob/main/controllers/userController.js"
    click UserModel "https://github.com/honcito/backend-users-passport-jwt-bcrypt-oaut2-google-github/blob/main/models/User.js"

    %% Styles
    classDef internal fill:#FFFFFF,stroke:#000000,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#424242,stroke-width:1px,stroke-dasharray: 5 5
    classDef database fill:#D7CCC8,stroke:#5D4037,stroke-width:1px
    classDef oauth fill:#F3E5F5,stroke:#8E24AA,stroke-width:1px
```
