# marcelotadini/scoders-back architecture

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

- Interactive diagram: https://gitdiagram.com/marcelotadini/scoders-back
- Repository: https://github.com/marcelotadini/scoders-back

## Overview

##### Project type and purpose
- This is a NestJS-based server-side application written in TypeScript. It exposes REST endpoints (via Controllers) and a WebSocket gateway for real-time communication, implements authentication, user management, and product management, and persists data in MongoDB via Mongoose.

##### File structure to uncover architectural choices
- Top-level “src” folder broken into feature modules: auth/, user/, product/, plus shared/ for cross-cutting concerns.
- Each feature module follows the “Controller → Service → Repository” pattern and houses DTOs, schemas, and (in product/) a WebSocket gateway.
- Global pipes, filters, interceptors, and guards live in shared/.
- Configuration files (nest-cli.json, tsconfig.json, Dockerfile) enable build, linting, formatting, containerization, and CI/CD (via .github/workflows/main.yml).

##### README for tech stack
- NestJS framework (Express by default), TypeScript, Mongoose (MongoDB), Docker, GitHub Actions.
- Testing harness: Jest for unit and e2e tests.
- Validation pipe uses Zod under the hood.

##### Main components
a. NestJS HTTP Server (Express/Fastify adapter)
b. Middleware & Global Utilities
- Redoc middleware (serves API docs)
- HTTP exception filter
- Logging interceptor
- Cache interceptor
- Zod validation pipe
- Auth guard
c. Feature Modules (loaded into Nest’s DI container)
- AuthModule (AuthController → AuthService)
- UserModule (UserController → UserService → UserRepository)
- ProductModule (ProductController, ProductGateway → ProductService → ProductRepository)
d. Data Layer
- Repositories using Mongoose
- MongoDB database (collections: users, products)
e. External & DevOps
- Docker container
- CI/CD pipeline (GitHub Actions)
- Prettier, ESLint, Nest CLI

##### Interactions & Data Flow
- REST flow: Client → HTTP Server → (Middleware → Guard → Interceptor → Pipe) → Controller → Service → Repository → MongoDB → Service → Controller → HTTP Response
- WebSocket flow: Client WS → ProductGateway → ProductService → ProductRepository → MongoDB → ProductGateway (Broadcast)
- CI/CD: Commits → GitHub Actions → Docker build → Test suite → Push image to registry

##### Architectural patterns & principles
- Modular Monolith: logically separated modules, single process
- Dependency Injection: all controllers/services/repositories injected by Nest
- Layered Architecture: Presentation (HTTP/WS) → Business (Services) → Data (Repositories)
- Cross-cutting concerns centralized in shared/

##### Essential elements
- A middleware/interceptor pipeline in front of controllers
- Authentication guard sitting between middleware and controllers
- Docker boundary around the NestJS application
- CI/CD flow upstream of container build

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Docker boundary
    subgraph "Docker Container" 
        direction TB
        NestServer["NestJS HTTP Server\n(main.ts)"]:::server
        click NestServer "https://github.com/marcelotadini/scoders-back/blob/main/src/main.ts"

        %% Global middleware and utilities pipeline
        Redoc["Redoc Middleware"]:::middleware
        click Redoc "https://github.com/marcelotadini/scoders-back/blob/main/src/shared/middlewares/redoc.middleware.ts"
        HttpFilter["HTTP Exception Filter"]:::middleware
        click HttpFilter "https://github.com/marcelotadini/scoders-back/blob/main/src/shared/filters/http-exception.filter.ts"
        Logging["Logging Interceptor"]:::middleware
        click Logging "https://github.com/marcelotadini/scoders-back/blob/main/src/shared/interceptors/logging.interceptor.ts"
        Cache["Cache Interceptor"]:::middleware
        click Cache "https://github.com/marcelotadini/scoders-back/blob/main/src/shared/interceptors/cache.inteceptor.ts"
        ZodPipe["Zod Validation Pipe"]:::middleware
        click ZodPipe "https://github.com/marcelotadini/scoders-back/blob/main/src/shared/pipe/zod-validation.pipe.ts"
        AuthGuard["Auth Guard"]:::middleware
        click AuthGuard "https://github.com/marcelotadini/scoders-back/blob/main/src/shared/guards/auth.guard.ts"

        NestServer --> Redoc --> HttpFilter --> Logging --> Cache --> ZodPipe --> AuthGuard

        %% Feature Modules
        subgraph "Auth Module" 
            direction TB
            AuthController["AuthController"]:::controller
            click AuthController "https://github.com/marcelotadini/scoders-back/blob/main/src/auth/controllers/auth.controller.ts"
            AuthService["AuthService"]:::service
            click AuthService "https://github.com/marcelotadini/scoders-back/blob/main/src/auth/services/auth.service.ts"
            AuthController --> AuthService
        end
        click AuthModule "https://github.com/marcelotadini/scoders-back/blob/main/src/auth/auth.module.ts"
        class AuthModule module
        AuthModule["AuthModule"]:::module
        AuthModule --> AuthController

        subgraph "User Module" 
            direction TB
            UserController["UserController"]:::controller
            click UserController "https://github.com/marcelotadini/scoders-back/blob/main/src/user/controllers/user.controller.ts"
            UserService["UserService"]:::service
            click UserService "https://github.com/marcelotadini/scoders-back/blob/main/src/user/services/user.service.ts"
            UserRepo["UserRepository"]:::repository
            click UserRepo "https://github.com/marcelotadini/scoders-back/blob/main/src/user/repositories/user.repository.ts"
            MongooseUserRepo["UserMongooseRepository"]:::repository
            click MongooseUserRepo "https://github.com/marcelotadini/scoders-back/blob/main/src/user/repositories/mongoose/user.mongoose.repository.ts"
            UserController --> UserService --> UserRepo --> MongooseUserRepo
        end
        click UserModule "https://github.com/marcelotadini/scoders-back/blob/main/src/user/user.module.ts"
        UserModule["UserModule"]:::module
        UserModule --> UserController

        subgraph "Product Module"
            direction TB
            ProdController["ProductController"]:::controller
            click ProdController "https://github.com/marcelotadini/scoders-back/blob/main/src/product/controllers/product.controller.ts"
            ProdGateway["ProductGateway"]:::gateway
            click ProdGateway "https://github.com/marcelotadini/scoders-back/blob/main/src/product/gateways/product.gateway.ts"
            ProdService["ProductService"]:::service
            click ProdService "https://github.com/marcelotadini/scoders-back/blob/main/src/product/services/product.service.ts"
            ProdRepo["ProductRepository"]:::repository
            click ProdRepo "https://github.com/marcelotadini/scoders-back/blob/main/src/product/repositories/product.repository.ts"
            MongooseProdRepo["ProductMongooseRepository"]:::repository
            click MongooseProdRepo "https://github.com/marcelotadini/scoders-back/blob/main/src/product/repositories/mongoose/product.mongoose.repository.ts"
            ProdController --> ProdService
            ProdGateway --> ProdService
            ProdService --> ProdRepo --> MongooseProdRepo
        end
        click ProductModule "https://github.com/marcelotadini/scoders-back/blob/main/src/product/product.module.ts"
        ProductModule["ProductModule"]:::module
        ProductModule --> ProdController
        ProductModule --> ProdGateway

        %% Shared utilities injection arrows
        AuthGuard --> AuthController
        AuthGuard --> UserController
        AuthGuard --> ProdController
        AuthGuard --> ProdGateway
    end

    %% Database
    MongoDB["MongoDB\n(users, products)"]:::database
    MongooseUserRepo -->|uses| MongoDB
    MongooseProdRepo -->|uses| MongoDB

    %% CI/CD pipeline
    Commits["Developer Commits"]:::external
    CI["GitHub Actions CI/CD"]:::ci
    click CI "https://github.com/marcelotadini/scoders-back/blob/main/.github/workflows/main.yml"
    DockerBuild["Docker Build"]:::ci
    Commits --> CI --> DockerBuild -->|builds image| DockerContainer
    class DockerContainer docker

    %% Config files
    NestCLI["nest-cli.json"]:::config
    TSConfig["tsconfig.json\n& tsconfig.build.json"]:::config
    ESLint["eslint.config.mjs"]:::config
    Prettier[".prettierrc"]:::config
    Dockerfile["Dockerfile"]:::config

    %% Testing
    E2E["E2E Tests (test/app.e2e-spec.ts)"]:::test
    AuthSpec["Auth Guard Spec"]:::test
    click AuthSpec "https://github.com/marcelotadini/scoders-back/blob/main/src/shared/guards/auth.guard.spec.ts"
    LogSpec["Logging Interceptor Spec"]:::test
    click LogSpec "https://github.com/marcelotadini/scoders-back/blob/main/src/shared/interceptors/logging.interceptor.spec.ts"

    %% Styles
    classDef server fill:#f9f,stroke:#333,stroke-width:1px
    classDef middleware fill:#ffa500,stroke:#333,stroke-width:1px
    classDef module fill:#add8e6,stroke:#333,stroke-width:1px
    classDef controller fill:#87cefa,stroke:#333,stroke-width:1px
    classDef service fill:#00bfff,stroke:#333,stroke-width:1px
    classDef repository fill:#1e90ff,stroke:#333,stroke-width:1px
    classDef gateway fill:#dda0dd,stroke:#333,stroke-width:1px
    classDef database fill:#90ee90,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef ci fill:#9370db,stroke:#333,stroke-width:1px
    classDef docker fill:#ffe4b5,stroke:#333,stroke-width:1px
    classDef config fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef test fill:#ffb6c1,stroke:#333,stroke-width:1px

    %% Invisible link
    DockerContainer([" "])
```
