# mohammadforoutan/url-shortener-nestjs architecture

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

- Interactive diagram: https://gitdiagram.com/mohammadforoutan/url-shortener-nestjs
- Repository: https://github.com/mohammadforoutan/url-shortener-nestjs

## Overview

This is a NestJS URL-shortening service. Its principal workflow is authenticated URL creation or update, persistence, and public short-link resolution; a parallel workflow handles registration, login, and email verification. The graph captures the visible HTTP-to-use-case calls and sampled TypeORM transaction flow. Analytics/reporting is described in the README, but the supplied tree contains no corresponding analytics implementation, so it is not modeled as a runtime component. Other use-case-to-port wiring is left unverified where source excerpts do not show it.

Main entry points: [`src/infra/persistence/database/typeorm/repositories/typeorm-user.repository.ts`](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/persistence/database/typeorm/repositories/typeorm-user.repository.ts) (User repository), [`src/infra/persistence/database/typeorm/typeorm-database.module.ts`](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/persistence/database/typeorm/typeorm-database.module.ts) (TypeORM module), [`src/infra/persistence/database/typeorm/repositories/typeorm-url.repository.ts`](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/persistence/database/typeorm/repositories/typeorm-url.repository.ts) (URL repository), [`src/application/usecases/user`](https://github.com/mohammadforoutan/url-shortener-nestjs/tree/master/src/application/usecases/user) (User use cases)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP API"]
  node_httpmod["HTTP module<br/>[http.module.ts]"]
  node_urlapi["URL controller<br/>[url.controller.ts]"]
  node_authapi["Auth controller<br/>[auth.controller.ts]"]
end

subgraph group_application["Application workflows"]
  node_urlflows["URL use cases"]
  node_userflows["User use cases"]
  node_urlport["URL repository port<br/>[url.repository.ts]"]
  node_userport["User repository port<br/>[user.repository.ts]"]
end

subgraph group_domain["Domain model"]
  node_urlmodel["URL aggregate<br/>[url.ts]"]
  node_usermodel["User aggregate<br/>[user.ts]"]
end

subgraph group_infra["Infrastructure"]
  node_bootstrap["Nest bootstrap<br/>[main.ts]"]
  node_root["Root module<br/>[app.module.ts]"]
  node_typeorm["TypeORM module"]
  node_urlrepo["URL repository"]
  node_userrepo["User repository"]
  node_uow["Transaction manager"]
  node_entities["ORM entities"]
  node_email["Email adapter<br/>[email.service.ts]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]

node_client -.->|"sends requests"| node_bootstrap
node_bootstrap -->|"creates app"| node_root
node_root -->|"imports infrastructure"| node_httpmod
node_urlapi -->|"executes"| node_urlflows
node_authapi -->|"executes"| node_userflows
node_urlflows -.->|"uses"| node_urlport
node_userflows -.->|"uses"| node_userport
node_urlrepo -->|"runs transactions"| node_uow
node_userrepo -->|"runs transactions"| node_uow
node_userrepo -->|"queries and saves"| node_entities
node_typeorm -->|"binds repository"| node_urlrepo
node_typeorm -->|"binds repository"| node_userrepo
node_typeorm -->|"connects to"| node_postgres
node_urlrepo -.->|"maps domain"| node_urlmodel
node_userrepo -->|"maps domain"| node_usermodel
node_email -.->|"sends verification"| node_userflows

click node_bootstrap "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/main.ts"
click node_root "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/app.module.ts"
click node_httpmod "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/api/http/http.module.ts"
click node_urlapi "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/api/http/v1/url.controller.ts"
click node_authapi "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/api/http/v1/auth.controller.ts"
click node_urlflows "https://github.com/mohammadforoutan/url-shortener-nestjs/tree/master/src/application/usecases/url"
click node_userflows "https://github.com/mohammadforoutan/url-shortener-nestjs/tree/master/src/application/usecases/user"
click node_urlport "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/application/ports/url.repository.ts"
click node_userport "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/application/ports/user.repository.ts"
click node_urlmodel "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/domain/url/entities/url.ts"
click node_usermodel "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/domain/user/entities/user.ts"
click node_typeorm "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/persistence/database/typeorm/typeorm-database.module.ts"
click node_urlrepo "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/persistence/database/typeorm/repositories/typeorm-url.repository.ts"
click node_userrepo "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/persistence/database/typeorm/repositories/typeorm-user.repository.ts"
click node_uow "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/persistence/database/typeorm/unit-of-work/unit-of-work.service.ts"
click node_entities "https://github.com/mohammadforoutan/url-shortener-nestjs/tree/master/src/infra/persistence/database/typeorm/entities"
click node_email "https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/adaptors/email.service.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_httpmod,node_urlapi,node_authapi,node_client toneBlue
class node_urlflows,node_userflows,node_urlport,node_userport,node_postgres toneAmber
class node_urlmodel,node_usermodel toneMint
class node_bootstrap,node_root,node_typeorm,node_urlrepo,node_userrepo,node_uow,node_entities,node_email toneRose
```

## Components

### HTTP API

- [HTTP module](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/api/http/http.module.ts): `src/infra/api/http/http.module.ts`
- [URL controller](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/api/http/v1/url.controller.ts): `src/infra/api/http/v1/url.controller.ts`
- [Auth controller](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/api/http/v1/auth.controller.ts): `src/infra/api/http/v1/auth.controller.ts`

### Application workflows

- [URL use cases](https://github.com/mohammadforoutan/url-shortener-nestjs/tree/master/src/application/usecases/url): `src/application/usecases/url`
- [User use cases](https://github.com/mohammadforoutan/url-shortener-nestjs/tree/master/src/application/usecases/user): `src/application/usecases/user`
- [URL repository port](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/application/ports/url.repository.ts): `src/application/ports/url.repository.ts`
- [User repository port](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/application/ports/user.repository.ts): `src/application/ports/user.repository.ts`

### Domain model

- [URL aggregate](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/domain/url/entities/url.ts): `src/domain/url/entities/url.ts`
- [User aggregate](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/domain/user/entities/user.ts): `src/domain/user/entities/user.ts`

### Infrastructure

- [Nest bootstrap](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/main.ts): `src/main.ts`
- [Root module](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/app.module.ts): `src/app.module.ts`
- [TypeORM module](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/persistence/database/typeorm/typeorm-database.module.ts): `src/infra/persistence/database/typeorm/typeorm-database.module.ts`
- [URL repository](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/persistence/database/typeorm/repositories/typeorm-url.repository.ts): `src/infra/persistence/database/typeorm/repositories/typeorm-url.repository.ts`
- [User repository](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/persistence/database/typeorm/repositories/typeorm-user.repository.ts): `src/infra/persistence/database/typeorm/repositories/typeorm-user.repository.ts`
- [Transaction manager](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/persistence/database/typeorm/unit-of-work/unit-of-work.service.ts): `src/infra/persistence/database/typeorm/unit-of-work/unit-of-work.service.ts`
- [ORM entities](https://github.com/mohammadforoutan/url-shortener-nestjs/tree/master/src/infra/persistence/database/typeorm/entities): `src/infra/persistence/database/typeorm/entities`
- [Email adapter](https://github.com/mohammadforoutan/url-shortener-nestjs/blob/master/src/infra/adaptors/email.service.ts): `src/infra/adaptors/email.service.ts`

### Other components

- **API client**
- **PostgreSQL**

## Connections

- API client → Nest bootstrap: sends requests (evidence: `src/main.ts`)
- Nest bootstrap → Root module: creates app (evidence: `src/main.ts`)
- Root module → HTTP module: imports infrastructure (evidence: `src/app.module.ts`)
- URL controller → URL use cases: executes (evidence: `src/infra/api/http/v1/url.controller.ts`)
- Auth controller → User use cases: executes (evidence: `src/infra/api/http/v1/auth.controller.ts`)
- URL use cases → URL repository port: uses
- User use cases → User repository port: uses
- URL repository → Transaction manager: runs transactions (evidence: `src/infra/persistence/database/typeorm/repositories/typeorm-url.repository.ts`)
- User repository → Transaction manager: runs transactions (evidence: `src/infra/persistence/database/typeorm/repositories/typeorm-user.repository.ts`)
- User repository → ORM entities: queries and saves (evidence: `src/infra/persistence/database/typeorm/repositories/typeorm-user.repository.ts`)
- TypeORM module → URL repository: binds repository (evidence: `src/infra/persistence/database/typeorm/typeorm-database.module.ts`)
- TypeORM module → User repository: binds repository (evidence: `src/infra/persistence/database/typeorm/typeorm-database.module.ts`)
- TypeORM module → PostgreSQL: connects to (evidence: `src/infra/persistence/database/typeorm/typeorm-database.module.ts`)
- URL repository → URL aggregate: maps domain
- User repository → User aggregate: maps domain (evidence: `src/infra/persistence/database/typeorm/repositories/typeorm-user.repository.ts`)
- Email adapter → User use cases: sends verification
