All Projects → iDevoid → Stygis

iDevoid / Stygis

golang hexagonal architecture - focus on simplifed code, orgenized structure and better naming for functions and packages name

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Stygis

Wilson
ERP / CRM system for small to medium construction companies.
Stars: ✭ 84 (+95.35%)
Mutual labels:  ddd-architecture
Go Realworld Clean
a clean architecture implementation of the realworldapp : https://github.com/gothinkster/realworld
Stars: ✭ 301 (+600%)
Mutual labels:  ddd-architecture
Modular Monolith With Ddd
Full Modular Monolith application with Domain-Driven Design approach.
Stars: ✭ 6,210 (+14341.86%)
Mutual labels:  ddd-architecture
CQELight
CQELight is an entreprise grade extensible and customisable framework for creating software with CQRS, DDD & Event Sourcing patterns
Stars: ✭ 21 (-51.16%)
Mutual labels:  ddd-architecture
csharp-ddd-skeleton
🦈✨ C# DDD Skeleton: Bootstrap your new C# projects applying Hexagonal Architecture and Domain-Driven Design patterns
Stars: ✭ 67 (+55.81%)
Mutual labels:  ddd-architecture
Qbike
A demo of share bike using DDD, MicroService and Spring Cloud
Stars: ✭ 429 (+897.67%)
Mutual labels:  ddd-architecture
laravel-mvc-to-ddd
Automatically change the default Laravel MVC architecture to a DDD architecture approach
Stars: ✭ 13 (-69.77%)
Mutual labels:  ddd-architecture
Jdonframework
Domain-Driven-Design Pub/Sub Domain-Events framework
Stars: ✭ 978 (+2174.42%)
Mutual labels:  ddd-architecture
Jivejdon
Jivejdon is a Domain Driven Design appication with CQRS/ES/Clean/Hexagonal architecture
Stars: ✭ 287 (+567.44%)
Mutual labels:  ddd-architecture
Node Ddd Boilerplate
Node DDD Boilerplate
Stars: ✭ 501 (+1065.12%)
Mutual labels:  ddd-architecture
daruma-backend
🎎 Shared Expense Manager (Backend) - NestJS+DDD+CQRS+Event Sourcing 🎎
Stars: ✭ 70 (+62.79%)
Mutual labels:  ddd-architecture
Naos
A mildly opiniated modern cloud service architecture blueprint + reference implementation
Stars: ✭ 19 (-55.81%)
Mutual labels:  ddd-architecture
Tania Core
Tania is a farm management software to help farmers manage their farm operations.
Stars: ✭ 432 (+904.65%)
Mutual labels:  ddd-architecture
teamo-ddd-example
Implementing Domain Driven Design in PHP using Laravel
Stars: ✭ 46 (+6.98%)
Mutual labels:  ddd-architecture
Cp Ddd Framework
A lightweight flexible development framework for complex business architecture with full ecosystem!轻量级业务中台开发框架,中台架构的顶层设计和完整解决方案!
Stars: ✭ 566 (+1216.28%)
Mutual labels:  ddd-architecture
smartadmin.core.urf
Domain Driven Design (DDD) lightweight development architecture(support .net 5.0)
Stars: ✭ 100 (+132.56%)
Mutual labels:  ddd-architecture
Domain Driven Design Zh
DDD《领域驱动设计》中文翻译
Stars: ✭ 307 (+613.95%)
Mutual labels:  ddd-architecture
Ultimate Backend
Multi tenant SaaS starter kit with cqrs graphql microservice architecture, apollo federation, event source and authentication
Stars: ✭ 978 (+2174.42%)
Mutual labels:  ddd-architecture
Practical Clean Ddd
A simplified and effortless approach to get started with Domain-driven Design, Clean Architecture, CQRS, and Microservices patterns
Stars: ✭ 28 (-34.88%)
Mutual labels:  ddd-architecture
Ddd Guestbook
A DDD guestbook example written for ASP.NET Core
Stars: ✭ 447 (+939.53%)
Mutual labels:  ddd-architecture

stygis - golang Hexagonal Architecture

Just another sample of hexagonal architecture for golang focus on simplifed code, orgenized structure and better naming for functions and packages name No duplicate naming for package

old version:

https://github.com/iDevoid/stygis/tree/master

Project structure

stygis/
├── bin                                 
├── cmd                                 # Packages that provide support for a specific program that is being built, this contains cmd for REST, gRPC, etc
├── initiator                           # initialize any domain here that will be called inside cmd, so, no spaghetti init on cmd main package
├── internal                            # Contains all application packages (all functions must have return)
      ├── constants                     # For declaring all constants variable based on it's entity, declaring with full name descripting it
            ├── model                   # model is where the declaration of structs are being written
            ├── query                   # where query is being declared for storage sql, and it's better using sqlx naming system for passing the parameters
            ├── state                   # contains all constants variable (string, int, etc..) like status, or constant strings
      ├── glue                          # is just another name of middleware
            ├── routing                 # where the routing for handlers are assigned based on method and url
      ├── handler                       # any protocol interface that needs handler is being declare here, whether for cleaning input data, error payload handling, etc..
            ├── rest                    # handler for rest API technology
      ├── module                        # Domain packages are here, contains business logic and interfaces that belong to each domain, and no usecase calling other usecase
            ├── user                    # only sample domain, user package which handler for user business logic
                ├── initiator.go        # this is the only file to declare interface methods from storage and repository. also where to put func init the package.
                ....                    # name the file based on the usecase that may contains multiple acticity; example: login usecase for only one activity, profile contains edit profile and show profile
      ├── repository                    # this may a bit weird for you, this package uses for data storing logic, it is an optional if your domain only saves data to one db, but it's different when a domain uses multiple storage, for example caching and multiple persistences
      ├── storage                       # this is where you put the data storing code. whether persistence like postgresql, monggodb, etc. and caching like redis, etc. 
            ├── cache                   # package where caching storing code is written based on its domain.
            ├── persistence             # like its name, this package contains storing code for SQL or noSQL db
├── mocks                               # this contains all mock from any source. it contains some rules. it must be a generate files and the package name must be mock_(source)
      ├── psql                          # this is mock for psql contains package mock_psql, even tho it is written manually, it must have // Code generated manually. DO NOT EDIT.
      ├── redis                         # this is mock for redis contains package mock_redis, even tho it is written manually, it must have // Code generated manually. DO NOT EDIT.
      ├── user                          # this is generated by golang mock official generator
├── platform                            # external app for all uses (in here you can make function without return)
      ├── encryption                    # you can have any encryption method here
      ├── postgres                      # contains functions to open database postgres connections, with mutiple servers can be added, like db master and/or slave
      ├── redis                         # contains functions to open database redis connection, currently it uses only one connection, but this can be adjust just like the postgres connections
      ├── routers                       # contains functions to serve the HTTP Listener using all registered URLs with the handlers
├── static                              # to store any static file like pic, html, etc 

The Flow

constants (optional) -> glue (optional) -> handler -> module -> repository and/or storage


1. contants : depends on the development you may need to add some structs for data structuring that later can be used to the end of the flow
2. glue : depends on the technology you use
3. handler : requests are being orgenized, whether convertions, checking bad payloads, etc..
4. module : the business logic for processing the requests, everything that domain business logic has is centralized here, and write the log inside this package only
5. repository : use this if the business logic need the data logic that combine multiple data storage
6. storage : write the template of CRUD operation whatever the technology is

How TO Mock

Before you start to generate the mocks for any domain. Make sure that all interfaces are in initiator.go under your domain package.

  1. inside every initiator.go, put //go:generate mockgen -destination=../../../mocks/(source)/(file name destination).go -source=initiator.go under your package yourdomain line or under the first line example : //go:generate mockgen -destination=../../../mocks/user/user_mock.go -source=initiator.go

  2. run go generate ./... on your terminal (your directory position is the root of your project) this will runs the command you put inside the initiator.go the -destination=../../../mocks/(source) is to set the generated files to be all under mocks folder in your root project, so all mocks will be centralized under mocks package

How To:

  1. the package name (in file) must not be the same as the source
  2. to call the mock, write the package name (in file). for example: mock_user.NewMockCaching(ctrl) at least on VSCODE it automatically generate import mock_user "github.com/stygis/mocks/user why it must be mock_(source). because this is not a package of something to implement on the app. you cannot call the mock just using user.NewMockCaching(ctrl) or mock.NewMockCaching(ctrl). this is because unit test should be written manually, and the programmer who's writing it understands that unit test is important as the main code. also in technical reason, if we put the mock inside one package mocks as I did before. the other domain cannot make its mock because the same name of interfaces. this has a good side because you don't get many mocks function if the mocks are centralized inside one package, and the code and structure stay clean and organized.

Notes

Be aware that this may not be the better structure for your application, but i'm hopping to write into more general structure and stay simple

There is no duplication of package naming here, you can see that the there is rest folder inside cmd and handler. But the cmd doesn't use the rest package name, it uses main package name.

Medium

stygis — Golang Hexagonal Architecture

References

Ashley McNamara + Brian Ketelsen. Go best practices.

golang Hexagonal Arch Repositories

  1. Gira (A Hex Example)
  2. Kat Zień - Achieving maintainability with hexagonal architecture
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].