# hitenvats16/onlyauth-backend architecture

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

- Interactive diagram: https://gitdiagram.com/hitenvats16/onlyauth-backend
- Repository: https://github.com/hitenvats16/onlyauth-backend

## Overview

##### Project type and purpose
- OnlyAuthBackend is a standalone Node.js backend service whose sole purpose is to implement OAuth2 Authorization Code Grant and secure user authentication via Scrypt password hashing.
- There is no frontend in this repo; it exposes HTTP endpoints for clients (web/mobile/native) to register, authenticate, obtain access tokens, and manage resources.

##### File structure
- Top‑level files
- index.js – entrypoint that bootstraps the Express server
- Dockerfile & compose.dev.yaml – containerization and local orchestration
- development.env – environment variables
- package.json – dependencies and scripts
- common/
- config.js – centralized configuration loader
- constants/ – error codes, OAuth scopes
- db/ – Prisma schema, migration scripts, and DB setup
- errors.js – common error definitions
- utils/ – logger and time utilities
- modules/
Four feature modules, each with
- router.js – Express route definitions
- controller.js – HTTP request handlers
- service.js – business logic
- (optional) middleware.js – request filtering/authorization
– user, resources, operations, dashboard

##### README for additional insights
- Emphasizes use of Scrypt for password hashing (high compute/memory)
- Implements OAuth Authorization Code Grant flow

##### Detail
- Data flow for:
- User registration & login (Scrypt hashing)
- Authorization code exchange
- Access token generation
- Protected resource access
- Migration pipeline (common/db/migrations) as a side process or note

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    subgraph "Clients"
        WebClient["Web/Mobile Clients"]:::client
    end

    %% API Gateway
    subgraph "OnlyAuthBackend API Gateway"
        EG["Express Server Entrypoint"]:::api
        click EG "https://github.com/hitenvats16/onlyauth-backend/blob/main/index.js"

        subgraph "Configuration & Constants"
            CFG["Config Loader"]:::infra
            click CFG "https://github.com/hitenvats16/onlyauth-backend/blob/main/common/config.js"
            CODES["Error Codes"]:::infra
            click CODES "https://github.com/hitenvats16/onlyauth-backend/blob/main/common/constants/codes.js"
            SCOPES["OAuth Scopes"]:::infra
            click SCOPES "https://github.com/hitenvats16/onlyauth-backend/blob/main/common/constants/scopes.js"
        end

        ERR["Error Definitions"]:::infra
        click ERR "https://github.com/hitenvats16/onlyauth-backend/blob/main/common/errors.js"

        subgraph "Database Layer"
            PrismaSchema["Prisma Schema"]:::database
            click PrismaSchema "https://github.com/hitenvats16/onlyauth-backend/blob/main/common/db/schema.prisma"
            DBInit["DB Initialization"]:::database
            click DBInit "https://github.com/hitenvats16/onlyauth-backend/blob/main/common/db/index.js"
            Migrations["Migrations"]:::database
            click Migrations "https://github.com/hitenvats16/onlyauth-backend/tree/main/common/db/migrations/"
        end

        subgraph "Utilities"
            Logger["Logger"]:::util
            click Logger "https://github.com/hitenvats16/onlyauth-backend/blob/main/common/utils/logger.js"
            TimeUtil["Time Utilities"]:::util
            click TimeUtil "https://github.com/hitenvats16/onlyauth-backend/blob/main/common/utils/time.js"
            ScryptUtil["Scrypt Utility"]:::util
        end

        subgraph "Modules"
            subgraph "Auth Module"
                URtr["User Router"]:::api
                click URtr "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/user/router.js"
                UCtrl["User Controller"]:::backend
                click UCtrl "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/user/controller.js"
                USvc["Auth Service"]:::backend
                click USvc "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/user/service.js"
            end

            subgraph "Resource Module"
                RRtr["Resource Router"]:::api
                click RRtr "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/resources/router.js"
                RCtrl["Resource Controller"]:::backend
                click RCtrl "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/resources/controller.js"
                RSvc["Resource Service"]:::backend
                click RSvc "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/resources/service.js"
                RMid["Resource Middleware"]:::infra
                click RMid "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/resources/middleware.js"
            end

            subgraph "Operations Module"
                ORtr["Operations Router"]:::api
                click ORtr "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/operations/router.js"
                OCtrl["Operations Controller"]:::backend
                click OCtrl "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/operations/controller.js"
                OSvc["Operations Service"]:::backend
                click OSvc "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/operations/service.js"
            end

            subgraph "Dashboard Module"
                DRtr["Dashboard Router"]:::api
                click DRtr "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/dashboard/router.js"
                DCtrl["Dashboard Controller"]:::backend
                click DCtrl "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/dashboard/controller.js"
                DSvc["Dashboard Service"]:::backend
                click DSvc "https://github.com/hitenvats16/onlyauth-backend/blob/main/modules/dashboard/service.js"
            end
        end
    end

    %% External Services & Infrastructure
    ExternalOAuth["External OAuth Server"]:::external
    Postgres["PostgreSQL Database"]:::databaseCyl
    DockerCompose["Docker & Compose"]:::infra
    click DockerCompose "https://github.com/hitenvats16/onlyauth-backend/tree/main/Dockerfile"
    click DockerCompose "https://github.com/hitenvats16/onlyauth-backend/blob/main/compose.dev.yaml"

    %% Connections
    WebClient --> EG
    EG --> CFG
    EG --> CODES
    EG --> SCOPES
    EG --> ERR
    EG --> PrismaSchema
    EG --> DBInit
    EG --> Migrations
    EG --> Logger
    EG --> TimeUtil
    EG --> ScryptUtil
    EG --> URtr
    URtr --> UCtrl --> USvc --> ScryptUtil
    EG --> RRtr
    RRtr --> RCtrl --> RSvc
    EG --> ORtr
    ORtr --> OCtrl --> OSvc
    EG --> DRtr
    DRtr --> DCtrl --> DSvc
    EG --> ExternalOAuth
    Postgres --> PrismaSchema
    DockerCompose --> EG
    DockerCompose --> Postgres

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000
    classDef api fill:#87CEEB,stroke:#000
    classDef backend fill:#98FB98,stroke:#000
    classDef infra fill:#D3D3D3,stroke:#000
    classDef util fill:#CCCCCC,stroke:#000
    classDef database fill:#FFFF00,stroke:#000
    classDef databaseCyl fill:#FFFF00,stroke:#000,shape:cylinder
    classDef external fill:#FFA500,stroke:#000,shape:cloud
```
