# shukla-ashu/url-shortner-service architecture

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

- Interactive diagram: https://gitdiagram.com/shukla-ashu/url-shortner-service
- Repository: https://github.com/shukla-ashu/url-shortner-service

## Overview

##### Project type and purpose
- This is a backend service: a RESTful URL shortener built with Java and Spring Boot.
- Purpose: generate compact, shareable short URLs for given long URLs and redirect requests efficiently, using Redis for cache and MongoDB for persistence.

##### File structure
- Top-level artifacts:
- pom.xml, Maven wrapper files → Java/Spring Boot project built with Maven
- src/main/java/io/skycrate/urlshortner → application entry and package root
- configuration, controller, service, repository, mapper, model, strategy directories → layered architecture
- src/main/resources/application.properties → externalized configuration for MongoDB/Redis
- Tests under src/test/java mirror main packages → unit/integration tests for each layer

##### README for additional insights
- It outlines a 5-layer architecture: Controller → Service → Strategy → Repository → Database/Cache
- Technology stack: Java 17+, Spring Boot, MongoDB, Redis
- Describes API endpoints (`POST /api/shorten`, `GET /{shortUrl}`)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client"]:::external

    %% Application Entry
    App["UrlShortnerServiceApplication"]:::app

    %% Controller Layer
    subgraph "Controller Layer"
        direction TB
        UrlCtrl["UrlController"]:::http
        RedirCtrl["RedirectionController"]:::http
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        USvcIntf["UrlShortnerService"]:::business
        RSvcIntf["RedirectionService"]:::business
        USvcImpl["UrlShortnerServiceImpl"]:::business
        RSvcImpl["RedirectionServiceImpl"]:::business
    end

    %% Strategy Layer
    subgraph "Strategy Layer"
        direction TB
        StrategyIntf["UrlShortenerStrategy"]:::business
        Base62["Base62Encoding"]:::business
        Context["UrlShortnerContext"]:::business
    end

    %% Repository Layer
    subgraph "Repository Layer"
        direction TB
        Repo["UrlShortnerRepository"]:::data
    end

    %% Data Models
    subgraph "Data Models"
        direction TB
        SeqCnt["SequenceCounter"]:::data
        ShortDoc["ShortUrlDocument"]:::data
        ReqDTO["ShortUrlRequest"]:::data
        ResDTO["ShortUrlResponse"]:::data
        Mapper["ShortUrlMapper"]:::data
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        Redis["Redis Cache"]:::db
        Mongo["MongoDB"]:::db
    end

    %% Configuration
    Config["RedisConfig"]:::config
    Props["application.properties"]:::config

    %% Connections
    Client -->|"POST /api/shorten\nGET /{shortUrl}"| UrlCtrl
    UrlCtrl -->|"delegates to"| USvcIntf
    UrlCtrl -->|redirect request| RedirCtrl
    RedirCtrl -->|"delegates to"| RSvcIntf

    USvcIntf -->|"implemented by"| USvcImpl
    RSvcIntf -->|"implemented by"| RSvcImpl

    USvcImpl -->|"uses"| StrategyIntf
    RSvcImpl -->|"uses"| StrategyIntf

    StrategyIntf -->|"context chooses"| Base62
    Context -->|"invokes"| Base62

    USvcImpl -->|"calls save/find"| Repo
    RSvcImpl -->|"calls find"| Repo

    Repo -->|"cache-aside get/put"| Redis
    Redis -->|"fallback to"| Mongo
    Repo -->|"read/write"| Mongo

    USvcImpl -->|"maps DTO"| Mapper
    UrlCtrl -->|"maps request/response"| Mapper

    App -->|startup loads| Config
    Config -->|reads| Props

    %% Click Events
    click App "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/UrlShortnerServiceApplication.java"
    click Config "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/configuration/RedisConfig.java"
    click UrlCtrl "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/controller/UrlController.java"
    click RedirCtrl "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/controller/RedirectionController.java"
    click USvcIntf "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/service/UrlShortnerService.java"
    click RSvcIntf "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/service/RedirectionService.java"
    click USvcImpl "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/service/impl/UrlShortnerServiceImpl.java"
    click RSvcImpl "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/service/impl/RedirectionServiceImpl.java"
    click StrategyIntf "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/strategy/UrlShortenerStrategy.java"
    click Base62 "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/strategy/Base62Encoding.java"
    click Context "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/strategy/UrlShortnerContext.java"
    click Repo "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/repository/UrlShortnerRepository.java"
    click SeqCnt "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/model/database/SequenceCounter.java"
    click ShortDoc "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/model/database/ShortUrlDocument.java"
    click ReqDTO "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/model/request/ShortUrlRequest.java"
    click ResDTO "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/model/response/ShortUrlResponse.java"
    click Mapper "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/java/io/skycrate/urlshortner/mapper/ShortUrlMapper.java"
    click Props "https://github.com/shukla-ashu/url-shortner-service/blob/main/src/main/resources/application.properties"

    %% Styles
    classDef external fill:#E0E0E0,stroke:#000;
    classDef app fill:#B0E0E6,stroke:#000;
    classDef http fill:#ADD8E6,stroke:#000;
    classDef business fill:#90EE90,stroke:#000;
    classDef data fill:#FFA500,stroke:#000;
    classDef db fill:#F5DEB3,stroke:#000;
    classDef config fill:#FFE4B5,stroke:#000;
```
