# orarange/tinyurl architecture

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

- Interactive diagram: https://gitdiagram.com/orarange/tinyurl
- Repository: https://github.com/orarange/tinyurl

## Overview

##### Project type and purpose
- This is a full-stack Node.js/Express web application that provides a URL-shortening service (“tinyurl”).
- Users can register/login (OAuth support), create short links, retrieve original URLs, and manage premium features.

##### File structure
- Top-level files:
– index.js: application entry point
– package.json / package-lock.json: dependencies and scripts
- Directories:
– routes/: Express route handlers (HTTP endpoints for pages and APIs)
– functions/: business-logic modules invoked by routes (e.g., make short URL, OAuth, refresh tokens, user data)
– APIs/: modules that wrap external API calls or internal JSON APIs (e.g., gettiny, geturl)
– models/: data schemas/mappers (e.g., users, tinyurl, admin, premium, preuser)
– views/: EJS templates for server-side rendering (UI pages)
– public/: static assets (CSS, images, robots.txt, sitemap.xml)

##### README for additional insights
- The README is minimal, stating only the project name.
– Express.js framework
– EJS for templating
– A NoSQL or ORM-backed database (models folder)
– OAuth integration for login

##### Main components and their interactions
a. Client (Browser)
– Requests pages (login, dashboard, policy, admin, etc.)
– Submits forms (register, tiny URL creation)
b. Web Server (Node.js + Express)
– Routes layer: maps URLs to controller functions
– Controller/Functions layer: core logic lives in functions/*.js
– API wrappers: calls to external/internal services in APIs/*.js
– Model/Data Access layer: CRUD operations on URL mappings and user records
c. Database
– Stores user profiles, tiny URL mappings, admin settings, premium statuses
d. External Services
– OAuth Identity Providers (Google, etc.)
– Possibly analytics or link-preview services

##### Architectural patterns / design principles
- MVC-style separation:
– Views (EJS templates)
– Controllers (routes + functions)
– Models (data schemas)
- Service abstraction:
– functions/ holds business logic separate from route declarations
– APIs/ isolates third-party or micro-API calls
- Single monolithic deployment, but clearly modularized into layers

##### Detail
- How a user action (e.g., “Create Short URL”) flows from the browser through routes → functions → models → DB → back.
- Error-handling or refresh token flows if desired (e.g., oauth.js and refresh.js).

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser(("Browser")):::external
    Entry["index.js"]:::entry
    subgraph "Express Server"
        subgraph "Routes Layer"
            R_index["routes/index.js"]:::route
            R_login["routes/login.js"]:::route
            R_register["routes/register.js"]:::route
            R_logout["routes/logout.js"]:::route
            R_dash["routes/dash.js"]:::route
            R_tiny["routes/tiny.js"]:::route
            R_admin["routes/admin.js"]:::route
            R_buypremium["routes/buypremium.js"]:::route
            R_policy["routes/policy.js"]:::route
            R_gollogin["routes/gollogin.js"]:::route
            R_refe["routes/refe.js"]:::route
            R_bata["routes/bata.js"]:::route
        end
        subgraph "Functions/Services Layer"
            F_make["functions/make.js"]:::service
            F_dataremove["functions/dataremove.js"]:::service
            F_register["functions/register.js"]:::service
            F_userdata["functions/userdata.js"]:::service
            F_oauth["functions/oauth.js"]:::service
            F_refresh["functions/refresh.js"]:::service
        end
        subgraph "API Clients Layer"
            A_gettiny["APIs/gettiny.js"]:::api
            A_geturl["APIs/geturl.js"]:::api
            A_pull["APIs/pull.js"]:::api
            A_index["APIs/index.js"]:::api
        end
        subgraph "Models/Data-Access Layer"
            M_users["models/users.js"]:::model
            M_preuser["models/preuser.js"]:::model
            M_tinyurl["models/tinyurl.js"]:::model
            M_admin["models/admin.js"]:::model
            M_premium["models/premium.js"]:::model
        end
        subgraph "Views Layer"
            V_index["views/index.ejs"]:::view
            V_login["views/login.ejs"]:::view
            V_register["views/register.ejs"]:::view
            V_dash["views/dash.ejs"]:::view
            V_admin["views/admin.ejs"]:::view
            V_buypremium["views/buypremium.ejs"]:::view
            V_policy["views/policy.ejs"]:::view
            V_404["views/404.ejs"]:::view
            V_api["views/api.ejs"]:::view
            V_oldindex["views/oldindex.ejs"]:::view
        end
        subgraph "Public (Static Assets)"
            P_css1["public/css/style.css"]:::static
            P_css2["public/css/login.css"]:::static
            P_css3["public/css/policy.css"]:::static
            P_css4["public/css/responsive.css"]:::static
            P_images["public/images/"]:::static
            P_robots["public/robots.txt"]:::static
            P_sitemap["public/sitemap.xml"]:::static
        end
    end
    Database[(Database)]:::db
    OAuth((OAuth Provider)):::external

    Browser -->|"HTTP/HTTPS"| Entry
    Entry -->|"handles routes"| R_index
    R_index -->|"invokes"| F_make
    F_make -->|"uses schema"| M_tinyurl
    M_tinyurl -->|"reads/writes"| Database
    F_oauth -->|"auth flow"| OAuth
    R_login -->|"renders"| V_login
    R_register -->|"renders"| V_register
    R_dash -->|"renders"| V_dash
    R_admin -->|"renders"| V_admin
    R_buypremium -->|"renders"| V_buypremium
    R_policy -->|"renders"| V_policy
    R_index -->|"renders"| V_index
    Browser -->|"requests static assets"| P_css1
    Browser --> P_images

    click Entry "https://github.com/orarange/tinyurl/blob/master/index.js"
    click R_index "https://github.com/orarange/tinyurl/blob/master/routes/index.js"
    click R_login "https://github.com/orarange/tinyurl/blob/master/routes/login.js"
    click R_register "https://github.com/orarange/tinyurl/blob/master/routes/register.js"
    click R_logout "https://github.com/orarange/tinyurl/blob/master/routes/logout.js"
    click R_dash "https://github.com/orarange/tinyurl/blob/master/routes/dash.js"
    click R_tiny "https://github.com/orarange/tinyurl/blob/master/routes/tiny.js"
    click R_admin "https://github.com/orarange/tinyurl/blob/master/routes/admin.js"
    click R_buypremium "https://github.com/orarange/tinyurl/blob/master/routes/buypremium.js"
    click R_policy "https://github.com/orarange/tinyurl/blob/master/routes/policy.js"
    click R_gollogin "https://github.com/orarange/tinyurl/blob/master/routes/gollogin.js"
    click R_refe "https://github.com/orarange/tinyurl/blob/master/routes/refe.js"
    click R_bata "https://github.com/orarange/tinyurl/blob/master/routes/bata.js"
    click F_make "https://github.com/orarange/tinyurl/blob/master/functions/make.js"
    click F_dataremove "https://github.com/orarange/tinyurl/blob/master/functions/dataremove.js"
    click F_register "https://github.com/orarange/tinyurl/blob/master/functions/register.js"
    click F_userdata "https://github.com/orarange/tinyurl/blob/master/functions/userdata.js"
    click F_oauth "https://github.com/orarange/tinyurl/blob/master/functions/oauth.js"
    click F_refresh "https://github.com/orarange/tinyurl/blob/master/functions/refresh.js"
    click A_gettiny "https://github.com/orarange/tinyurl/blob/master/APIs/gettiny.js"
    click A_geturl "https://github.com/orarange/tinyurl/blob/master/APIs/geturl.js"
    click A_pull "https://github.com/orarange/tinyurl/blob/master/APIs/pull.js"
    click A_index "https://github.com/orarange/tinyurl/blob/master/APIs/index.js"
    click M_users "https://github.com/orarange/tinyurl/blob/master/models/users.js"
    click M_preuser "https://github.com/orarange/tinyurl/blob/master/models/preuser.js"
    click M_tinyurl "https://github.com/orarange/tinyurl/blob/master/models/tinyurl.js"
    click M_admin "https://github.com/orarange/tinyurl/blob/master/models/admin.js"
    click M_premium "https://github.com/orarange/tinyurl/blob/master/models/premium.js"
    click V_index "https://github.com/orarange/tinyurl/blob/master/views/index.ejs"
    click V_login "https://github.com/orarange/tinyurl/blob/master/views/login.ejs"
    click V_register "https://github.com/orarange/tinyurl/blob/master/views/register.ejs"
    click V_dash "https://github.com/orarange/tinyurl/blob/master/views/dash.ejs"
    click V_admin "https://github.com/orarange/tinyurl/blob/master/views/admin.ejs"
    click V_buypremium "https://github.com/orarange/tinyurl/blob/master/views/buypremium.ejs"
    click V_policy "https://github.com/orarange/tinyurl/blob/master/views/policy.ejs"
    click V_404 "https://github.com/orarange/tinyurl/blob/master/views/404.ejs"
    click V_api "https://github.com/orarange/tinyurl/blob/master/views/api.ejs"
    click V_oldindex "https://github.com/orarange/tinyurl/blob/master/views/oldindex.ejs"
    click P_css1 "https://github.com/orarange/tinyurl/blob/master/public/css/style.css"
    click P_css2 "https://github.com/orarange/tinyurl/blob/master/public/css/login.css"
    click P_css3 "https://github.com/orarange/tinyurl/blob/master/public/css/policy.css"
    click P_css4 "https://github.com/orarange/tinyurl/blob/master/public/css/responsive.css"
    click P_images "https://github.com/orarange/tinyurl/tree/master/public/images/"
    click P_robots "https://github.com/orarange/tinyurl/blob/master/public/robots.txt"
    click P_sitemap "https://github.com/orarange/tinyurl/blob/master/public/sitemap.xml"

    classDef entry fill:#f9f,stroke:#333,stroke-width:1px
    classDef route fill:#bbf,stroke:#333,stroke-width:1px
    classDef service fill:#bfb,stroke:#333,stroke-width:1px
    classDef api fill:#ddd,stroke:#333,stroke-width:1px
    classDef model fill:#fbf,stroke:#333,stroke-width:1px
    classDef view fill:#fbc,stroke:#333,stroke-width:1px
    classDef static fill:#cff,stroke:#333,stroke-width:1px
    classDef db fill:#fea,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#eee,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2
```
