# wtrbtl03/url-shortner architecture

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

- Interactive diagram: https://gitdiagram.com/wtrbtl03/url-shortner
- Repository: https://github.com/wtrbtl03/url-shortner

## Overview

##### Project type and purpose
- This is a Django-based full-stack web application that provides URL shortening functionality.
- The README points to a “getPico.Link” project, confirming this is an open-source URL shortener built on Django.

##### File structure
- Top-level Django project folder: URLShortner/ (contains settings, ASGI/Wsgi, urls).
- Two Django apps:
- home/ – likely handles the landing page, index view, basic templates.
- maps/ – contains models for URL ↔ code mapping, forms (input_field_form), resolve logic.
- Static assets: static/script.js, static/style.css.
- Templates: index.html, test.html, 404.html.
- Database: db.sqlite3.
- manage.py – entry point for dev commands.

##### Key insights from the README
- Uses Django’s built-in server stack (ASGI/Wsgi), SQLite for persistence.

##### Main components
a. Client Browser (User Interface)
– Renders HTML templates, runs script.js for dynamic form behavior, uses style.css.
b. Load Balancer / Web Server (optional in prod)
– Could be NGINX or Gunicorn/uvicorn to serve ASGI/Wsgi endpoints.
c. Django Application Layer
– URLShortner project module (settings, URL router)
– home app (views.index, views.test)
– maps app (views.create_short_url, views.resolve_short_url, input_field_form)
– Django Admin interface (home/admin.py, maps/admin.py)
d. Persistence Layer
– SQLite (db.sqlite3) storing URL mappings via maps.models
e. Static Asset Server or CDN
– Serves static/script.js, static/style.css
f. External Services (optional/extension)
– Could add caching (Redis) or analytics services

##### Relationships and data flows
1. Client → HTTP POST /create/short/ via maps app → Django views → maps.models.save(original_url, code) → DB insert.
2. Django → returns short URL in JSON or HTML response → Client displays it.
3. Client (or any user) → HTTP GET /`/ → maps.resolve view → DB lookup → HTTP 302 redirect to original URL.
4. home/index view serves landing page (HTTP GET /).
5. Static files served either by Django’s staticfiles or external server.
6. Django Admin → HTTP requests to /admin/ for CRUD management of URL entries.

##### Architectural patterns and design principles
- MVC/MVT pattern (Django’s Model-View-Template)
- Separation of concerns:
- home app for generic pages
- maps app for core URL mapping logic
- static/templates separated from Python code
- Single-database design (SQLite) – easy to swap to PostgreSQL in production.
- RESTful endpoints for create and resolve operations.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    Client["Client Browser"]:::client

    %% Web Server Layer
    WebServer["Nginx/Gunicorn (Web Server)"]:::web

    %% Django Application Layer
    subgraph "Django Application"
        Manage["manage.py"]:::entry
        DJProject["URLShortner Project\n(settings.py,\nasgi.py,\nwsgi.py,\nurls.py)"]:::core
        HomeApp["Home App\n(home/views.py,\nhome/urls.py,\nhome/admin.py,\nhome/models.py,\nhome/apps.py)"]:::app
        MapsApp["Maps App\n(maps/models.py,\nmaps/input_field_form.py,\nmaps/views.py,\nmaps/resolve.py,\nmaps/urls.py,\nmaps/admin.py,\nmaps/apps.py)"]:::app
        DjangoAdmin["Django Admin Interface"]:::admin
        subgraph "Templates"
            Index["index.html"]:::template
            TestT["test.html"]:::template
            NotFound["404.html"]:::template
        end
        subgraph "Documentation"
            README["README.md"]:::doc
            License["LICENSE"]:::doc
        end
    end

    %% Persistence Layer
    DB["SQLite Database\n(db.sqlite3)"]:::db

    %% Static Asset Layer
    StaticServer["Static Asset Server/CDN\n(script.js, style.css)"]:::static

    %% Connections
    Client -->|"HTTP GET / (landing page)"| WebServer
    Client -->|"HTTP POST /create/short"| WebServer
    Client -->|"HTTP GET /{code}"| WebServer
    WebServer -->|"WSGI/ASGI call"| DJProject
    DJProject -->|"routes to views"| HomeApp
    DJProject -->|"routes to views"| MapsApp
    DJProject -->|"routes to admin"| DjangoAdmin
    HomeApp -->|"renders templates"| Index
    HomeApp -->|"renders templates"| TestT
    HomeApp -->|"renders templates"| NotFound
    MapsApp -->|"reads/writes URL mappings"| DB
    HomeApp -->|"serves from"| StaticServer
    MapsApp -->|"serves from"| StaticServer
    StaticServer -->|"delivers JS/CSS"| Client
    DJProject -->|"runs via"| Manage

    %% Click Events
    click DJProject "https://github.com/wtrbtl03/url-shortner/blob/main/URLShortner/settings.py"
    click DJProject "https://github.com/wtrbtl03/url-shortner/blob/main/URLShortner/urls.py"
    click DJProject "https://github.com/wtrbtl03/url-shortner/blob/main/URLShortner/asgi.py"
    click DJProject "https://github.com/wtrbtl03/url-shortner/blob/main/URLShortner/wsgi.py"
    click Manage "https://github.com/wtrbtl03/url-shortner/blob/main/manage.py"
    click HomeApp "https://github.com/wtrbtl03/url-shortner/blob/main/home/views.py"
    click HomeApp "https://github.com/wtrbtl03/url-shortner/blob/main/home/urls.py"
    click HomeApp "https://github.com/wtrbtl03/url-shortner/blob/main/home/admin.py"
    click HomeApp "https://github.com/wtrbtl03/url-shortner/blob/main/home/models.py"
    click HomeApp "https://github.com/wtrbtl03/url-shortner/blob/main/home/apps.py"
    click MapsApp "https://github.com/wtrbtl03/url-shortner/blob/main/maps/models.py"
    click MapsApp "https://github.com/wtrbtl03/url-shortner/blob/main/maps/input_field_form.py"
    click MapsApp "https://github.com/wtrbtl03/url-shortner/blob/main/maps/views.py"
    click MapsApp "https://github.com/wtrbtl03/url-shortner/blob/main/maps/resolve.py"
    click MapsApp "https://github.com/wtrbtl03/url-shortner/blob/main/maps/urls.py"
    click MapsApp "https://github.com/wtrbtl03/url-shortner/blob/main/maps/admin.py"
    click MapsApp "https://github.com/wtrbtl03/url-shortner/blob/main/maps/apps.py"
    click StaticServer "https://github.com/wtrbtl03/url-shortner/blob/main/static/script.js"
    click StaticServer "https://github.com/wtrbtl03/url-shortner/blob/main/static/style.css"
    click Index "https://github.com/wtrbtl03/url-shortner/blob/main/templates/index.html"
    click TestT "https://github.com/wtrbtl03/url-shortner/blob/main/templates/test.html"
    click NotFound "https://github.com/wtrbtl03/url-shortner/blob/main/templates/404.html"
    click DB "https://github.com/wtrbtl03/url-shortner/blob/main/db.sqlite3"
    click README "https://github.com/wtrbtl03/url-shortner/blob/main/README.md"
    click License "https://github.com/wtrbtl03/url-shortner/tree/main/LICENSE"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef web fill:#90EE90,stroke:#000,stroke-width:1px
    classDef core fill:#FFFACD,stroke:#000,stroke-width:1px
    classDef app fill:#FFD700,stroke:#000,stroke-width:1px
    classDef entry fill:#E6E6FA,stroke:#000,stroke-width:1px
    classDef admin fill:#FFE4E1,stroke:#000,stroke-width:1px
    classDef db fill:#FFA500,stroke:#000,stroke-width:1px
    classDef static fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef template fill:#F0F8FF,stroke:#000,stroke-width:1px
    classDef doc fill:#F5F5F5,stroke:#000,stroke-width:1px
```
