https://github.com/go-dev-frame/sponge
A powerful Go development framework for developing RESTful APIs, gRPC, and microservices projects in a "low-code" manner.
https://github.com/go-dev-frame/sponge
cloud-native code-generation custom-templates developer-tools gin go-sponge golang grpc grpc-gateway low-code microservice restful-api sponge web
Last synced: about 1 month ago
JSON representation
A powerful Go development framework for developing RESTful APIs, gRPC, and microservices projects in a "low-code" manner.
- Host: GitHub
- URL: https://github.com/go-dev-frame/sponge
- Owner: go-dev-frame
- License: mit
- Created: 2022-09-19T15:18:07.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-02T13:09:43.000Z (2 months ago)
- Last Synced: 2025-04-04T08:43:06.791Z (about 1 month ago)
- Topics: cloud-native, code-generation, custom-templates, developer-tools, gin, go-sponge, golang, grpc, grpc-gateway, low-code, microservice, restful-api, sponge, web
- Language: Go
- Homepage: https://go-sponge.com
- Size: 17.1 MB
- Stars: 1,715
- Watchers: 18
- Forks: 174
- Open Issues: 26
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## English | [简体中文](assets/readme-cn.md)
![]()
[](https://goreportcard.com/report/github.com/go-dev-frame/sponge)
[](https://codecov.io/gh/go-dev-frame/sponge)
[](https://pkg.go.dev/github.com/go-dev-frame/sponge)
[](https://github.com/go-dev-frame/sponge/actions)
[](https://github.com/avelino/awesome-go)
[](https://img.shields.io/github/license/go-dev-frame/sponge)**Sponge** is a powerful `Go` development framework. Its core concept revolves around reverse-engineering modular code by parsing `SQL`, `Protobuf`, and `JSON` files. The generated code can be flexibly and seamlessly assembled into various types of complete backend services (`similar to the characteristics of sponge cells, where disassembled sponge cells can automatically recombine into a new sponge`).
Sponge provides an all-in-one solution for project development with outstanding engineering capabilities, covering code generation, development, testing, API documentation, and deployment, significantly enhancing development efficiency, reducing complexity, and enabling high-quality projects with a "low-code approach".
### Applicable scenarios
Sponge is suitable for quickly developing various high-performance backend services, including but not limited to:
- `Web` services (gin);
- `gRPC` services;
- `HTTP+gRPC` hybrid services;
- `gRPC Gateway API` services;
- cloud-native microservices.Additionally, developers can use custom templates to generate various types of code to meet specific business needs.
### Core Highlights
1. **One-click generation of complete backend service code**
For `Web` or `gRPC` services that only require `CRUD APIs`, no `Go` code needs to be written. Simply connect to a database (e.g., `MySQL`, `MongoDB`, `PostgreSQL`, `SQLite`) to one-click generate complete backend service code and easily deploy it to Linux servers, Docker, or Kubernetes.2. **Efficient development of general-purpose services**
When developing general-purpose `Web`, `gRPC`, `HTTP+gRPC`, or `gRPC Gateway` services, you only need to focus on three aspects:
- Defining database tables;
- Defining API descriptions in Protobuf files;
- Writing business logic code in the generated templates.The framework code and CRUD API code are all automatically generated by sponge.
3. **Support for custom templates, offering flexible extensibility**
Sponge supports generating various types of project-specific code using custom templates, not limited to the `Go` language. For example:
- Backend code;
- Frontend code;
- Configuration files;
- Test code;
- Build and deployment scripts, etc.4. **Generate code on the page, simple and easy to use**
Sponge allows code generation directly on the page, making it simpler and more user-friendly than using the command line. You only need to fill in the relevant parameters on the page to generate code with one click.5. **Built-in AI assistant generates business logic implementation code**
Sponge comes with a built-in AI assistant (ChatGPT and DeepSeek), combining the strengths of both to form a comprehensive and efficient development solution:
- **Sponge**: Handles infrastructure code generation (service framework, CRUD API interfaces, and custom API interfaces without business logic implementation).
- **AI assistant**: Focuses on business logic implementation (table structure DDL design, custom API interface definition, and business logic implementation code).
### Quick Start
1. **Install sponge**
Sponge supports installation on Windows, macOS, and Linux. Click to view the [**sponge installation guide**](https://github.com/go-dev-frame/sponge/blob/main/assets/install-en.md).
2. **Open the code generation UI**
After installation, run the following command to open the sponge UI:
```bash
sponge run
```Access `http://localhost:24631` in a local browser to generate code through the UI interface, as shown below:
![]()
> To access from a browser on a different host, specify the host IP or domain when starting the UI, e.g., `sponge run -a http://your_host_ip:24631`. Alternatively, you can run the UI service in Docker to support cross-host access. Click to view the guide on [running the sponge UI service in Docker](https://github.com/go-dev-frame/sponge/blob/main/assets/install-en.md#Docker%E7%8E%AF%E5%A2%83).
### Main Features
Sponge has built-in rich features and components (for on-demand use):
| Features or Components | Examples |
| :---------- | :-------- |
| Web framework [gin](https://github.com/gin-gonic/gin) | [gin example](https://github.com/go-dev-frame/sponge/blob/main/internal/routers/routers.go#L35)
[gin middleware examples ](https://github.com/go-dev-frame/sponge/blob/main/pkg/gin/middleware/README.md) |
| RPC framework [gRPC](https://github.com/grpc/grpc-go) | [gRPC example](https://github.com/go-dev-frame/sponge/blob/main/internal/server/grpc.go#L312)
[gRPC interceptor examples](https://github.com/go-dev-frame/sponge/blob/main/pkg/grpc/interceptor/README.md) |
| Configuration parsing [viper](https://github.com/spf13/viper) | [example](https://github.com/go-dev-frame/sponge/blob/main/pkg/conf/README.md#example-of-use) |
| Logging [zap](https://github.com/uber-go/zap) | [example](https://github.com/go-dev-frame/sponge/blob/main/pkg/logger/README.md#example-of-use) |
| ORM [gorm](https://github.com/go-gorm/gorm), [mongo-go-driver](https://github.com/mongodb/mongo-go-driver) | [gorm example](https://github.com/go-dev-frame/sponge/blob/main/pkg/sgorm/README.md#examples-of-use)
[mongodb example](https://github.com/go-dev-frame/sponge/blob/main/pkg/mgo/README.md#example-of-use) |
| Cache [go-redis](https://github.com/go-redis/redis), [ristretto](https://github.com/dgraph-io/ristretto) | [go-redis example](https://github.com/go-dev-frame/sponge/blob/main/pkg/goredis/README.md#example-of-use)
[ristretto example](https://github.com/go-dev-frame/sponge/blob/main/pkg/cache/memory.go#L25) |
| 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) | [example](https://github.com/go-dev-frame/sponge/blob/main/pkg/jwt/README.md#example-of-use) |
| Parameter Verification [validator](https://github.com/go-playground/validator), [protoc-gen-validate](https://github.com/bufbuild/protoc-gen-validate) | [validator example](https://github.com/go-dev-frame/sponge/blob/main/internal/types/userExample_types.go#L17)
[protoc-gen-validate example](https://github.com/go-dev-frame/sponge/blob/main/api/serverNameExample/v1/userExample.proto#L156) |
| Websocket [gorilla/websocket](https://github.com/gorilla/websocket) | [example](https://github.com/go-dev-frame/sponge/blob/main/pkg/ws/README.md#example-of-use) |
| Crontab [cron](https://github.com/robfig/cron) | [example](https://github.com/go-dev-frame/sponge/blob/main/pkg/gocron/README.md#example-of-use) |
| Message Queue [rabbitmq](https://github.com/rabbitmq/amqp091-go), [kafka](https://github.com/IBM/sarama) | [rabbitmq example](https://github.com/go-dev-frame/sponge/blob/main/pkg/rabbitmq/README.md#example-of-use)
[kafka example](https://github.com/go-dev-frame/sponge/blob/main/pkg/kafka/README.md#example-of-use) |
| Distributed Transaction Manager [dtm](https://github.com/dtm-labs/dtm) | [example](https://github.com/go-dev-frame/sponge_examples/blob/main/_11_sponge-dtm-service-registration-discovery/internal/rpcclient/dtmservice.go#L31) |
| Distributed Lock [dlock](https://github.com/go-dev-frame/sponge/tree/main/pkg/dlock) | [example](https://github.com/go-dev-frame/sponge/blob/main/pkg/dlock/README.md#example-of-use) |
| Adaptive rate limiting [ratelimit](https://github.com/go-dev-frame/sponge/tree/main/pkg/shield/ratelimit) | [example](https://github.com/go-dev-frame/sponge/tree/main/pkg/shield/ratelimit#example-of-use) |
| Adaptive circuit breaking [circuitbreaker](https://github.com/go-dev-frame/sponge/tree/main/pkg/shield/circuitbreaker) | [example](https://github.com/go-dev-frame/sponge/tree/main/pkg/shield/circuitbreaker#example-of-use) |
| Distributed Tracing [opentelemetry](https://github.com/open-telemetry/opentelemetry-go) | [example](https://github.com/go-dev-frame/sponge/blob/main/pkg/tracer/README.md#example-of-use)
[cross-service tracing example](https://github.com/go-dev-frame/sponge/blob/main/pkg/tracer/example-en.md) |
| Metrics monitoring [prometheus](https://github.com/prometheus/client_golang/prometheus), [grafana](https://github.com/grafana/grafana) | [gin example](https://github.com/go-dev-frame/sponge/blob/main/pkg/gin/middleware/metrics/README.md#example-of-use)
[gRPC example](https://github.com/go-dev-frame/sponge/blob/main/pkg/grpc/metrics/README.md#example-of-use)
[web and gRPC monitoring examples](https://github.com/go-dev-frame/sponge/blob/main/pkg/grpc/metrics/monitor-example-en.md) |
| Service registration and discovery [etcd](https://github.com/etcd-io/etcd), [consul](https://github.com/hashicorp/consul), [nacos](https://github.com/alibaba/nacos) | [service registration example](https://github.com/go-dev-frame/sponge/blob/main/pkg/servicerd/registry/README.md#example-of-use)
[service discovery example](https://github.com/go-dev-frame/sponge/blob/main/pkg/servicerd/discovery/README.md#example-of-use) |
| Adaptive collecting [profile](https://go.dev/blog/pprof) | [example](https://github.com/go-dev-frame/sponge/blob/main/pkg/prof/go-profile-en.md) |
| Resource statistics [gopsutil](https://github.com/shirou/gopsutil) | [example](https://github.com/go-dev-frame/sponge/tree/main/pkg/stat#example-of-use) |
| Configuration center [nacos](https://github.com/alibaba/nacos) | [example](https://go-sponge.com/components?id=configuration-center) |
| Code quality checking [golangci-lint](https://github.com/golangci/golangci-lint) | - |
| Continuous integration and deployment CI/CD [kubernetes](https://github.com/kubernetes/kubernetes), [docker](https://www.docker.com/), [jenkins](https://github.com/jenkinsci/jenkins) | [example](https://go-sponge.com/deployment?id=continuous-integration-and-deployment) |
| Generate project business architecture diagram [spograph](https://github.com/go-dev-frame/spograph) | [example](https://github.com/go-dev-frame/spograph?tab=readme-ov-file#example-of-use) |
| Custom template generation code [go template](https://pkg.go.dev/text/[email protected]) | [json example](https://go-sponge.com/custom-template-field)
[sql example](https://go-sponge.com/custom-template-sql)
[protobuf example](https://go-sponge.com/custom-template-protobuf) |
| AI assistant [deepseek](https://deepseek.com), [chatgpt](https://chatgpt.com) | [example](https://github.com/go-dev-frame/sponge/blob/main/cmd/sponge/commands/assistant/generate.go#L42) |
### Code Generation Engine
The code generation engine of sponge supports two methods for generating the required project code: **built-in templates** and **custom templates**. Below are the framework diagrams for both approaches.
1. The framework for code generation based on built-in templates in sponge is shown below, supporting both SQL and Protobuf formats.
![]()
2. The framework for code generation based on custom templates in sponge is shown below, supporting JSON, SQL, and Protobuf formats.
![]()
### Microservice framework
Five of the six types of back-end services created by sponge are microservice architectures. The diagram below illustrates a typical layered microservice structure, featuring high performance, scalability, and built-in service governance capabilities.
![]()
Performance testing of http and grpc service code created by the microservices framework: 50 concurrent, 1 million total requests.


Click to view the [**test code**](https://github.com/zhufuyi/microservices_framework_benchmark).
### Project Code Directory Structure
The project code directory structure created by sponge follows the [project-layout](https://github.com/golang-standards/project-layout).
Sponge supports creating three types of project code structures: `Monolithic application monorepo (monolith)`, `Microservices multi-repo (multi-repo)`, and `Microservices monorepo (mono-repo)`.
1. The code directory structure for creating a `Monolithic application monorepo (monolith)` or `Microservices multi-repo (multi-repo)` is as follows:
```bash
.
├── api # Protobuf files and generated * pb.go directory
├── assets # Store various static resources, such as images, markdown files, etc.
├── cmd # Program entry directory
├── configs # Directory for configuration files
├── deployments # Bare metal, docker, k8s deployment script directory.
├── docs # Directory for API interface Swagger documentation.
├── internal # Directory for business logic code.
│ ├── cache # Cache directory wrapped around business logic.
│ ├── config # Directory for Go structure configuration files.
│ ├── dao # Data access directory.
│ ├── database # database 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.
├── test # Directory for scripts required for testing services and test SQL.
├── third_party # Directory for third-party protobuf files or external helper programs.
├── Makefile # Develop, test, deploy related command sets .
├── go.mod # Go module dependencies and version control file.
└── go.sum # Go module dependencies key and checksum file.
```
2. The code directory structure for creating a `Microservices monorepo (mono-repo)` (large repository code directory structure) is as follows:
```bash
.
├── api
│ ├── server1 # Protobuf files and generated *pb.go directory for service 1.
│ ├── server2 # Protobuf files and generated *pb.go directory for service 2.
│ ├── server3 # Protobuf files and generated *pb.go directory for service 3.
│ └── ...
├── server1 # Code directory for Service 1, it has a similar structure to the microservice multi repo directory.
├── server2 # Code directory for Service 2, it has a similar structure to the microservice multi repo directory.
├── server3 # Code directory for Service 3, it has a similar structure to the microservice multi repo directory.
├── ...
├── third_party # Third-party protobuf files.
├── go.mod # Go module dependencies and version control file.
└── go.sum # Go module dependencies' checksums and hash keys.
```
### Sponge Development Documentation
Click to view [the detailed documentation](https://go-sponge.com/) for Sponge development project, including code generation, development, configuration, and deployment instructions, and more.
### Examples of use
#### Examples of create services
- [Create **web** service based on **sql** (including CRUD)](https://github.com/go-dev-frame/sponge_examples/tree/main/1_web-gin-CRUD)
- [Create **grpc** service based on **sql** (including CRUD)](https://github.com/go-dev-frame/sponge_examples/tree/main/2_micro-grpc-CRUD)
- [Create **web** service based on **protobuf**](https://github.com/go-dev-frame/sponge_examples/tree/main/3_web-gin-protobuf)
- [Create **grpc** service based on **protobuf** ](https://github.com/go-dev-frame/sponge_examples/tree/main/4_micro-grpc-protobuf)
- [Create **grpc gateway** service based on **protobuf**](https://github.com/go-dev-frame/sponge_examples/tree/main/5_micro-gin-rpc-gateway)
- [Create **grpc+http** service based on **protobuf**](https://github.com/go-dev-frame/sponge_examples/tree/main/_10_micro-grpc-http-protobuf)#### Examples of develop complete project
- [Simple community web backend service](https://github.com/go-dev-frame/sponge_examples/tree/main/7_community-single)
- [Simple community web service broken down into microservice](https://github.com/go-dev-frame/sponge_examples/tree/main/8_community-cluster)#### Distributed transaction examples
- [Simple distributed order system](https://github.com/go-dev-frame/sponge_examples/tree/main/9_order-grpc-distributed-transaction)
- [Flash sale](https://github.com/go-dev-frame/sponge_examples/tree/main/_12_sponge-dtm-flashSale)
- [E-Commerce system](https://github.com/go-dev-frame/sponge_examples/tree/main/_14_eshop)#### Sponge+AI assistant collaborative development
- [Home appliance retail management platform](https://github.com/go-dev-frame/sponge_examples/tree/main/_15_appliance_store)
**If it's help to you, give it a star ⭐.**