https://github.com/xmlking/grpc-starter-kit
https://github.com/xmlking/grpc-starter-kit
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/xmlking/grpc-starter-kit
- Owner: xmlking
- License: mit
- Created: 2020-06-14T19:11:00.000Z (almost 6 years ago)
- Default Branch: develop
- Last Pushed: 2023-12-03T20:15:07.000Z (over 2 years ago)
- Last Synced: 2024-06-19T01:57:13.107Z (almost 2 years ago)
- Language: TypeScript
- Size: 9.57 MB
- Stars: 47
- Watchers: 5
- Forks: 5
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# grpc-starter-kit
Microservices starter kit for **Golang**, aims to be developer friendly.
An _open source_ framework for building and deploying distributed applications. This template _monorepo_ style project allows you to write your application as a modular monolith and deploy it as a set of microservices.
[](https://godoc.org/github.com/xmlking/grpc-starter-kit)
[](https://golang.org/dl/)
[](https://renovatebot.com/)
[](https://opensource.org/licenses/MIT)
### Build Status
[](https://github.com/xmlking/grpc-starter-kit/actions?query=branch%3Adevelop+event%3Apush+workflow%3A%22Test+on+Push%22)
### Quality
[](https://goreportcard.com/report/github.com/xmlking/grpc-starter-kit)
[](https://lgtm.com/projects/g/xmlking/grpc-starter-kit/alerts/)
[](https://codecov.io/gh/xmlking/grpc-starter-kit)
[](https://lgtm.com/projects/g/xmlking/grpc-starter-kit/context:go)
## Overview
### What you get
- [x] Monorepo - Sharing Code Between Microservices
- [x] gRPC microservices
- [x] Versatile ingress gateway based on Envoy with Config Manager [esp-v2](https://github.com/GoogleCloudPlatform/esp-v2)
- [ ] Proxy-less Service Discovery and xDS based gRPC Load Balancer with [Traffic Director](https://cloud.google.com/blog/products/networking/traffic-director-supports-proxyless-grpc)
- [x] Input Validation with [protoc-gen-validate (PGV)](https://github.com/envoyproxy/protoc-gen-validate)
- [x] Add/replace struct tags on generated protobuf messages [protoc-gen-gotag (PGGT)](https://github.com/srikrsna/protoc-gen-gotag)
- [x] Config - Pluggable Sources, Mergeable Config, Environment Overlays
- [x] Customizable Logging
- [x] Flexible [errors](https://github.com/cockroachdb/errors) lib: _PII-free, gRPC middleware, opt-in Sentry.io reporting_
- [x] Graph-Based ORM [ent](https://entgo.io/)
- [x] CRUD API with [ent](https://entgo.io/blog/2021/03/18/generating-a-grpc-server-with-ent/)
- [x] Dependency injection [Container](https://github.com/sarulabs/di), Try [wire](https://itnext.io/mastering-wire-f1226717bbac) next?
- [ ] Adaptive System Protection / Adaptive concurrency limits with
[Alibaba's Sentinel](https://github.com/alibaba/sentinel-golang/wiki),
[Netflix's concurrency-limits](https://medium.com/@NetflixTechBlog/performance-under-load-3e6fa9a60581),
[go-concurrency-limits](https://github.com/platinummonkey/go-concurrency-limits)
- [x] multi-stage-multi-target Dockerfile
- [x] [Reproducible builds](https://reproducible-builds.org/) and [Verifiable Builds](https://goreleaser.com/customization/verifiable_builds/) with [GoReleaser](https://goreleaser.com/customization/build/#reproducible-builds)
- [x] One Step _build/publish/deploy_ with [ko](https://github.com/google/ko)
- [x] BuildInfo with [govvv](https://github.com/ahmetb/govvv)
- [ ] Switch to [Bazel Build](https://bazel.build/)
- [x] Linting with [GolangCI](https://github.com/golangci/golangci-lint) linters aggregator
- [x] Linting Protos with [Buf](https://buf.build/docs/introduction)
- [x] Linting rest with [super-linter](https://github.com/github/super-linter/blob/master/docs/disabling-linters.md)
- [x] CICD Pipelines with [GitHub Actions](https://github.com/features/actions)
- [x] Kubernetes _Matrix Deployment_ with [Kustomize](https://kustomize.io/)
- [ ] Add k8s [healthchecks](https://github.com/heptiolabs/healthcheck) with [cmux](https://medium.com/@drgarcia1986/listen-grpc-and-http-requests-on-the-same-port-263c40cb45ff)
- [x] Feature Flags & [Feature Gating](https://codeburst.io/designing-feature-gates-with-firebase-8b2a2394a88e) (enable/disable with zero cost)
- [x] Observability via [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-go)
- [ ] Service Mesh with [Istio](https://istio.io/)
- [ ] GraphQL Gateway with [gqlgen](https://gqlgen.com/), [rejoiner](https://github.com/google/rejoiner),[gqlgen](https://github.com/Shpota/skmz)
- [ ] Graceful / zero downtime upgrades [tableflip](https://github.com/cloudflare/tableflip)
- [ ] Cache — Ephemeral key-value storage with TTLs
- [ ] Secondary Index — Ephemeral Index with Redis Search
- [ ] Crypto — App-level data encryption/decryption with Key Management
- [ ] Auth — API Authentication with OpenID Connect, JWT, WebAuthN/[Passwordless](https://github.com/teamhanko/apple-wwdc21-webauthn-example) Login
- [ ] [Zero Trust](https://smallstep.com/docs/practical-zero-trust) or [BeyondProd](https://cloud.google.com/security/beyondprod) style e2e Security
- [ ] **mTLS**
- [ ] _Option 1 (noCert)_: With **Application LayerTransport Security** [(ALTS)](https://github.com/salrashid123/grpc_alts)
- [ ] _Option 2 (autoCert)_: With [AutoCert](https://github.com/smallstep/autocert/tree/master/examples/hello-mtls/go-grpc)
- [ ] _Option 3 (Step xDS)_: With Smallstep's Secret Discovery Service [SDS](https://github.com/smallstep/step-sds)
- [ ] [supply-chain](https://github.com/goreleaser/supply-chain-example) GoReleaser + Go Mod proxying + Cosign keyless signing + Syft SBOM generation example.
- [ ] [Multi-arch container image ]()
- [ ] [gkit](https://github.com/songzhibin97/gkit)
- [ ] [Continuous Profiling for Go Applications](https://betterprogramming.pub/continuous-profiling-go-applications-8cdbdfdfc5ab) with [Pyroscope](https://github.com/grafana/pyroscope)
## Getting Started
### Prerequisite
Refer [prerequisites](docs/introduction/prerequisites.md) docs
### Initial Setup
Also Refer [scaffolding](docs/introduction/scaffolding.md) docs
> clone the repo
```bash
git clone https://github.com/xmlking/grpc-starter-kit ~/Developer/Work/go/grpc-starter-kit
# pull dependencies (when every time `go.mod` changed)
go mod download
```
### Run
#### Database
By default, this project use embedded `sqlite3` database. if you want to use **postgreSQL**,
- start **postgres** via `docker-compose` command provided below
- uncomment `postgres` import statement and comment `sqlite` in `main.go`
- start micro server with `export export CONFY_FILES=/config/config.yml,/config/config.pg.yml` flag
i.e., `CONFY_FILES=/config/config.yml,/config/config.pg.yml go run service/account/main.go`
```bash
# to start postgres in foreground
docker-compose up postgres
# to stop postgres
docker-compose down
# if needed, remove `postgres_data` volume to recreate database next time, when you start.
docker system prune --volumes
```
#### Services
> Node: `--server_address=localhost:5501x --broker_address=localhost:5502x` required only when you are behind VPN a.k.a `Work From Home`
```bash
# dev mode
make run-recorder
make run-emailer
make run-greeter
make run-account
# experiments
make run-cedemo
make run-play
make run-xds
```
> optionally specify any **Confy** environment variable
```bash
```shell
export CONFY_ENV=production
export CONFY_FILES=/config/config.yml
# (or) export CONFY_FILES=/config/config.yml,/config/config.pg.yml
export CONFY_DEBUG_MODE=true
export CONFY_VERBOSE_MODE=true
export CONFY_SILENT_MODE=true
export CONFY_ENV=production
export CONFY_ENV_PREFIX=APP
export APP_FEATURES_TLS_ENABLED=true
make run-account
```
### Test
Refer [testing](docs/testing/testing.md) docs
## GitOps
### Make
Refer [makefile](docs/introduction/makefile.md) docs
### Docker
Refer [docker](docs/devops/docker.md) docs
### Release
Refer [releasing](docs/concepts/releasing.md) docs
### Deploy
```bash
make docker DOCKER_REGISTRY=ghcr.io DOCKER_CONTEXT_PATH=xmlking/grpc-starter-kit
docker rmi $(docker images -f "dangling=true" -q)
# make kustomize OVERLAY=e2e NS=default VERSION=v0.1.0-440-g6c7fb7a
make kustomize
kubectl apply -f build/kubernetes.yaml
POD_NAME=$(kubectl get pods -lapp.kubernetes.io/name=account-srv -o jsonpath='{.items[0].metadata.name}')
kubectl logs -f -c srv $POD_NAME
kubectl delete -f build/kubernetes.yaml
```
## Reference
### Project Docs
1. [prerequisites](docs/introduction/prerequisites.md)
2. [scaffolding](docs/introduction/scaffolding.md)
3. [makefile](docs/introduction/makefile.md)
4. [testing](docs/testing/testing.md)
5. [docker](docs/devops/docker.md)
6. [gitops](docs/advanced/gitops.md)
7. [Protobuf Style Guide](https://buf.build/docs/style-guide)
8. [Google Protobuf Style Guide](https://github.com/uber-go/guide/blob/master/style.md)
9. [Spine Protobuf Style Guide](https://spine.io/docs/introduction/naming-conventions)
### External Docs
1. [Go Repo Layout](https://christine.website/blog/within-go-repo-layout-2020-09-07)
2. [examples](https://github.com/micro/examples) - example usage code for micro
3. [microhq](https://github.com/microhq) - a place for prebuilt microservices
4. [explorer](https://micro.mu/explore/) - which aggregates micro based open source projects
5. [micro-plugins](https://github.com/micro/go-plugins) extensible micro plugins
6. [step-by-step-guide-micro](https://github.com/micro-in-cn/tutorials/tree/master/microservice-in-micro)
7. [micro-in-cn](https://github.com/micro-in-cn/tutorials/tree/master/examples)
8. [Platform Web](https://github.com/micro-in-cn/platform-web)
9. [grpc template](https://github.com/vtolstov/micro-template-grpc)
10. [Simple API backed by PostgresQL, Golang and gRPC](https://medium.com/@vptech/complexity-is-the-bane-of-every-software-engineer-e2878d0ad45a)
11. [securing gRPC connections with TLS](https://itnext.io/practical-guide-to-securing-grpc-connections-with-go-and-tls-part-2-994ef93b8ea9) via [certify](https://github.com/johanbrandhorst/certify)
12. [Google Service Weaver: A Framework for Writing Distributed Applications](https://opensource.googleblog.com/2023/03/introducing-service-weaver-framework-for-writing-distributed-applications.html)
## 🔗 Credits
- [atlas-app-toolkit](https://github.com/infobloxopen/atlas-app-toolkit)
- [dapr](https://github.com/dapr/dapr)
- [goyave](https://github.com/System-Glitch/goyave)