# forkjustrubik/user_service-rubik_fork architecture

> Architecture diagram of the GitHub repository forkjustrubik/user_service-rubik_fork, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/forkjustrubik/user_service-rubik_fork
- Repository: https://github.com/forkjustrubik/user_service-rubik_fork

## Overview

##### Project Type and Purpose
- This is a modular, server-side REST API built with the NestJS framework (Node.js + TypeScript).
- Its purpose is to provide user authentication (sign-up, sign-in, JWT issuance/refresh), user profile retrieval, and account-helper operations (password reset/update).
- It follows NestJS’s modules + dependency injection + TypeORM for Postgres.

##### File Structure Analysis
- Top level:
- Dockerfile, .github/workflows: CI/CD and containerization
- package.json, tsconfig.json, lint/ESLint/Prettier configs
- src/
- main.ts and app.module.ts: application entry and root DI container
- src/commons: cross-cutting concerns
– configuration (Postgres module), database layer (TypeORM entities, DTOs, repos), guards, middleware, security utils, strategies, wrappers
- src/modules: feature modules
– auth: sign-up, sign-in, refresh, JWT strategies
– user: get profile, change password
– account-helper: request/reset/update password flows
- test/: e2e suite

##### README Insights
- Generic Nest starter; confirms use of NestJS core, CLI, and recommended deployment practices.

##### Components
a. Main Components
- Client (browser/mobile/other service)
- NestJS REST API server
- Controllers (AuthController, UserController, AccountHelperController)
- Services (AuthService, UserService, AccountHelperService)
- Commons layer
– Guards (JWTAuthGuard, JWTAdminGuard)
– Strategies (JWT, local)
– Middleware (BasicAuth)
– Database Repositories (UserRepo, TokenRepo, OtpCodeRepo)
- PostgreSQL database
- (Optional) External Email Service for password reset notifications
b. Relationships & Data Flow
1. Client issues HTTP requests → appropriate Controller endpoint
2. Controller calls Service methods
3. Service applies business logic, calls Repo to query/write Entities via TypeORM
4. Repos interact with Postgres
5. Service returns data/DTO to Controller → Controller wraps in ResponseWrapper → HTTP response
6. Guards/Strategies intercept requests for authentication/authorization
c. Architectural Patterns
- Layered architecture:
Presentation (controllers) → Business (services) → Data (repos/entities)
- Modular segmentation: commons vs. feature modules
- Dependency Injection (Nest’s DI container)
- Use of DTOs for validation and typing
- Guards & Strategies for cross-cutting security
d. Key Technologies
- NestJS (Framework, Modules, Controllers, Providers)
- TypeScript
- TypeORM (Entities, DTOs, Repositories)
- PostgreSQL
- JWT for auth, bcrypt or similar for password encoding
- Docker for containerization, GitHub Actions for CI/CD

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    Client["Client\n(Browser/Mobile)"]:::external

    %% Application Entry
    subgraph "Application Entry"
        Main["main.ts"]:::presentation
        AppModule["app.module.ts"]:::presentation
    end

    %% Presentation Layer
    subgraph "Auth Module (Presentation)" 
        AuthController["AuthController"]:::presentation
    end
    subgraph "User Module (Presentation)"
        UserController["UserController"]:::presentation
    end
    subgraph "Account-Helper Module (Presentation)"
        AccountHelperController["AccountHelperController"]:::presentation
    end

    %% Business Layer
    subgraph "Auth Module (Business)"
        AuthService["AuthService"]:::business
    end
    subgraph "User Module (Business)"
        UserService["UserService"]:::business
    end
    subgraph "Account-Helper Module (Business)"
        AccountHelperService["AccountHelperService"]:::business
    end

    %% Commons Modules
    subgraph Commons
        subgraph "Security Cross-Cutting"
            JWTAuthGuard["JWTAuthGuard"]:::business
            JWTAdminGuard["JWTAdminGuard"]:::business
            LocalStrategy["LocalStrategy"]:::business
            JWTStrategy["JWTStrategy"]:::business
            JWTAdminStrategy["JWTAdminStrategy"]:::business
            BasicAuthMW["BasicAuth Middleware"]:::business
        end
        subgraph "Database Layer"
            UserRepo["UserRepo"]:::data
            TokenRepo["TokenRepo"]:::data
            OtpCodeRepo["OtpCodeRepo"]:::data
        end
        PostgresConfig["PostgresModule"]:::data
        subgraph "Wrappers & Utils"
            RequestWrapper["RequestWrapper"]:::business
            ResponseWrapper["ResponseWrapper"]:::business
            RandomStringUtil["randomString Util"]:::business
        end
        subgraph "Security Utils"
            PasswordEncode["passwordEncode"]:::business
            PasswordVerify["passwordVerify"]:::business
            JWTDecode["jwtDecodeWithoutVerification"]:::business
        end
    end

    %% Data Layer
    PostgresDB[("PostgreSQL DB")]:::data
    ExternalEmail["External Email Service"]:::external

    %% Flows
    Client -->|HTTP Request| AuthController
    Client -->|HTTP Request| UserController
    Client -->|HTTP Request| AccountHelperController

    AuthController -->|calls| AuthService
    UserController -->|calls| UserService
    AccountHelperController -->|calls| AccountHelperService

    AuthService -->|uses| UserRepo
    AuthService -->|uses| TokenRepo
    AuthService -->|uses| OtpCodeRepo

    UserService -->|uses| UserRepo

    AccountHelperService -->|uses| OtpCodeRepo
    AccountHelperService -->|uses| TokenRepo
    AccountHelperService -->|sends email| ExternalEmail

    UserRepo -->|queries| PostgresDB
    TokenRepo -->|queries| PostgresDB
    OtpCodeRepo -->|queries| PostgresDB

    %% Guards and Strategies
    AuthController ---|protected by| JWTAuthGuard
    AuthController ---|protected by| LocalStrategy
    AuthController ---|admin guard| JWTAdminGuard

    %% Configuration injection
    AppModule --> PostgresConfig
    AuthModuleDef["auth.module.ts"]:::business
    UserModuleDef["user.module.ts"]:::business
    AccountHelperModuleDef["account-helper.module.ts"]:::business

    AppModule --> AuthModuleDef
    AppModule --> UserModuleDef
    AppModule --> AccountHelperModuleDef

    %% Click Events
    click Main "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/main.ts"
    click AppModule "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/app.module.ts"
    click AuthController "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/modules/auth/auth.controller.ts"
    click AuthService "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/modules/auth/auth.service.ts"
    click AuthModuleDef "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/modules/auth/auth.module.ts"
    click UserController "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/modules/user/user.controller.ts"
    click UserService "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/modules/user/user.service.ts"
    click UserModuleDef "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/modules/user/user.module.ts"
    click AccountHelperController "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/modules/account-helper/account-helper.controller.ts"
    click AccountHelperService "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/modules/account-helper/account-helper.service.ts"
    click AccountHelperModuleDef "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/modules/account-helper/account-helper.module.ts"
    click PostgresConfig "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/configuation/database/postgres.module.ts"
    click UserRepo "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/database/repos/user.repo.ts"
    click TokenRepo "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/database/repos/token.repo.ts"
    click OtpCodeRepo "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/database/repos/otpCode.repo.ts"
    click JWTAuthGuard "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/guards/jwt-auth.guard.ts"
    click JWTAdminGuard "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/guards/jwt-admin.guard.ts"
    click LocalStrategy "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/strategies/local.strategy.ts"
    click JWTStrategy "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/strategies/jwt.strategy.ts"
    click JWTAdminStrategy "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/strategies/jwt-admin.strategy.ts"
    click BasicAuthMW "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/middlewares/basicAuth.middleware.ts"
    click PasswordEncode "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/security/passwordEncode.ts"
    click PasswordVerify "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/security/passwordVerify.ts"
    click JWTDecode "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/security/jwtDecodeWithoutVerification.ts"
    click RequestWrapper "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/wrappers/request.wrapper.ts"
    click ResponseWrapper "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/wrappers/response.wrapper.ts"
    click RandomStringUtil "https://github.com/forkjustrubik/user_service-rubik_fork/blob/main/src/commons/utils/randomString.ts"

    %% Styles
    classDef presentation fill:#cce5ff,stroke:#66b0ff,color:#000;
    classDef business fill:#d4edda,stroke:#8fbc8f,color:#000;
    classDef data fill:#fff3cd,stroke:#ffdf7e,color:#000;
    classDef external fill:#e2e3e5,stroke:#c8c9ca,color:#000;
```
