Giter VIP home page Giter VIP logo

golang-clean-architecture's Introduction

A Simple Clean Architecture Implementation In Golang

Clean Architecture is a software architectural pattern designed to create scalable, maintainable, and testable applications using the Go programming language. It enforces a clear separation of concerns, making it easier to develop and maintain complex software systems.

alt text

What I have done in this sample project?

  • A sample user module with 5 apis
  • Send template mail using SMTP
  • Dockerizing project by dockerfile and docker-compose
  • Swagger API docs
  • Unit test
  • Integration tests for each use case

I. Tech stack:

  • Gin
  • GORM
  • Postgres
  • JWT
  • Docker

II. API documentation with Swagger

alt text

1. Install Swaggo

    go install github.com/swaggo/swag/cmd/swag@latest

2. Init swag to generate docs

    swag init -g cmd/main.go

III. Prepare database

1. Create postgres database using Docker

    make init_db

2. Remove database

    make  rm_db

IV. Run application

  • Remember to download all dependencies before you start server
    go mod download
    go mod tidy
  • Then you need to config your SMPT (gmail) in local.env and prod.env in config/env directory.
    # MAIL CONFIG
    MAIL_FROM=YOUR GMAIL
    MAIL_PASS=YOUR GMAIL APP PASSWORD
    MAIL_SERVER=smtp.gmail.com
    MAIL_PORT=587

1. Run with migration database

    make local m=true

2. Run without migration database

    make local m=false

V. Run with Docker

  • When you initiate the server using docker-compose, you don't need to start the database separately, as it will already be set up within docker-compose.

1. Compose up

  • The only command you need to start the server.
  • Remember to set up a prod.env file in the config/env directory before running the command. You can set up this file the same way as the local.env file, for example.
    make compose_up

2. Compose down

  • Run this command if you want to clear everything, including images and containers of the application, and the database as well.
    make compose_down

golang-clean-architecture's People

Contributors

anthanhphan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.