Ecosyste.ms: Awesome

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

https://github.com/zhufuyi/sponge

Sponge is a powerful Go development framework, it's easy to develop web and microservice projects.
https://github.com/zhufuyi/sponge

architecture crud development-framework generate-code gin go golang grpc grpc-gateway microservice-framework microservices restful-api rpc sponge web

Last synced: 23 days ago
JSON representation

Sponge is a powerful Go development framework, it's easy to develop web and microservice projects.

Lists

README

        

## English | [简体中文](assets/readme-cn.md)



[![Go Report](https://goreportcard.com/badge/github.com/zhufuyi/sponge)](https://goreportcard.com/report/github.com/zhufuyi/sponge)
[![codecov](https://codecov.io/gh/zhufuyi/sponge/branch/main/graph/badge.svg)](https://codecov.io/gh/zhufuyi/sponge)
[![Go Reference](https://pkg.go.dev/badge/github.com/zhufuyi/sponge.svg)](https://pkg.go.dev/github.com/zhufuyi/sponge)
[![Go](https://github.com/zhufuyi/sponge/workflows/Go/badge.svg?branch=main)](https://github.com/zhufuyi/sponge/actions)
[![Awesome Go](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/avelino/awesome-go)
[![License: MIT](https://img.shields.io/github/license/zhufuyi/sponge)](https://img.shields.io/github/license/zhufuyi/sponge)

**Sponge** is a powerful development framework that integrates `automatic code generation`, `Gin and GRPC`. Sponge has a rich set of code generation commands, and the generated different functional codes can be combined into a complete service (similar to how artificially broken sponge cells can automatically reassemble into a new complete sponge). From code generation, development, testing, API documentation to deployment, one-stop project development greatly improves development efficiency and reduces development difficulty, implementation of "low-code way" development projects.


If you are develop web service or microservice with CRUD APIs, you don't need to write any Go code can be compiled and deployed to the linux server, docker, k8s, just need to connect to the database (mysql、mongodb、postgresql、tidb、sqlite) to generate a complete backend service Go code.

If you develop generic web or microservices, just focus on the three core parts of `define tables in the database`, `define api description information in the proto files`, `fill in business logic code in the generated template files`, and the rest of the Go code is automatically generated by sponge.


### Sponge Generates the Code Framework

Sponge is mainly based on `SQL` and `Protobuf` two ways to generate code, each way has to generate code for different functions. `SQL` supports databases **mysql**, **mongodb**, **postgresql**, **tidb**, **sqlite**.

#### Generate Code Framework




#### Generate Code Framework Corresponding UI Interface




### Microservice framework

Sponge is also a microservices framework, the framework diagram is shown below, which is a typical microservice hierarchical structure, with high performance, high scalability, contains commonly used service governance features, you can easily replace or add their own service governance features.




Performance testing of http and grpc service code created by the microservices framework: 50 concurrent, 1 million total requests.

![http-server](https://raw.githubusercontent.com/zhufuyi/microservices_framework_benchmark/main/test/assets/http-server.png)

![grpc-server](https://raw.githubusercontent.com/zhufuyi/microservices_framework_benchmark/main/test/assets/grpc-server.png)

Click to view the [**test code**](https://github.com/zhufuyi/microservices_framework_benchmark).


### Key Features

- Web framework [gin](https://github.com/gin-gonic/gin)
- RPC framework [grpc](https://github.com/grpc/grpc-go)
- Configuration parsing [viper](https://github.com/spf13/viper)
- Configuration center [nacos](https://github.com/alibaba/nacos)
- Logging component [zap](https://github.com/uber-go/zap)
- Database ORM component [gorm](https://github.com/go-gorm/gorm), [mongo-go-driver](https://github.com/mongodb/mongo-go-driver)
- Cache component [go-redis](https://github.com/go-redis/redis), [ristretto](https://github.com/dgraph-io/ristretto)
- Automated API documentation [swagger](https://github.com/swaggo/swag), [protoc-gen-openapiv2](https://github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2)
- Authentication [jwt](https://github.com/golang-jwt/jwt)
- Message Queue [rabbitmq](https://github.com/rabbitmq/amqp091-go)
- Distributed Transaction Manager [dtm](https://github.com/dtm-labs/dtm)
- Parameter validation [validator](https://github.com/go-playground/validator)
- Adaptive rate limiting [ratelimit](https://github.com/zhufuyi/sponge/tree/main/pkg/shield/ratelimit)
- Adaptive circuit breaking [circuitbreaker](https://github.com/zhufuyi/sponge/tree/main/pkg/shield/circuitbreaker)
- Distributed Tracing [opentelemetry](https://github.com/open-telemetry/opentelemetry-go)
- Metrics monitoring [prometheus](https://github.com/prometheus/client_golang/prometheus), [grafana](https://github.com/grafana/grafana)
- Service registration and discovery [etcd](https://github.com/etcd-io/etcd), [consul](https://github.com/hashicorp/consul), [nacos](https://github.com/alibaba/nacos)
- Adaptive collecting [profile](https://go.dev/blog/pprof)
- Resource statistics [gopsutil](https://github.com/shirou/gopsutil)
- Code quality checking [golangci-lint](https://github.com/golangci/golangci-lint)
- Continuous integration and deployment [jenkins](https://github.com/jenkinsci/jenkins), [docker](https://www.docker.com/), [kubernetes](https://github.com/kubernetes/kubernetes)


### Project Code Directory Structure

The project code directory structure created by sponge follows the [project-layout](https://github.com/golang-standards/project-layout) and is structured as follows. Supported repository types are `monolithic application single repository (monolith)`, `microservice multi-repository (multi-repo)`, `microservice single repository (mono-repo)`.

```bash
.
├── api # Directory for exposing external API interfaces, typically containing proto files and generated *.pb.go files. The directory structure is typically in the form `api/xxx/v1`, where v1 indicates the version.
├── assets # Store various static resources, such as images, markdown files, etc.
├── cmd # Program entry directory
│ └── serviceName
│ ├── initial # Program initialization, consisting of three files: initApp initializes configurations, registerServers registers services (HTTP or grpc), and registerClose registers resource cleanup.
│ └── main.go # Program entry file
├── configs # Directory for configuration files
├── deployments # Directory for deployment scripts, supporting Bare Metal, Docker and Kubernetes deployments.
├─ docs # Directory for API interface Swagger documentation.
├── i(I)nternal # Directory for business logic code, if the first letter is lowercase (internal), it means private code, if the first letter is capitalised (Internal), it means it can be reused by other code.
│ ├── cache # Cache directory wrapped around business logic.
│ ├── config # Directory for Go structure configuration files.
│ ├── dao # Data access directory.
│ ├── ecode # Directory for system error codes and custom business error codes.
│ ├── handler # Directory for implementing HTTP business functionality (specific to web services).
│ ├── model # Database model directory.
│ ├── routers # HTTP routing directory.
│ ├── rpcclient # Directory for client-side code that connects to grpc services.
│ ├── server # Directory for creating services, including HTTP and grpc.
│ ├── service # Directory for implementing grpc business functionality (specific to grpc services).
│ └── types # Directory for defining request and response parameter structures for HTTP.
├── pkg # Directory for shared libraries.
├── scripts # Directory for scripts, including compilation, execution, code generation, and deployment scripts.
├── test # Directory for scripts required for testing services and test SQL.
└── third_party # Directory for external helper programs, forked code, and other third-party tools.
```


### Quick start

#### Installation sponge

Sponge can be installed on Windows, macOS, Linux and Docker environments. Click here for [instructions on installing sponge](https://github.com/zhufuyi/sponge/blob/main/assets/install-en.md).

#### Starting UI service

After installing the sponge, start the UI service:

```bash
sponge run
```

Access `http://localhost:24631` in a local browser and manipulate the generated code on the UI page.

> If you want to access it on a cross-host browser, you need to specify the host ip or domain name when starting the UI, example `sponge run -a http://your_host_ip:24631`. It is also possible to start the UI service on docker to support cross-host access, Click for instructions on [starting the sponge UI service in docker](https://github.com/zhufuyi/sponge/blob/main/assets/install-en.md#docker-environment).


### Sponge Development Documentation

Detailed instructions for operating, configuring, and deploying a project using sponge development, Click here to view the [sponge development documentation](https://go-sponge.com/)


### Examples of use

#### Examples of create services

- [Create **web** service based on **sql** (including CRUD)](https://github.com/zhufuyi/sponge_examples/tree/main/1_web-gin-CRUD)
- [Create **grpc** service based on **sql** (including CRUD)](https://github.com/zhufuyi/sponge_examples/tree/main/2_micro-grpc-CRUD)
- [Create **web** service based on **protobuf**](https://github.com/zhufuyi/sponge_examples/tree/main/3_web-gin-protobuf)
- [Create **grpc** service based on **protobuf** ](https://github.com/zhufuyi/sponge_examples/tree/main/4_micro-grpc-protobuf)
- [Create **grpc gateway** service based on **protobuf**](https://github.com/zhufuyi/sponge_examples/tree/main/5_micro-gin-rpc-gateway)
- [Create **grpc+http** service based on **protobuf**](https://github.com/zhufuyi/sponge_examples/tree/main/a_micro-grpc-http-protobuf)

#### Examples of develop complete project

- [Simple community web backend service](https://github.com/zhufuyi/sponge_examples/tree/main/7_community-single)
- [Simple community web service broken down into microservice](https://github.com/zhufuyi/sponge_examples/tree/main/8_community-cluster)

#### Distributed transaction examples

- [Simple distributed order system](https://github.com/zhufuyi/sponge_examples/tree/main/9_order-grpc-distributed-transaction)


### License

See the [LICENSE](LICENSE) file for licensing information.




**If it's help to you, give it a star ⭐.**