# nehoko/shorty architecture

> Architecture diagram of the GitHub repository nehoko/shorty, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nehoko/shorty
- Repository: https://github.com/nehoko/shorty

## Overview

##### Main Components

a) Client Interface Layer:
- HTTP API endpoints (represented in router.ts)
- Incoming requests for URL shortening and URL retrieval

b) Service Layer:
- ShortyService (from src/ShortyService.ts)
- URL processing and management logic
- Connection to string utilities (stringUtils.ts)

c) Data Layer:
- Database component (from src/Database.ts)
- Storage for URL mappings
- UrlDto model representation

##### Key Relationships to Highlight

**[Client] → [Router Layer] → [Service Layer] → [Database Layer]**

##### Specific Implementation Details

- Main application entry (main.ts)
- Configuration handling (environment variables)
- URL DTO model (src/model/UrlDto.ts)
- String utility functions (stringUtils.ts)

##### Technical Specifications

Annotations showing:
- Deno runtime environment
- URL lifetime management (MAX_LIFETIME_IN_DAYS)
- Retry mechanism (MAX_RETRIES)
- URL length constraints (SHORT_URL_MAX_LENGTH)

**┌─────────────────────────────────────────┐**
- Client Request             │
- ┬───────────────────────┘
- ↓
**┌─────────────────────────────────────────┐**
- Router (router.ts)           │
- ┬───────────────────────┘
- ↓
**┌─────────────────────────────────────────┐**
- ShortyService (Service Layer)    │
- ┐ ┌───────────────────┐ │
- String Utils   │ │    URL Processing │ │
- ┘ └───────────────────┘ │
- ┬───────────────────────┘
- ↓
**┌─────────────────────────────────────────┐**
- Database (Database.ts)          │
- ┘

##### Technical Notes

- The stateless nature of the service
- The URL validation and processing flow
- Database interaction patterns
- Configuration management
- Error handling and retry mechanisms

Remember to maintain a balance between showing enough detail to understand the system while keeping it clean and readable. The focus should be on the core URL shortening functionality and its supporting components.

- How requests flow through the system
- Where different types of processing occur
- How data is stored and retrieved
- How configuration affects the system
- Where to find specific functionality in the codebase

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CR[Client Request]
    end

    subgraph Router
        RT["Router"]:::router
    end

    subgraph Service
        SS["ShortyService"]:::service
        SU["String Utils"]:::util
    end

    subgraph Data
        DB["Database"]:::database
        DTO["URL DTO Model"]:::model
    end

    subgraph Configuration
        CF["Environment Config"]:::config
        TF["Test Framework"]:::test
    end

    subgraph Technical
        IN["Initialization"]:::init
        AP["Application Entry"]:::main
        DW["Deployment Workflow"]:::deploy
    end

    CR --> RT
    RT --> SS
    SS --> SU
    SS --> DB
    DB --> DTO
    CF --> SS
    CF --> DB
    IN --> AP
    AP --> RT
    TF -.-> SS

    %% Component Mappings
    click RT "https://github.com/Nehoko/shorty/blob/main/src/router.ts"
    click SS "https://github.com/Nehoko/shorty/blob/main/src/ShortyService.ts"
    click DB "https://github.com/Nehoko/shorty/blob/main/src/Database.ts"
    click DTO "https://github.com/Nehoko/shorty/blob/main/src/model/UrlDto.ts"
    click SU "https://github.com/Nehoko/shorty/blob/main/src/stringUtils.ts"
    click AP "https://github.com/Nehoko/shorty/blob/main/main.ts"
    click IN "https://github.com/Nehoko/shorty/blob/main/init.ts"
    click TF "https://github.com/Nehoko/shorty/blob/main/test/main_test.ts"
    click CF "https://github.com/Nehoko/shorty/blob/main/deno.json"
    click DW "https://github.com/Nehoko/shorty/blob/main/.github/workflows/deploy.yml"

    %% Styling
    classDef router fill:#6C8EBF,stroke:#333,stroke-width:2px
    classDef service fill:#82B366,stroke:#333,stroke-width:2px
    classDef database fill:#D4E1F5,stroke:#333,stroke-width:2px
    classDef util fill:#FFE6CC,stroke:#333,stroke-width:2px
    classDef model fill:#F8CECC,stroke:#333,stroke-width:2px
    classDef config fill:#D5E8D4,stroke:#333,stroke-width:2px
    classDef test fill:#FFF2CC,stroke:#333,stroke-width:2px
    classDef init fill:#E1D5E7,stroke:#333,stroke-width:2px
    classDef main fill:#DAE8FC,stroke:#333,stroke-width:2px
    classDef deploy fill:#F5F5F5,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Router Component"]:::router
        L2["Service Component"]:::service
        L3["Database Component"]:::database
        L4["Utility Component"]:::util
        L5["Model Component"]:::model
        L6["Configuration"]:::config
        L7["Test Component"]:::test
    end
```
