An open API service indexing awesome lists of open source software.

https://github.com/guntoroyk/go-user-api

A RESTFul API build using Go to demonstrate basic CRUD, authentication, and authorization. Code organized using Clean Architecture and Proxy Design Pattern.
https://github.com/guntoroyk/go-user-api

clean-architecture crud-application design-patterns go golang rest-api

Last synced: about 2 months ago
JSON representation

A RESTFul API build using Go to demonstrate basic CRUD, authentication, and authorization. Code organized using Clean Architecture and Proxy Design Pattern.

Awesome Lists containing this project

README

          

# go-user-api

A RESTFul API build using Go to demonstrate basic CRUD, authentication, and authorization.
Code organized using Clean Architecture and Proxy Design Pattern.

GitHub Repository: https://github.com/guntoroyk/go-user-api

# API Documentation

This API was deployed to Google Kubernetes Engine (GKE) Cluster with public IP `34.142.137.17`.

API docs can be accessed through this link: https://documenter.getpostman.com/view/6929584/2s8YzTTh9w

Or, click button bellow to try the API in Postman:

[![Run in Postman](https://run.pstmn.io/button.svg)]()

Or click this URL to open Postman Public Collection https://elements.getpostman.com/redirect?entityId=6929584-9e93e6a5-57ca-4250-931d-276052fe8dc0&entityType=collection

Don't forget to change the Environment located on the upper right corner of Postman app.

If you having trouble accessing that URL, you can download the the postman-collection.json here http://34.142.137.17/docs, then import it to your Postman desktop application.

# Credential

- Role: Admin

```
Username: admin

Password: 1234
```

- Role: User

```
Username: user

Password: 1234
```

## How to run on Local

Clone the repository

```
git clone git@github.com:guntoroyk/go-user-api.git
```

Run on docker

```
docker-compose up --build -d
```

The API will available at http://localhost:8000

## How to run on Kubernetes cluster

```
kubectl apply -f k8s-deploy/app/app_deployment.yml

kubectl apply -f k8s-deploy/app/app_service.yml

kubectl get svc

kubectl get pods
```

## Run the unit test

```
go mod vendor -v

go test ./... -v
```

## Software Design & Architecture Diagram

This API has 4 domains layer to follow the Clean Architecture:

- Entity layer
- Repository Layer
- Usecase Layer
- Handler Layer

With additional `Middleware` to intercept HTTP request & response, and `Proxy` between the Usecase and Repository to modify input & output data (here I used it to hash the password).

![Alt Software Design](./docs/software-design-diagram.png?raw=true "Software Design")

This API was deployed to Google Kubernetes Engine (GKE) cluster with following diagram:

![Alt Architecture Diagram](./docs/architecture-diagram-2.png?raw=true "Architecture Diagram")

The kubernetes deployment config is located on `./k8s-deploy` folder.

Run this command to deploy using `kubectl`:

```
kubectl apply -f k8s-deploy/app/app_deployment.yml

kubectl apply -f k8s-deploy/app/app_service.yml
```

Here is to check the deployment result:

![Alt Check kubernetes deployment](./docs/kubectl-get-svc-get-pods.png?raw=true "gCheck kubernetes deployment")

## Flowchart

1. Login

![Alt Login](./docs/flow-chart-login.png?raw=true "Login")

2. Refresh Token

![Alt Refresh Token](./docs/flow-chart-refresh-token.png?raw=true "Refresh Token")

3. Create User

![Alt Create User](./docs/flow-chart-create-user.png?raw=true "Create User")

4. Update User

![Alt Update User](./docs/flow-chart-update-user.png?raw=true "Update User")

5. Get Users

![Alt Get Users](./docs/flow-chart-get-user.png?raw=true "Get Users")

6. Get User By ID

![Alt Get User By ID](./docs/flow-chart-get-user-by-id.png?raw=true "Get User By ID")

7. Delete User

![Alt Delete User](./docs/flow-chart-delete-user.png?raw=true "Delete User")