Skip to content

this is hexagonal based url shortening application

Notifications You must be signed in to change notification settings

KhanSufiyanMirza/shorty

Repository files navigation

Explanation of Hexagonal Architecture:

Hexagonal architecture, also known as ports and adapters architecture, is a software design pattern that aims to separate the core business logic of an application from its external dependencies. This separation leads to several benefits, including:

  • Maintainability: Changes to external systems (databases, APIs, etc.) don't require changes to the core logic, making the application easier to maintain.
  • Testability: The core logic can be tested independently of external dependencies, making it easier to write reliable tests.
  • Adaptability: The application can be easily adapted to different technologies by changing the adapters without affecting the core logic.
  • Flexibility: Developers can focus on writing clean and testable business logic without worrying about the specifics of external systems.

Key Concepts of Hexagonal Architecture:

  1. Core Domain: This is the heart of the application, and it contains the business logic that is independent of any external dependencies.
  2. Ports: These are interfaces that define how the core domain interacts with the outside world.
  3. Adapters: These are implementations of the ports that connect the core domain to specific external systems.

Here's an analogy to understand it better:

Imagine a restaurant. The core domain is the kitchen, where chefs prepare food using recipes and ingredients. The ports are the menus and ordering systems (like online orders or phone calls) that tell the kitchen what to cook. The adapters are the waiters and delivery drivers who take orders from customers and deliver them to the kitchen.

Additional Resources:

Project Structure for Hexagonal Architecture in Go

This project demonstrates a hexagonal architecture approach for building a software system in Go. The goal is to create a maintainable, testable, and adaptable application with clear separation of concerns.

Folder Structure:

.
├── cmd
│   ├── cli
│   │   └── main.go
│   ├── grpc
│   │   └── main.go
│   └── http
│       ├── main.go
│       └── server
│           └── server.go
├── config
│   ├── appconfig.go
│   ├── cache.go
│   ├── config.go
│   ├── configproviders.go
│   ├── db.go
│   ├── event.go
│   └── kafka.go
├── constants
│   └── errs.go
├── db
│   ├── migration
│   │   ├── 000001_init_schema.down.sql
│   │   └── 000001_init_schema.up.sql
│   └── query
├── deployment
│   ├── certs
│   │   ├── jwt-certs
│   │   │   ├── app.rsa
│   │   │   └── app.rsa.pub
│   │   └── ssl-certs
│   │       ├── sslcert.crt
│   │       └── sslcert.key
│   ├── config
│   │   └── config.yaml
│   └── docker
│       └── docker-compose.yaml
├── Dockerfile
├── go.mod
├── go.sum
├── grpc_entrypoint.sh
├── internal
│   ├── adapters
│   │   ├── inbound
│   │   │   ├── fasthttpl
│   │   │   │   ├── handlers
│   │   │   │   └── routes
│   │   │   ├── gin
│   │   │   │   ├── handlers
│   │   │   │   ├── middlewares
│   │   │   │   └── routes
│   │   │   └── grpc
│   │   │       ├── pb
│   │   │       ├── proto
│   │   │       ├── rpc.go
│   │   │       ├── rpc_test.go.txt
│   │   │       └── server.go
│   │   └── outbound
│   │       └── db
│   │           ├── cachestore
│   │           ├── db.go
│   │           └── gormdbwrapper
│   ├── application
│   │   ├── api
│   │   │   ├── api.go
│   │   │   └── urlshortenerservice
│   │   │       └── urlshortener.go
│   │   ├── core
│   │   │   └── arithmetic
│   │   │       ├── arithmetic.go
│   │   │       └── arithmetic_test.go
│   │   └── rules
│   │       └── interface.go
│   └── ports
│       ├── inbound
│       │   └── services.go
│       └── outbound
│           ├── db.go
│           └── redis_db.go
├── loadtest.txt
├── models
│   ├── dto
│   │   ├── customshort.go
│   │   └── httpmsg.go
│   └── entity
│       └── customshort.go
├── README.md
├── scripts
│   ├── attack.sh
│   └── plot.sh
├── utils
│   ├── env
│   │   ├── env.go
│   │   └── env_test.go
│   ├── fasthttp
│   │   └── response.go
│   ├── helpers
│   │   └── helpers.go
│   ├── http
│   │   └── response.go
│   ├── logger
│   │   ├── logger.go
│   │   └── logger_test.go
│   ├── sanitize
│   │   └── sanitize.go
│   └── utils.go
└── vegeta
    ├── payload1.xml
    ├── payload.xml
    ├── plot.html
    ├── results.bin
    └── targets.http

Key Components:

  • cmd: Executables for CLI, gRPC, and HTTP interfaces.
  • config: Application configuration for various aspects.
  • constants: Error definitions.
  • db: Database-related code, including migrations and queries.
  • deployment: Deployment-specific files.
  • internal: Core project code:
    • adapters: Infrastructure-specific implementations for inbound/outbound ports.
    • application: Business logic components.
    • ports: Interfaces for