# cdkooistra/url-shortener architecture

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

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

## Overview

##### Project Type and Main Components
- This is clearly a microservices-based full-stack backend API. There are two distinct microservices:
- The “app” service: Likely the main URL shortening service handling URL creation, redirection, and related logic.
- The “auth” service: Dedicated to user authentication, token management (notably using JWT as seen in auth/jwt.py), and possibly authorization.
- Additional components include a PostgreSQL database (as evidenced by the Kubernetes deployment files: postgres-deployment.yaml and postgres-service.yaml) and the containerization/orchestration layer (Docker & Kubernetes).

- Two separate directories—app and auth—indicate that these are self-contained services with their own routes, models, schemas, services, and utility functions.
- Their individual Dockerfiles (docker/app.Dockerfile and docker/auth.Dockerfile) and Kubernetes deployment/service YAML files confirm that they run in separate containers.
- The project also contains configuration files (requirements.txt, .dockerignore, .gitignore) and tests, implying a well-organized development and deployment pipeline.

##### Architectural Pattern and Design Principles
- The design follows a microservices architecture where each service is independently deployable.
- There’s a clear separation of concerns: the “app” for core URL shortening functionalities, and “auth” for managing security (authentication/authorization).
- Docker and Kubernetes are used to package, deploy, and scale services.
- The use of JWT for authentication and secure communications is an important design detail.

- Client/User Interface: Although not provided explicitly, assume external clients interact via API calls.
- App Service (URL Shortener):
- Handles the main business logic for generating and redirecting shortened URLs.
- Communicates with the PostgreSQL database for storing URL mappings.
- May interact with the Auth service if authentication is needed.
- Auth Service:
- Manages user authentication, token generation (via JWT), and possibly authorization.
- Provides an API endpoint for authentication requests.
- PostgreSQL Database:
- Stores persistent data for URL mappings, user credentials, and other persistent entities.
- Container and Orchestration Layer:
- Docker: Represent the containerization of each service.
- Kubernetes: Illustrate deployments and services configuration (for app, auth, and PostgreSQL), emphasizing scalability and service discovery.

##### Final Assembly
- Optionally, add a layer that represents the container orchestration environment (marking Docker and Kubernetes features), which encapsulates the deployment orchestration of the microservices.

Happy diagramming!

## Diagram (Mermaid)

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

    subgraph "Microservices Layer"
        AppService["App Service (URL Shortener)"]:::service
        AuthService["Auth Service (JWT Authentication)"]:::service
        Postgres["PostgreSQL Database"]:::database
    end

    subgraph "Container Orchestration"
        Docker["Docker Containers"]:::orchestration
        K8s["Kubernetes Orchestration"]:::orchestration
    end

    External -->|"API_request"| AppService
    AppService -->|"auth_call"| AuthService
    AppService -->|"read/write"| Postgres
    AuthService -->|"read/write"| Postgres

    Docker -->|"containerizes"| AppService
    Docker -->|"containerizes"| AuthService
    K8s -->|"orchestrates"| Docker
    K8s -->|"manages"| Postgres

    click AppService "https://github.com/cdkooistra/url-shortener/tree/main/app/"
    click AppService "https://github.com/cdkooistra/url-shortener/blob/main/docker/app.Dockerfile"
    click AppService "https://github.com/cdkooistra/url-shortener/blob/main/kubernetes/app-deployment.yaml"
    click AppService "https://github.com/cdkooistra/url-shortener/blob/main/kubernetes/app-service.yaml"

    click AuthService "https://github.com/cdkooistra/url-shortener/tree/main/auth/"
    click AuthService "https://github.com/cdkooistra/url-shortener/blob/main/docker/auth.Dockerfile"
    click AuthService "https://github.com/cdkooistra/url-shortener/blob/main/kubernetes/auth-deployment.yaml"
    click AuthService "https://github.com/cdkooistra/url-shortener/blob/main/kubernetes/auth-service.yaml"

    click Postgres "https://github.com/cdkooistra/url-shortener/blob/main/kubernetes/postgres-deployment.yaml"
    click Postgres "https://github.com/cdkooistra/url-shortener/blob/main/kubernetes/postgres-service.yaml"

    click Docker "https://github.com/cdkooistra/url-shortener/tree/main/docker/"
    click K8s "https://github.com/cdkooistra/url-shortener/tree/main/kubernetes/"

    classDef external fill:#a2d5c6,stroke:#333,stroke-width:2px
    classDef service fill:#ffd966,stroke:#333,stroke-width:2px
    classDef database fill:#f4cccc,stroke:#333,stroke-width:2px
    classDef orchestration fill:#cfe2f3,stroke:#333,stroke-width:2px
```
