How elyseemb/urlshortener works
Project type and purpose
• This is a serverless URL-shortening microservice written in Go, packaged with AWS SAM and deployed as one or more AWS Lambda functions behind an API Gateway. Its sole responsibility is to generate (and potentially resolve) short links, persisting them in an external datastore and collecting basic stats.
File structure
• .aws-sam/ + template.yml: AWS SAM build artifacts and CloudFormation template for Lambda definitions, IAM roles, API Gateway.
• compose.yml: Docker Compose setup (likely local DynamoDB or local testing harness).
• main.go: Lambda entrypoint wired by SAM (invokes handlers).
• internal/
• adapters/functions/generate/: Lambda bootstrap for the “generate URL” function
• adapters/handlers/: HTTP‐level handlers parsing requests, calling core services
• adapters/repository/: persistence adapter (Link repository implementation, e.g. DynamoDB)
• config/: configuration loader (env variables, AWS region, table names)
• core/domain/: domain objects (Link, Stats)
• core/ports/: domain‐service interfaces (repository ports)
• core/services/: business logic implementing the ports (link creation, stats)
• makefile, go.mod, go.sum: build tooling and dependencies
README
• Confirms a Go-based URL shortener, deployable on AWS Lambda. No UI; purely an API.
a. Main components
1) Client (e.g. HTTP client or browser)
2) AWS API Gateway (REST API endpoint)
3) AWS Lambda “Generate” function (Go runtime)
4) Configuration module (env + SAM parameters)
5) Core service layer (domain + business logic)
6) Repository adapter (persistence)
7) DynamoDB table (or whichever datastore)
8) (Optional) Stats pipeline / CloudWatch metrics
9) Deployment artifacts (SAM/CloudFormation, S3 bucket)
b. Relationships & interactions
• Client → API Gateway (POST /generate)
• API Gateway → Lambda function
• Lambda handler loads config → invokes core service
• Core service calls repository adapter → DynamoDB
• DynamoDB returns item → core service returns short link
• Lambda returns JSON via API Gateway → Client
• (Stats domain objects feed CloudWatch or a secondary queue)
c. Architectural patterns
• Hexagonal (Ports & Adapters / Clean Architecture):
• Core domain & services (pure business logic)
• Ports define interfaces (e.g. LinksRepository)
• Adapters implement ports (DynamoDB, HTTP handlers, Lambda shim)
• Serverless microservice pattern: AWS SAM to define Lambda + API Gateway, minimal infra.
d. Key technologies
• Go modules, Go 1.x runtime
• AWS SAM / CloudFormation
• AWS Lambda, AWS API Gateway
• AWS DynamoDB (or chosen persistence)
• Docker Compose for local emulation (DynamoDB Local)
Elements
• Clear labels: “API Gateway”, “Lambda Function: generate”, “Core Service (domain + ports)”, “Repository Adapter”, “DynamoDB Table”
• Code modules inside Lambda in green (handlers, services, repositories)
• Infra as code (SAM template) in gray