# gokul3710/qp-assessment architecture

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

- Interactive diagram: https://gitdiagram.com/gokul3710/qp-assessment
- Repository: https://github.com/gokul3710/qp-assessment

## Overview

##### Project type and purpose
- This is a modular, monolithic backend API built with the NestJS framework in TypeScript.
- It exposes REST endpoints for user authentication (signup/login using JWT), product catalog operations, order management, and event tracking/emission.
- It connects to a relational database via TypeORM, emits domain events internally, and follows a layered Controller→Service→Repository pattern.

##### File structure
- Top-level config files:
- Dockerfile, docker-compose.yaml – containerization
- tsconfig.json / tsconfig.build.json – TypeScript compilation
- nest-cli.json – Nest CLI configuration
- package.json / package-lock.json – dependencies & scripts
- src/
- app.module.ts – root module
- main.ts – application bootstrap
- auth/ – AuthModule (controllers, services, DTOs)
- user/ – UserModule (service, entity)
- products/ – ProductsModule
- order/ – OrderModule (with order-product entity)
- events/ – EventsModule (emitter, entity, service)
- common/ – shared guards, interceptors, decorators, constants, JWT strategy
- database/ – DatabaseModule (TypeORM configuration)
- test/ – e2e tests; src/**/*.spec.ts – unit tests

##### README for additional insights
- Generic NestJS starter; confirms REST-API use, test scripts, deployment steps.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    Client["Client UI"]:::external

    %% HTTP/API Layer
    subgraph "HTTP/API Layer"
        direction TB
        AuthController["AuthController"]:::controller
        ProductsController["ProductsController"]:::controller
        OrderController["OrderController"]:::controller
    end

    %% Business Logic Modules
    subgraph "Business Logic Modules"
        direction TB
        AuthService["AuthService"]:::service
        UserService["UserService"]:::service
        ProductsService["ProductsService"]:::service
        OrderService["OrderService"]:::service
        EventsEmitter["EventsEmitter"]:::eventbus
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        Database["Relational DB"]:::database
        UserEntity["UserEntity"]:::entity
        ProductEntity["ProductEntity"]:::entity
        OrderEntity["OrderEntity"]:::entity
        OrderProductEntity["OrderProductEntity"]:::entity
        EventsEntity["EventsEntity"]:::entity
    end

    %% Common (Cross-cutting)
    subgraph "Common / Cross-cutting"
        direction TB
        CommonModule["CommonModule"]:::module
        Guards["Guards"]:::cross
        Interceptors["Interceptors"]:::cross
        Decorators["Decorators"]:::cross
        JWTStrategy["JWTStrategy"]:::cross
    end

    %% Root & Infrastructure
    subgraph "Root & Infrastructure"
        direction TB
        AppModule["AppModule"]:::module
        Main["main.ts"]:::module
        Dockerfile["Dockerfile"]:::infra
        DockerCompose["docker-compose.yaml"]:::infra
    end

    %% Tests
    subgraph "Tests"
        direction TB
        E2E["E2E Tests"]:::test
        UnitTests["Unit Tests"]:::test
    end

    %% Relationships
    Client -->|"HTTP Request"| AuthController
    Client -->|"HTTP Request"| ProductsController
    Client -->|"HTTP Request"| OrderController

    AuthController -->|"uses"| AuthService
    ProductsController -->|"uses"| ProductsService
    OrderController -->|"uses"| OrderService

    AuthService -->|"publishes"| EventsEmitter
    OrderService -->|"publishes"| EventsEmitter
    EventsEmitter -->|"consumed by"| EventsService

    AuthService --- UserService
    OrderService --> ProductsService

    AuthService -->|"JWT validate"| JWTStrategy
    AuthService -->|"queries"| UserEntity
    UserService -->|"queries"| UserEntity

    ProductsService -->|"queries"| ProductEntity
    OrderService -->|"queries"| OrderEntity
    OrderService -->|"queries"| OrderProductEntity

    EventsService["EventsService"]:::service -->|"persists"| EventsEntity

    UserEntity --- Database
    ProductEntity --- Database
    OrderEntity --- Database
    OrderProductEntity --- Database
    EventsEntity --- Database

    Guards -.-> AuthController
    Guards -.-> ProductsController
    Guards -.-> OrderController

    Interceptors -.-> AuthController
    Interceptors -.-> ProductsController
    Interceptors -.-> OrderController

    Decorators -.-> AuthController
    Decorators -.-> ProductsController
    Decorators -.-> OrderController

    DatabaseModule["DatabaseModule"]:::infra --> Database

    AppModule --> AuthModule["AuthModule"]:::module
    AppModule --> UserModule["UserModule"]:::module
    AppModule --> ProductsModule["ProductsModule"]:::module
    AppModule --> OrderModule["OrderModule"]:::module
    AppModule --> EventsModule["EventsModule"]:::module
    AppModule --> CommonModule

    Main --> AppModule

    Dockerfile --> AppModule
    DockerCompose --> AppModule

    AppModule --> DatabaseModule

    AppModule --> Guards
    AppModule --> Interceptors

    AppModule --> JWTStrategy

    AppModule --> Decorators

    AppModule --> EventsEmitter

    E2E --> Main
    UnitTests --> AuthService
    UnitTests --> ProductsService
    UnitTests --> OrderService

    %% Click Events
    click AuthModule "https://github.com/gokul3710/qp-assessment/blob/master/src/auth/auth.module.ts"
    click AuthController "https://github.com/gokul3710/qp-assessment/blob/master/src/auth/auth.controller.ts"
    click AuthService "https://github.com/gokul3710/qp-assessment/blob/master/src/auth/auth.service.ts"
    click UserModule "https://github.com/gokul3710/qp-assessment/blob/master/src/user/user.module.ts"
    click UserService "https://github.com/gokul3710/qp-assessment/blob/master/src/user/user.service.ts"
    click UserEntity "https://github.com/gokul3710/qp-assessment/blob/master/src/user/user.entity.ts"
    click ProductsModule "https://github.com/gokul3710/qp-assessment/blob/master/src/products/products.module.ts"
    click ProductsController "https://github.com/gokul3710/qp-assessment/blob/master/src/products/products.controller.ts"
    click ProductsService "https://github.com/gokul3710/qp-assessment/blob/master/src/products/products.service.ts"
    click ProductEntity "https://github.com/gokul3710/qp-assessment/blob/master/src/products/product.entity.ts"
    click OrderModule "https://github.com/gokul3710/qp-assessment/blob/master/src/order/order.module.ts"
    click OrderController "https://github.com/gokul3710/qp-assessment/blob/master/src/order/order.controller.ts"
    click OrderService "https://github.com/gokul3710/qp-assessment/blob/master/src/order/order.service.ts"
    click OrderEntity "https://github.com/gokul3710/qp-assessment/blob/master/src/order/order.entity.ts"
    click OrderProductEntity "https://github.com/gokul3710/qp-assessment/blob/master/src/order/order-product.enity.ts"
    click EventsModule "https://github.com/gokul3710/qp-assessment/blob/master/src/events/events.module.ts"
    click EventsService "https://github.com/gokul3710/qp-assessment/blob/master/src/events/events.service.ts"
    click EventsEmitter "https://github.com/gokul3710/qp-assessment/blob/master/src/events/events.emitter.ts"
    click EventsEntity "https://github.com/gokul3710/qp-assessment/blob/master/src/events/events.entity.ts"
    click CommonModule "https://github.com/gokul3710/qp-assessment/blob/master/src/common/common.module.ts"
    click Guards "https://github.com/gokul3710/qp-assessment/tree/master/src/common/guards"
    click Interceptors "https://github.com/gokul3710/qp-assessment/blob/master/src/common/interceptors/jsend.interceptor.ts"
    click Decorators "https://github.com/gokul3710/qp-assessment/blob/master/src/common/decorators/user.decorator.ts"
    click JWTStrategy "https://github.com/gokul3710/qp-assessment/blob/master/src/common/strategy/jwt.strategy.ts"
    click DatabaseModule "https://github.com/gokul3710/qp-assessment/blob/master/src/database/database.module.ts"
    click AppModule "https://github.com/gokul3710/qp-assessment/blob/master/src/app.module.ts"
    click Main "https://github.com/gokul3710/qp-assessment/blob/master/src/main.ts"
    click Dockerfile "https://github.com/gokul3710/qp-assessment/tree/master/Dockerfile"
    click DockerCompose "https://github.com/gokul3710/qp-assessment/blob/master/docker-compose.yaml"
    click E2E "https://github.com/gokul3710/qp-assessment/blob/master/test/app.e2e-spec.ts"
    click UnitTests "https://github.com/gokul3710/qp-assessment/blob/master/src/auth/auth.service.spec.ts"

    %% Styles
    classDef external fill:#eee,stroke:#333
    classDef controller fill:#f9f,stroke:#333
    classDef service fill:#9f9,stroke:#333
    classDef module fill:#fcf,stroke:#333
    classDef entity fill:#ccf,stroke:#333
    classDef database fill:#cff,stroke:#333
    classDef infra fill:#cff,stroke:#333
    classDef cross fill:#ffc,stroke:#333
    classDef eventbus fill:#ff9,stroke:#333
    classDef test fill:#eee,stroke:#333
```
