# iamn1/link-shortener architecture

> Architecture diagram of the GitHub repository iamn1/link-shortener, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/iamn1/link-shortener
- Repository: https://github.com/iamn1/link-shortener

## Overview

MaizLink is a web URL-shortening service with guest and registered-user links, RBAC, authentication, analytics, administration, and operational integrations. The main workflow accepts a shorten request, creates a link through the application layer, persists it, and later redirects visitors; the README also documents batch creation, QR codes, asynchronous click counting, and email confirmation. The graph combines these documented capabilities with the sampled controller, context, and infrastructure evidence; several internal calls are left unverified where their implementation was not shown.

Main entry points: [`src/link_shortener/web/controllers/api_controller.py`](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/web/controllers/api_controller.py) (API controllers), [`src/link_shortener/infrastructure/database/manager.py`](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/database/manager.py) (SQL database), [`src/link_shortener/application/use_cases/links/create_short_link.py`](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/use_cases/links/create_short_link.py) (Create short link), [`src/link_shortener/application/use_cases/links/redirect_link.py`](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/use_cases/links/redirect_link.py) (Redirect workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_controllers["API controllers<br/>[api_controller.py]"]
  node_auth_controller["Auth controller<br/>[auth_controller.py]"]
  node_web_security["Request security<br/>[context.py]"]
end

subgraph group_application["Application workflows"]
  node_request_context["Request context<br/>[context.py]"]
  node_link_facade["Link workflows<br/>[link_service.py]"]
  node_create_link["Create short link"]
  node_batch["Batch creation"]
  node_redirect["Redirect workflow<br/>[redirect_link.py]"]
  node_auth_facade["Account workflows<br/>[auth_service.py]"]
  node_auth_dto["Auth DTOs<br/>[auth.py]"]
  node_base_use_case["Use-case base<br/>[base_use_case.py]"]
  node_auth_port["Authentication port<br/>[auth_service.py]"]
  node_stats["Statistics workflows<br/>[get_visit_stats.py]"]
  node_admin["Admin workflows<br/>[admin_service.py]"]
end

subgraph group_domain["Domain model"]
  node_link_entity["Link model<br/>[link.py]"]
  node_refresh_entity["Refresh session<br/>[refresh_session.py]"]
  node_domain_errors["Domain errors<br/>[exceptions.py]"]
  node_domain_i18n["Translatable messages<br/>[i18n.py]"]
end

subgraph group_infrastructure["Infrastructure"]
  node_auth_impl["JWT authentication"]
  node_database[("SQL database<br/>[manager.py]")]
  node_db_repositories["SQL repositories"]
  node_container["Dependency container<br/>[container.py]"]
  node_cache["Cache adapters<br/>[redis_cache.py]"]
  node_task_queue["Task queue<br/>[celery_queue.py]"]
  node_worker["Click and mail tasks<br/>[tasks.py]"]
  node_cli["Operations CLI<br/>[flask.py]"]
end

node_visitor(("Visitor"))
node_smtp[("SMTP mail")]

node_visitor -->|"shortens or redirects"| node_controllers
node_controllers -->|"requests link action"| node_link_facade
node_link_facade -.->|"delegates creation"| node_create_link
node_create_link -->|"persists link"| node_database
node_controllers -->|"accepts batch requests"| node_batch
node_controllers -->|"routes code lookup"| node_redirect
node_redirect -->|"uses redirect cache"| node_cache
node_redirect -->|"resolves link"| node_database
node_create_link -.->|"creates domain link"| node_link_entity
node_controllers -->|"builds request context"| node_request_context
node_request_context -->|"supplies request metadata"| node_create_link
node_auth_controller -->|"calls account workflows"| node_auth_facade
node_auth_facade -.->|"uses authentication service"| node_auth_port
node_auth_port -->|"implemented by"| node_auth_impl
node_auth_controller -->|"formats responses"| node_auth_dto
node_web_security -.->|"validates session"| node_auth_impl
node_database -->|"provides sessions"| node_db_repositories
node_container -->|"configures database"| node_database
node_controllers -->|"uses two-level caching"| node_cache
node_controllers -->|"queues click work"| node_task_queue
node_task_queue -->|"dispatches tasks"| node_worker
node_worker -->|"records clicks"| node_database
node_worker -->|"sends confirmation mail"| node_smtp
node_controllers -->|"serves analytics"| node_stats
node_controllers -->|"serves administration"| node_admin
node_cli -->|"gets application services"| node_container
node_base_use_case -.->|"shares request metadata"| node_request_context
node_domain_errors -->|"marks translatable text"| node_domain_i18n
node_db_repositories -->|"maps session entity"| node_refresh_entity

click node_controllers "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/web/controllers/api_controller.py"
click node_auth_controller "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/web/controllers/auth_controller.py"
click node_request_context "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/context.py"
click node_link_facade "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/facades/link_service.py"
click node_create_link "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/use_cases/links/create_short_link.py"
click node_batch "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/use_cases/batch/batch_create_links.py"
click node_redirect "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/use_cases/links/redirect_link.py"
click node_auth_facade "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/facades/auth_service.py"
click node_auth_dto "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/dtos/auth.py"
click node_base_use_case "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/use_cases/base_use_case.py"
click node_link_entity "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/domain/entities/link.py"
click node_refresh_entity "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/domain/entities/refresh_session.py"
click node_domain_errors "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/domain/exceptions.py"
click node_domain_i18n "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/domain/i18n.py"
click node_auth_port "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/ports/auth/auth_service.py"
click node_auth_impl "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/auth/jwt_auth_service.py"
click node_web_security "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/web/security/context.py"
click node_database "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/database/manager.py"
click node_db_repositories "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/database/repositories/sqlalchemy_refresh_session_repository.py"
click node_container "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/di/container.py"
click node_cache "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/cache/redis_cache.py"
click node_task_queue "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/task_queue/celery_queue.py"
click node_worker "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/task_queue/tasks.py"
click node_stats "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/use_cases/stats/get_visit_stats.py"
click node_admin "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/facades/admin_service.py"
click node_cli "https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/cli/adapters/flask.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_controllers,node_auth_controller,node_web_security toneBlue
class node_request_context,node_link_facade,node_create_link,node_batch,node_redirect,node_auth_facade,node_auth_dto,node_base_use_case,node_auth_port,node_stats,node_admin,node_smtp toneAmber
class node_link_entity,node_refresh_entity,node_domain_errors,node_domain_i18n toneMint
class node_auth_impl,node_database,node_db_repositories,node_container,node_cache,node_task_queue,node_worker,node_cli toneRose
class node_visitor toneIndigo
```

## Components

### Web interface

- [API controllers](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/web/controllers/api_controller.py): `src/link_shortener/web/controllers/api_controller.py`
- [Auth controller](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/web/controllers/auth_controller.py): `src/link_shortener/web/controllers/auth_controller.py`
- [Request security](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/web/security/context.py): `src/link_shortener/web/security/context.py`

### Application workflows

- [Request context](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/context.py): `src/link_shortener/application/context.py`
- [Link workflows](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/facades/link_service.py): `src/link_shortener/application/facades/link_service.py`
- [Create short link](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/use_cases/links/create_short_link.py): `src/link_shortener/application/use_cases/links/create_short_link.py`
- [Batch creation](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/use_cases/batch/batch_create_links.py): `src/link_shortener/application/use_cases/batch/batch_create_links.py`
- [Redirect workflow](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/use_cases/links/redirect_link.py): `src/link_shortener/application/use_cases/links/redirect_link.py`
- [Account workflows](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/facades/auth_service.py): `src/link_shortener/application/facades/auth_service.py`
- [Auth DTOs](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/dtos/auth.py): `src/link_shortener/application/dtos/auth.py`
- [Use-case base](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/use_cases/base_use_case.py): `src/link_shortener/application/use_cases/base_use_case.py`
- [Authentication port](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/ports/auth/auth_service.py): `src/link_shortener/application/ports/auth/auth_service.py`
- [Statistics workflows](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/use_cases/stats/get_visit_stats.py): `src/link_shortener/application/use_cases/stats/get_visit_stats.py`
- [Admin workflows](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/application/facades/admin_service.py): `src/link_shortener/application/facades/admin_service.py`

### Domain model

- [Link model](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/domain/entities/link.py): `src/link_shortener/domain/entities/link.py`
- [Refresh session](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/domain/entities/refresh_session.py): `src/link_shortener/domain/entities/refresh_session.py`
- [Domain errors](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/domain/exceptions.py): `src/link_shortener/domain/exceptions.py`
- [Translatable messages](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/domain/i18n.py): `src/link_shortener/domain/i18n.py`

### Infrastructure

- [JWT authentication](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/auth/jwt_auth_service.py): `src/link_shortener/infrastructure/auth/jwt_auth_service.py`
- [SQL database](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/database/manager.py): `src/link_shortener/infrastructure/database/manager.py`
- [SQL repositories](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/database/repositories/sqlalchemy_refresh_session_repository.py): `src/link_shortener/infrastructure/database/repositories/sqlalchemy_refresh_session_repository.py`
- [Dependency container](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/di/container.py): `src/link_shortener/infrastructure/di/container.py`
- [Cache adapters](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/cache/redis_cache.py): `src/link_shortener/infrastructure/cache/redis_cache.py`
- [Task queue](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/task_queue/celery_queue.py): `src/link_shortener/infrastructure/task_queue/celery_queue.py`
- [Click and mail tasks](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/task_queue/tasks.py): `src/link_shortener/infrastructure/task_queue/tasks.py`
- [Operations CLI](https://github.com/iamn1/link-shortener/blob/master/src/link_shortener/infrastructure/cli/adapters/flask.py): `src/link_shortener/infrastructure/cli/adapters/flask.py`

### Other components

- **Visitor**
- **SMTP mail**

## Connections

- Visitor → API controllers: shortens or redirects (evidence: `README.md`)
- API controllers → Link workflows: requests link action (evidence: `src/link_shortener/web/controllers/api_controller.py`)
- Link workflows → Create short link: delegates creation
- Create short link → SQL database: persists link (evidence: `README.md`)
- API controllers → Batch creation: accepts batch requests (evidence: `README.md`)
- API controllers → Redirect workflow: routes code lookup (evidence: `README.md`)
- Redirect workflow → Cache adapters: uses redirect cache (evidence: `README.md`)
- Redirect workflow → SQL database: resolves link (evidence: `README.md`)
- Create short link → Link model: creates domain link
- API controllers → Request context: builds request context (evidence: `src/link_shortener/web/controllers/api_controller.py`)
- Request context → Create short link: supplies request metadata (evidence: `src/link_shortener/application/context.py`)
- Auth controller → Account workflows: calls account workflows (evidence: `src/link_shortener/web/controllers/auth_controller.py`)
- Account workflows → Authentication port: uses authentication service
- Authentication port → JWT authentication: implemented by (evidence: `src/link_shortener/infrastructure/auth/jwt_auth_service.py`)
- Auth controller → Auth DTOs: formats responses (evidence: `src/link_shortener/web/controllers/auth_controller.py`)
- Request security → JWT authentication: validates session
- SQL database → SQL repositories: provides sessions (evidence: `src/link_shortener/infrastructure/database/manager.py`)
- Dependency container → SQL database: configures database
- API controllers → Cache adapters: uses two-level caching (evidence: `README.md`)
- API controllers → Task queue: queues click work (evidence: `README.md`)
- Task queue → Click and mail tasks: dispatches tasks (evidence: `README.md`)
- Click and mail tasks → SQL database: records clicks (evidence: `README.md`)
- Click and mail tasks → SMTP mail: sends confirmation mail (evidence: `README.md`)
- API controllers → Statistics workflows: serves analytics (evidence: `README.md`)
- API controllers → Admin workflows: serves administration (evidence: `README.md`)
- Operations CLI → Dependency container: gets application services (evidence: `src/link_shortener/infrastructure/cli/adapters/flask.py`)
- Use-case base → Request context: shares request metadata (evidence: `src/link_shortener/application/use_cases/base_use_case.py`)
- Domain errors → Translatable messages: marks translatable text (evidence: `src/link_shortener/domain/i18n.py`)
- SQL repositories → Refresh session: maps session entity (evidence: `src/link_shortener/infrastructure/database/repositories/sqlalchemy_refresh_session_repository.py`)
