https://github.com/raezil/thunder
gRPC-Gateway + Prisma + GO
https://github.com/raezil/thunder
backend containerization framework golang grpc-gateway-example grpc-go kubernetes prisma template
Last synced: 7 months ago
JSON representation
gRPC-Gateway + Prisma + GO
- Host: GitHub
- URL: https://github.com/raezil/thunder
- Owner: Raezil
- Created: 2024-11-03T12:42:00.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-02-27T18:10:43.000Z (8 months ago)
- Last Synced: 2025-02-27T19:10:54.806Z (8 months ago)
- Topics: backend, containerization, framework, golang, grpc-gateway-example, grpc-go, kubernetes, prisma, template
- Language: Go
- Homepage:
- Size: 10.4 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# **Thunder - A Minimalist Backend Framework in Go**
*A gRPC-Gateway-powered framework with Prisma, Kubernetes and Go for scalable microservices.*[](https://golang.org)
[](LICENSE)
[](https://github.com/Raezil/Thunder/stargazers)
[](https://github.com/Raezil/Thunder/issues)## **Table of Contents**
- [π Features](#-features)
- [π Getting Started](#-getting-started)
- - [β‘ Thunder CLI](#thunder-cli)
- [1οΈβ£ Install Dependencies](#1οΈβ£-install-dependencies)
- [2οΈβ£ Define Your gRPC Service](#2οΈβ£-define-your-grpc-service)
- [π οΈ Prisma Integration](#οΈ-prisma-integration)
- [π Running the Server](#-running-the-server)
- [a. Code Generation](#a-code-generation)
- [b. Start the **gRPC + REST API** server](#b-start-the-grpc--rest-api-server)
- [π Running the Tests](#-running-the-tests)
- [a. Mocking Tests](#a-mocking-tests)
- [b. Running the Tests](#b-running-the-tests)
- [π§ Kubernetes Deployment](#-kubernetes-deployment)
- [1οΈβ£ Generate TLS Certificates](#1οΈβ£-generate-tls-certificates)
- [2οΈβ£ Build & Push Docker Image](#2οΈβ£-build--push-docker-image)
- [3οΈβ£ Deploy to Kubernetes](#3οΈβ£-deploy-to-kubernetes)
- [π‘ API Testing](#-api-testing)
- [Register a User](#register-a-user)
- [Login](#login)
- [π Contributing](#-contributing)
- [π References](#-references)
- [π£ Stay Connected](#-stay-connected)---
## **π Features**
βοΈ **gRPC + REST (gRPC-Gateway)** β Automatically expose RESTful APIs from gRPC services.
βοΈ **Prisma Integration** β Use Prisma for efficient database access in Go.
βοΈ **Kubernetes Ready** β Easily deploy and scale with Kubernetes.
βοΈ **TLS Security** β Secure gRPC communications with TLS.
βοΈ **Structured Logging** β Built-in `zap` logging.
βοΈ **Rate Limiting & Authentication** β Pre-configured middleware.
βοΈ **Modular & Extensible** β Easily extend Thunder for custom use cases.
βοΈ **Thunder CLI** - generate, deploy, create new project by using dedicated CLI.---
## **π Getting Started**
### **Thunder CLI**
For a comprehensive guide on how to use Thunder CLIβincluding installation steps, available commands, and usage examplesβyou can refer to the official documentation here:
https://github.com/Raezil/Thunder/blob/main/thunder-cli.mdThis file covers everything you need to get started with Thunder CLI and will help you integrate it into your development workflow.
### **1οΈβ£ Install Dependencies**
Ensure you have Go, `protoc`, and Prisma installed.```sh
go mod tidy
```### **2οΈβ£ Define Your gRPC Service**
Create a `.proto` file, e.g., `user.proto`:```proto
syntax = "proto3";package example;
option go_package = "backend/";
import "google/api/annotations.proto";
// A simple service definition.
service UserService {
rpc GetUser (UserRequest) returns (UserResponse) {
option (google.api.http) = {
get: "/v1/users/{id}"
};
}
}// Request and response messages.
message UserRequest {
int32 id = 1;
}message UserResponse {
int32 id = 1;
string name = 2;
int32 age = 3;
}
```
---## **π οΈ Prisma Integration**
Thunder automatically integrates Prisma for database management. Define your schema:## a. Create Your schema.prisma File
```prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}model User {
id String @default(cuid()) @id
name String
email String @unique
}
```## **π Running the Server**
#### a. Code Generation
```
thunder generate -proto=filename.proto -prisma=true
```
> **Note:** Replace `filename` with the actual name of your gRPC service.
> **Note** Remember to install [ Thunder CLI](#thunder-cli)#### b. Start the **gRPC + REST API** server:
```sh
go run ./server/main.go
```
> **Note:** Generate TLS certificates prior running the server.## **π Running the Tests**
#### a. Mocking Tests
To mock a gRPC server:
```
cd backend
mockgen -source=yourservice_grpc.pb.go -destination=yourservice_mock.go
```
> **Note:** Replace `yourservice` with the actual name of your gRPC service. Look into /backend/authenticator_server_test.go to see how to develop tests or look into https://github.com/golang/mock#### b. Running the Tests
```
go test ./backend/... ./db/...
```---
## **π§ Kubernetes Deployment**
### **1οΈβ£ Generate TLS Certificates**
```sh
mkdir certs
openssl req -x509 -newkey rsa:4096 -keyout certs/server.key -out certs/server.crt -days 365 -nodes \
-subj "/CN=localhost" \
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
```### **2οΈβ£ Build & Push Docker Image**
```
thunder docker
```### **3οΈβ£ Deploy to Kubernetes**
```sh
thunder deploy
```
**Note** Remember to install [ Thunder CLI](#thunder-cli)#### Checking Pod Status
```
kubectl get pods -n default
kubectl describe pod $NAME -n default
```---
## **π‘ API Testing**
### **Register a User**
```sh
curl -k --http2 -X POST https://localhost:8080/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "newuser@example.com",
"password": "password123",
"name": "John",
"surname": "Doe",
"age": 30
}'
```### **Login**
```sh
curl -k --http2 -X POST https://localhost:8080/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "newuser@example.com",
"password": "password123"
}'
```
---## **π Contributing**
Want to improve Thunder? π
1. Fork the repo
2. Create a feature branch (`git checkout -b feature-new`)
3. Commit your changes (`git commit -m "Added feature"`)
4. Push to your branch (`git push origin feature-new`)
5. Submit a PR!---
## **π References**
- π [Go Documentation](https://golang.org/doc/)
- π [gRPC-Gateway](https://grpc-ecosystem.github.io/grpc-gateway/)
- π οΈ [Prisma ORM](https://www.prisma.io/docs/)
- βοΈ [Kubernetes Docs](https://kubernetes.io/docs/)---
## **π£ Stay Connected**
β Star the repo if you find it useful!
π§ For questions, reach out via [GitHub Issues](https://github.com/Raezil/Thunder/issues).