# linkmetal/phone-catalog-back architecture

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

- Interactive diagram: https://gitdiagram.com/linkmetal/phone-catalog-back
- Repository: https://github.com/linkmetal/phone-catalog-back

## Overview

##### Project type and purpose
- This is a backend API service (NestJS) that exposes REST endpoints to manage a phone catalog.
- It uses MongoDB (via Mongoose) for data persistence, Cloudinary for hosting images, and Swagger for API documentation.

##### File structure
- Top-level files:
- Dockerfile, docker-compose.yml, Procfile, .env.example – deployment and environment setup.
- nest-cli.json, tsconfig*.json, package.json – build and tooling.
- src/ directory:
- src/main.ts – application entrypoint.
- src/app.module.ts – root NestJS module.
- src/phones/* – PhonesModule (controllers, services, DTOs, schemas, repository interfaces & implementations).
- src/cloudinary/* – CloudinaryModule (provider, service).
- src/config.ts – global configuration provider.
- src/types/PaginatedResponse.ts – shared type.
- scripts/ – initialization of Mongo users.
- test/ – Jest e2e and unit tests.

##### Insights from README
- Features: phone catalog CRUD, image uploads to Cloudinary.
- Tech stack: TypeScript, NestJS, Mongoose/MongoDB, Cloudinary, Swagger, Jest.
- Deployment: Docker, Heroku (Procfile), GitHub Actions for CI.

##### Elements
- Labels: name each module/component clearly (e.g., PhonesController, PhonesService, PhonesRepository).
- Rectangles (light blue) for application layers/modules
- Clouds (yellow) for external services (Cloudinary)

##### Detailed capturing of architectural elements
- Configuration injection path (ConfigModule → other modules).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph Clients
        REST["REST Clients"]:::client
        SwaggerUI["Swagger UI"]:::client
    end

    subgraph "NestJS API"
        direction TB
        Entry["main.ts"]:::entrypoint
        AppModule["app.module.ts"]:::module
        Config["Config Module"]:::module
        PhonesModule["PhonesModule"]:::module
        CloudModule["CloudinaryModule"]:::module

        Entry --> AppModule
        AppModule --> Config
        AppModule --> PhonesModule
        AppModule --> CloudModule

        subgraph "Phones Module"
            direction TB
            PhonesController["PhonesController"]:::controller
            PhonesService["PhonesService"]:::service
            PhonesRepoIface["PhonesRepository Interface"]:::repository
            PhonesRepoMongo["PhonesRepository Mongo"]:::repository
            PhonesRepoFake["PhonesRepository Fake"]:::repository
            PhoneSchema["Phone Schema"]:::schema

            PhonesController --> PhonesService
            PhonesService --> PhonesRepoIface
            PhonesRepoIface --> PhonesRepoMongo
            PhonesRepoIface --> PhonesRepoFake
            PhonesRepoMongo --> PhoneSchema
        end

        subgraph "Cloudinary Module"
            direction TB
            CloudProvider["Cloudinary Provider"]:::provider
            CloudService["CloudinaryService"]:::service
            CloudService --> CloudProvider
        end

        Config --> PhonesModule
        Config --> CloudModule

        Paginated["PaginatedResponse"]:::type
        PhonesService --> Paginated
    end

    REST -->|HTTP| PhonesController
    SwaggerUI -->|HTTP| Entry

    subgraph Database
        MongoDB["MongoDB"]:::db
    end

    subgraph External
        Cloudinary["Cloudinary"]:::external
    end

    PhonesRepoMongo -->|reads/writes| MongoDB
    CloudService -->|uploads| Cloudinary

    subgraph Deployment/CI/CD
        direction TB
        DockerEngine["Docker Engine"]:::tool
        DockerCompose["docker-compose.yml"]:::tool
        Heroku["Heroku"]:::tool
        GitHubActions["GitHub Actions"]:::tool
        InitScript["Mongo Init Script"]:::script
        EnvExample[".env.example"]:::tool

        DockerEngine -->|build| DockerCompose
        GitHubActions -->|CI/CD| DockerEngine
        GitHubActions -->|deploy| Heroku
    end

    %% Click Events
    click Entry "https://github.com/linkmetal/phone-catalog-back/blob/master/src/main.ts"
    click AppModule "https://github.com/linkmetal/phone-catalog-back/blob/master/src/app.module.ts"
    click Config "https://github.com/linkmetal/phone-catalog-back/blob/master/src/config.ts"
    click PhonesModule "https://github.com/linkmetal/phone-catalog-back/blob/master/src/phones/phones.module.ts"
    click PhonesController "https://github.com/linkmetal/phone-catalog-back/blob/master/src/phones/phones.controller.ts"
    click PhonesService "https://github.com/linkmetal/phone-catalog-back/blob/master/src/phones/phones.service.ts"
    click PhonesRepoIface "https://github.com/linkmetal/phone-catalog-back/blob/master/src/phones/phones.repository.ts"
    click PhonesRepoMongo "https://github.com/linkmetal/phone-catalog-back/blob/master/src/phones/phones.repository.mongodb.ts"
    click PhonesRepoFake "https://github.com/linkmetal/phone-catalog-back/blob/master/src/phones/phones.repository.fake.ts"
    click PhoneSchema "https://github.com/linkmetal/phone-catalog-back/blob/master/src/phones/schemas/phone.schema.ts"
    click CloudModule "https://github.com/linkmetal/phone-catalog-back/blob/master/src/cloudinary/cloudinary.module.ts"
    click CloudProvider "https://github.com/linkmetal/phone-catalog-back/blob/master/src/cloudinary/cloudinary.provider.ts"
    click CloudService "https://github.com/linkmetal/phone-catalog-back/blob/master/src/cloudinary/cloudinary.service.ts"
    click Paginated "https://github.com/linkmetal/phone-catalog-back/blob/master/src/types/PaginatedResponse.ts"
    click InitScript "https://github.com/linkmetal/phone-catalog-back/blob/master/scripts/mongo-init.js"
    click DockerCompose "https://github.com/linkmetal/phone-catalog-back/blob/master/docker-compose.yml"
    click Heroku "https://github.com/linkmetal/phone-catalog-back/tree/master/Procfile"
    click EnvExample "https://github.com/linkmetal/phone-catalog-back/blob/master/.env.example"
    click GitHubActions "https://github.com/linkmetal/phone-catalog-back/blob/master/.github/workflows/node.js.yml"

    classDef client fill:#ffe699,stroke:#000;
    classDef entrypoint fill:#cfe2f3,stroke:#000;
    classDef module fill:#cfe2f3,stroke:#000;
    classDef controller fill:#c9daf8,stroke:#000;
    classDef service fill:#b6d7a8,stroke:#000;
    classDef repository fill:#d9ead3,stroke:#000;
    classDef schema fill:#ead1dc,stroke:#000;
    classDef provider fill:#d0e0e3,stroke:#000;
    classDef db fill:#b6d7a8,stroke:#000,stroke-width:1px;
    classDef external fill:#fff2cc,stroke:#000;
    classDef tool fill:#e2efda,stroke:#000;
    classDef script fill:#d9d2e9,stroke:#000;
    classDef type fill:#f4cccc,stroke:#000;
```
