# gopinathmaharaja/shorturl architecture

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

- Interactive diagram: https://gitdiagram.com/gopinathmaharaja/shorturl
- Repository: https://github.com/gopinathmaharaja/shorturl

## Overview

This is a Go Fiber URL-shortening API. Its principal workflow is user registration and login, followed by authenticated short-link creation and public redirection; the API also exposes click analytics. The graph captures route registrations and calls visible in excerpts, plus the documented MongoDB persistence capability. Several service, repository, startup, and optional cache details are indexed but unsampled, so their internal connections are omitted or marked unverified rather than inferred.

Main entry points: [`routes/router.go`](https://github.com/gopinathmaharaja/shorturl/blob/main/routes/router.go) (Route setup), [`internal/shortUrl/handler.go`](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/shortUrl/handler.go) (Short-link handlers), [`internal/user/repository.go`](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/user/repository.go) (User repository), [`internal/shortUrl/repository.go`](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/shortUrl/repository.go) (Short-link repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_router["Route setup<br/>[router.go]"]
  node_health["Health endpoints<br/>[health_handler.go]"]
  node_ratelimit["Rate limiting<br/>[ratelimit.go]"]
  node_main["Application startup<br/>[main.go]"]
end

subgraph group_identity["Identity"]
  node_user_handler["User handlers<br/>[handler.go]"]
  node_auth_middleware["JWT and API-key auth<br/>[jwt.go]"]
  node_user_service["User service<br/>[service.go]"]
  node_user_model["User model<br/>[model.go]"]
  node_user_repository["User repository<br/>[repository.go]"]
end

subgraph group_links["Short Links"]
  node_short_handler["Short-link handlers<br/>[handler.go]"]
  node_short_service["Short-link service<br/>[service.go]"]
  node_short_repository["Short-link repository<br/>[repository.go]"]
  node_short_model["Link and analytics models<br/>[model.go]"]
  node_cron["Scheduled cleanup<br/>[cron.go]"]
end

subgraph group_infrastructure["Persistence and Support"]
  node_mongo[("MongoDB<br/>[mongo.go]")]
  node_redis_cache["Redis cache<br/>[redis.go]"]
  node_logger["Logger<br/>[logger.go]"]
end

node_client(("API client"))

node_client -.->|"sends requests"| node_router
node_router -->|"registers health"| node_health
node_router -->|"registers auth routes"| node_user_handler
node_router -->|"registers link routes"| node_short_handler
node_router -->|"protects URL routes"| node_auth_middleware
node_router -->|"applies limits"| node_ratelimit
node_user_handler -.->|"calls"| node_user_service
node_auth_middleware -->|"looks up users"| node_user_repository
node_short_handler -->|"creates and resolves links"| node_short_service
node_short_handler -->|"requests click analytics"| node_short_repository
node_user_service -.->|"persists users"| node_user_repository
node_short_service -.->|"persists links"| node_short_repository
node_user_repository -.->|"stores user records"| node_mongo
node_short_repository -.->|"stores links and analytics"| node_mongo
node_main -.->|"starts API"| node_router
node_main -.->|"initializes database"| node_mongo

click node_router "https://github.com/gopinathmaharaja/shorturl/blob/main/routes/router.go"
click node_health "https://github.com/gopinathmaharaja/shorturl/blob/main/internal/handlers/health_handler.go"
click node_ratelimit "https://github.com/gopinathmaharaja/shorturl/blob/main/internal/middleware/ratelimit.go"
click node_user_handler "https://github.com/gopinathmaharaja/shorturl/blob/main/internal/user/handler.go"
click node_auth_middleware "https://github.com/gopinathmaharaja/shorturl/blob/main/internal/middleware/jwt.go"
click node_user_service "https://github.com/gopinathmaharaja/shorturl/blob/main/internal/user/service.go"
click node_user_model "https://github.com/gopinathmaharaja/shorturl/blob/main/internal/user/model.go"
click node_user_repository "https://github.com/gopinathmaharaja/shorturl/blob/main/internal/user/repository.go"
click node_short_handler "https://github.com/gopinathmaharaja/shorturl/blob/main/internal/shortUrl/handler.go"
click node_short_service "https://github.com/gopinathmaharaja/shorturl/blob/main/internal/shortUrl/service.go"
click node_short_repository "https://github.com/gopinathmaharaja/shorturl/blob/main/internal/shortUrl/repository.go"
click node_short_model "https://github.com/gopinathmaharaja/shorturl/blob/main/internal/shortUrl/model.go"
click node_cron "https://github.com/gopinathmaharaja/shorturl/blob/main/internal/utils/cron.go"
click node_mongo "https://github.com/gopinathmaharaja/shorturl/blob/main/pkg/db/mongo.go"
click node_redis_cache "https://github.com/gopinathmaharaja/shorturl/blob/main/pkg/cache/redis.go"
click node_logger "https://github.com/gopinathmaharaja/shorturl/blob/main/pkg/logger/logger.go"
click node_main "https://github.com/gopinathmaharaja/shorturl/blob/main/cmd/main.go"

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_router,node_health,node_ratelimit,node_main,node_client toneBlue
class node_user_handler,node_auth_middleware,node_user_service,node_user_model,node_user_repository toneAmber
class node_short_handler,node_short_service,node_short_repository,node_short_model,node_cron toneMint
class node_mongo,node_redis_cache,node_logger toneRose
```

## Components

### HTTP API

- [Route setup](https://github.com/gopinathmaharaja/shorturl/blob/main/routes/router.go): `routes/router.go`
- [Health endpoints](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/handlers/health_handler.go): `internal/handlers/health_handler.go`
- [Rate limiting](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/middleware/ratelimit.go): `internal/middleware/ratelimit.go`
- [Application startup](https://github.com/gopinathmaharaja/shorturl/blob/main/cmd/main.go): `cmd/main.go`

### Identity

- [User handlers](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/user/handler.go): `internal/user/handler.go`
- [JWT and API-key auth](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/middleware/jwt.go): `internal/middleware/jwt.go`
- [User service](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/user/service.go): `internal/user/service.go`
- [User model](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/user/model.go): `internal/user/model.go`
- [User repository](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/user/repository.go): `internal/user/repository.go`

### Short Links

- [Short-link handlers](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/shortUrl/handler.go): `internal/shortUrl/handler.go`
- [Short-link service](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/shortUrl/service.go): `internal/shortUrl/service.go`
- [Short-link repository](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/shortUrl/repository.go): `internal/shortUrl/repository.go`
- [Link and analytics models](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/shortUrl/model.go): `internal/shortUrl/model.go`
- [Scheduled cleanup](https://github.com/gopinathmaharaja/shorturl/blob/main/internal/utils/cron.go): `internal/utils/cron.go`

### Persistence and Support

- [MongoDB](https://github.com/gopinathmaharaja/shorturl/blob/main/pkg/db/mongo.go): `pkg/db/mongo.go`
- [Redis cache](https://github.com/gopinathmaharaja/shorturl/blob/main/pkg/cache/redis.go): `pkg/cache/redis.go`
- [Logger](https://github.com/gopinathmaharaja/shorturl/blob/main/pkg/logger/logger.go): `pkg/logger/logger.go`

### Other components

- **API client**

## Connections

- API client → Route setup: sends requests (evidence: `README.md`)
- Route setup → Health endpoints: registers health (evidence: `routes/router.go`)
- Route setup → User handlers: registers auth routes (evidence: `routes/router.go`)
- Route setup → Short-link handlers: registers link routes (evidence: `routes/router.go`)
- Route setup → JWT and API-key auth: protects URL routes (evidence: `routes/router.go`)
- Route setup → Rate limiting: applies limits (evidence: `routes/router.go`)
- User handlers → User service: calls
- JWT and API-key auth → User repository: looks up users (evidence: `internal/middleware/jwt.go`)
- Short-link handlers → Short-link service: creates and resolves links (evidence: `internal/shortUrl/handler.go`)
- Short-link handlers → Short-link repository: requests click analytics (evidence: `internal/shortUrl/handler.go`)
- User service → User repository: persists users
- Short-link service → Short-link repository: persists links
- User repository → MongoDB: stores user records
- Short-link repository → MongoDB: stores links and analytics
- Application startup → Route setup: starts API
- Application startup → MongoDB: initializes database
