Home

Awesome

Golang Clean Architecture

The following is a folder structure pattern that I usually use, although I don't use all of them because of the project I'm working on only small projects that are not too big, so if you are interested in the pattern I made, you can use it if you think it's good, check this link for new update for this architecture here.

Table Of Content

What Are The Benefits ?

Flow Diagram

<img src="./diagram.png" alt="flow-diagram"/>

Folder Structure Pattern

├── tests
│   └── test.auth_test.go
│   └── test.student_test.go
└── docker
│   └── swagger
│   │     └── Dockerfile
│   │     └── openapi.yml
│   └── mysql
│   │     └── Dockerfile
│   │     └── mysql.cnf
│   └── golang
│   │     └── Dockerfile
├── handlers
│   └── auth
│   │     └── handler.login.go
│   │     └── handler.register.go
│   └── student
│   │     └── handler.create.go
│   │     └── handler.create.go
└── repositorys
│   └── auth
│   │     └── repository.login.go
│   │     └── repository.register.go
│   └── student
│   │     └── repository.create.go
│   │     └── repository.create.go
└── services
│   └── auth
│   │     └── services.login.go
│   │     └── services.register.go
│   └── student
│   │     └── services.create.go
│   │     └── services.create.go
└── helpers
│   └── helper.apiResponse.go
│   └── helper.randomString.go.go
└── middlewares
│   └── middleware.auth.go
│   └── middleware.role.go.go
└── models
│   └── model.auth.go
│   └── model.student.go.go
└── routes
│   └── route.auth.go
│   └── route.student.go
└── schemas
│   └── schema.auth.go
│   └── schema.student.go.go
└── templates
│   └── template.register.html
│   └── template.activation.html
└── pkg
│   └── pkg.jwt.go
│   └── pkg.bcrypt.go
│   └── pkg.cron.go
└── scripts
│   └── script.gcpRunner.sh
│   └── script.awsRunner.sh
└── configs
│   └── openapi.yml
│   └── serverless.yml
└── cmd
│   └── cmd.pgMigration.go
│   └── cmd.pgSeeds.go
└── crons
│   └── cron.autoDeleteLogs.go
│   └── cron.emailBlast.go
└── databases
│   └── migrations
│   │     └── auth_20210913.go //generate auto by cli using third party library
│   │     └── student_20210913.go //generate auto by cli using third party library
│   └── seeds
│   │     └── auth_20210913.go //generate auto by cli using third party library
│   │     └── student_20210913.go //generate auto by cli using third party library
│   └── sql
│   │     └── database.auth.sql
│   │     └── database.student.sql

Folder Status And Description

Folder NameFolder StatusDescription
TestsOptionalA collection of functions used to create a series of tests or run a test, be it unit testing or integration testing, which will later be used for the application itself.
Folder NameFolder StatusDescription
DockerOptionalA collection of functions that are used to create a container for the application that has been created, which will later be used for the application itself.
Folder NameFolder StatusDescription
HanldersOptionalA collection of functions used to handle all requests passed down from the client via routing, where later those requests will be forwarded to services and repositories for further processing, which will later be used for the application itself.
Folder NameFolder StatusDescription
RepositorysRequiredA collection of functions used to handle all requests given from handlers and services, which then those requests will be used to communicate with the database, which will later be used for the application itself.
Folder NameFolder StatusDescription
ServicesRequiredA collection of functions that are used to forward requests given by handlers to repositories, which will later be used for the application itself.
Folder NameFolder StatusDescription
HelpersOptionalA collection of functions used to create utilities for application purposes, such as customError or customResponse, which will later be used for the application itself.
Folder NameFolder StatusDescription
MiddlewaresOptionalA collection of functions that are used as a service for HTTP Requests such as authJWt, authRole, customLogger whether used per-route or used globally without the need to use them in each route, which will later be used for the application itself.
Folder NameFolder StatusDescription
ModelsRequiredA collection of functions used to represent the table structure in a database, which will later be used for the application itself.
Folder NameFolder StatusDescription
RoutesRequiredA collection of endpoints or addresses from the server itself, which is used for communication lines between the client and the server, which will later be used for the application itself.
Folder NameFolder StatusDescription
SchemasRequiredA collection of functions that are used to represent the desired request structure, according to the requests required by the database, which will later be used for the application itself.
Folder NameFolder StatusDescription
TemplatesOptionalA collection of functions that are used to output HTML code into emails to be used as templates, which will later be used for purposes such as activationCode or resetPassword, which will later be used for the application itself.
Folder NameFolder StatusDescription
PkgOptionalA collection of functions that are used for the purpose of customizing a library into a separate function, which will later be used for the application itself.
Folder NameFolder StatusDescription
ScriptsOptionalA collection of functions that are used to trigger a function from another function, such as importing a database from a .sql file into a container using docker, which will later be used for the application itself.
Folder NameFolder StatusDescription
ConfigsOptionalA collection of functions that contains all the configurations related to the application needs, such as .env or serverless.yml, which will later be used for the application itself.
Folder NameFolder StatusDescription
CmdOptionalA collection of functions that are used to interact directly with the terminal, usually used for purposes such as running database migrations or seeds, which will later be used for the application itself.
Folder NameFolder StatusDescription
CronsOptionalA collection of functions that are used to trigger a desired function, according to the time specified by the user, which will later be used for the application itself.
Folder NameFolder StatusDescription
DatabasesOptionalA collection of functions used to create migrations or seeds for the database, which will later be used for the application itself.

Command

<p align="right" style="padding: 5px; border-radius: 100%; background-color: red; font-size: 2rem;"> <b><a href="#golang-clean-architecture">BACK TO TOP</a></b> </p>