{"id":15178828,"url":"https://github.com/carlosasrc/url-shortener","last_synced_at":"2026-03-02T06:02:27.389Z","repository":{"id":251301743,"uuid":"836931356","full_name":"CarlosAsrc/url-shortener","owner":"CarlosAsrc","description":"A simple URL shortener app in Go. IaC with terraform config and CI/CD with github actions provided.","archived":false,"fork":false,"pushed_at":"2024-09-03T21:20:37.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T19:24:10.399Z","etag":null,"topics":["aws","docker","docker-compose","dynamodb","ecs","github-actions","golang","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CarlosAsrc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-01T21:27:47.000Z","updated_at":"2024-09-10T17:52:01.000Z","dependencies_parsed_at":"2024-09-23T10:31:01.025Z","dependency_job_id":null,"html_url":"https://github.com/CarlosAsrc/url-shortener","commit_stats":{"total_commits":41,"total_committers":1,"mean_commits":41.0,"dds":0.0,"last_synced_commit":"d13539de8e68a9759ab5d3f387293c3801d44905"},"previous_names":["carlosasrc/url-shortener"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CarlosAsrc/url-shortener","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CarlosAsrc%2Furl-shortener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CarlosAsrc%2Furl-shortener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CarlosAsrc%2Furl-shortener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CarlosAsrc%2Furl-shortener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CarlosAsrc","download_url":"https://codeload.github.com/CarlosAsrc/url-shortener/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CarlosAsrc%2Furl-shortener/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29993541,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T01:47:34.672Z","status":"online","status_checked_at":"2026-03-02T02:00:07.342Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","docker","docker-compose","dynamodb","ecs","github-actions","golang","terraform"],"created_at":"2024-09-27T15:23:24.950Z","updated_at":"2026-03-02T06:02:27.370Z","avatar_url":"https://github.com/CarlosAsrc.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# URL Shortener\n\nThis project implements a URL shortening service using Go, DynamoDB, ECS, and Terraform.\n\n![image](https://github.com/user-attachments/assets/7f3059a3-97e9-4aa3-8787-3fe9d5c1bc4c)\n\n## Table of Contents\n\n- [Architecture](#architecture)\n- [Terraform Project](#terraform-project)\n  - [Modules](#modules)\n    - [vpc](#module-vpc)\n    - [iam](#module-iam)\n    - [dynamodb](#module-dynamodb)\n    - [ecs](#module-ecs)\n    - [ec2](#module-ec2)\n- [Go Server Routes](#go-server-routes)\n  - [POST /shorten](#post-apishorten)\n  - [GET /long-url/{shortURL}](#get-short_code)\n- [URL Shortening Algorithm](#url-shortening-algorithm)\n\n## Architecture\n\nThe application is deployed on AWS and utilizes the following services:\n\n- **ECS (Elastic Container Service):** Runs the Go server as a containerized application.\n- **EC2 (Elastic Compute Cloud):** Provides the underlying virtual machines for the ECS cluster.\n- **DynamoDB:** Stores the mapping between short codes and original URLs.\n- **ALB (Application Load Balancer):** Distributes incoming traffic to the ECS service.\n\n## Terraform Project\n\nThe Terraform project is responsible for provisioning and managing the infrastructure for the URL shortening service.\n\n### Modules\n\nThe project is organized into several modules:\n\n#### Module: vpc\n\nThis module defines the VPC (Virtual Private Cloud) network infrastructure, including:\n\n- VPC with a specified CIDR block.\n- Public subnets for internet-facing resources.\n- Security groups for controlling network traffic.\n\n#### Module: iam\n\nThis module manages the IAM (Identity and Access Management) roles and policies required for the application, including:\n\n- ECS task execution role for allowing ECS tasks to access other AWS resources.\n- ECS instance role for granting permissions to EC2 instances running ECS tasks.\n\n#### Module: dynamodb\n\nThis module provisions the DynamoDB table used to store the URL mappings.\n\n#### Module: ecs\n\nThis module defines the ECS cluster, task definition, and service for running the Go server. It configures:\n\n- ECS cluster for grouping and managing ECS tasks.\n- ECS task definition specifying the container image, environment variables, and resource limits for the Go server.\n- ECS service for ensuring the desired number of tasks are running and registered with the load balancer.\n\n#### Module: ec2\n\nThis module provisions the EC2 instances that will run the ECS tasks. It configures:\n\n- Auto Scaling group for dynamically adjusting the number of EC2 instances based on demand.\n- EC2 instances with the required instance type, security groups, and IAM role.\n\n## Go Server Routes\n\nThe Go server exposes the following API routes:\n\n### POST /shorten\n\nThis route accepts a JSON payload with the original URL and returns a short code.\n\n**Request Body:**\n\n```json\n{\n  \"long_url\": \"https://www.example.com/long-url\"\n}\n```\n\nResponse Body:\n\n```json\n{\n  \"short_url\": \"short\"\n}\n```\n\n### GET /long-url/{shortURL}\nThis route redirects the user to the original URL associated with the provided short code.\n\n### URL Shortening Algorithm\n\nThe ShortenURL function generates a short code for a given URL using a CRC32 checksum and hexadecimal conversion. Here's a breakdown:\n\n- Hashing:\n  - It utilizes the crc32.NewIEEE() function to create a new CRC32 checksum using the IEEE polynomial. CRC32 is a non-cryptographic hash function known for its speed and relatively low collision rates.\nThe code calculates the checksum of the input longUrl by feeding its byte representation into the hasher using hasher.Write([]byte(longUrl)).\n\n- Hexadecimal Conversion:\n  - hasher.Sum32() computes the final 32-bit checksum of the input URL.\nfmt.Sprintf(\"%x\", ...) formats the obtained 32-bit checksum into a hexadecimal string representation.\nIn essence: The function takes a long URL, computes its CRC32 checksum, and returns the hexadecimal representation of that checksum as the short code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarlosasrc%2Furl-shortener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarlosasrc%2Furl-shortener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarlosasrc%2Furl-shortener/lists"}