A gRPC-Gateway-powered framework with Prisma, Kubernetes, and Go for scalable microservices.
Architecture Diagram Coming Soon!
Thunder is designed for and , particularly suited for:
When Not to Use Thunder
git clone https://github.com/Raezil/Thunder.git
cd Thunder
chmod +x install.sh
./install.sh
#99 Setup
Create a new Thunder application:
thunder init myapp
cd myapp
Install Dependencies
go mod tidy
Define Your gRPC Service
Create a .proto file (e.g., example.proto):
syntax = "proto3";
package example;
import "google/api/annotations.proto";
service Example {
rpc SayHello(HelloRequest) returns (HelloResponse) {
option (google.api.http) = {
get: "/v1/example/sayhello";
};
};
}
message HelloRequest {
string name = 1;
}
message HelloResponse {
string message = 1;
}
Add your service entry in services.json:
[
{
"ServiceName": "Example",
"ServiceStruct": "ExampleServiceServer",
"ServiceRegister": "RegisterExampleServer",
"HandlerRegister": "RegisterExampleHandler"
}
]
Define your schema in schema.prisma:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @default(cuid()) @id
name String
email String @unique
}
Generate the service implementation:
thunder generate --proto=example.proto
Start the server:
go run ./cmd/app/server/main.go
Server accessible via HTTP at localhost:8080 and gRPC at localhost:50051.
Mocking Tests:
cd pkg/services/generated
mockgen -source=yourservice_grpc.pb.go -destination=./yourservice_mock.go
Run Tests:
go test ./pkg/db ./pkg/middlewares/ ./pkg/services/ ./pkg/services/generated
PgBouncer Configuration
This setup configures PgBouncer to connect to a PostgreSQL database using Kubernetes resources.
Updating the userlist.txt Secret
To regenerate and update the userlist.txt secret, use the following command to encode the credentials:
echo '"postgres" "postgres"'|base64
Now, update pgbouncer-all.yaml under the Secret section with the new base64-encoded value:
apiVersion: v1
kind: Secret
metadata:
name: pgbouncer-secret
type: Opaque
data:
userlist.txt: <BASE64_ENCODED_VALUE>
# "postgres" "postgres" in base64
Generate TLS Certificates
cd cmd
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"
Generate Kubernetes Secrets
kubectl create secret generic app-secret --from-literal=DATABASE_URL="postgres://postgres:postgres@pgbouncer-service:6432/thunder?sslmode=disable" \
--from-literal=JWT_SECRET="secret"
kubectl create secret generic postgres-secret --from-literal=POSTGRES_USER=postgres \
--from-literal=POSTGRES_PASSWORD=postgres \
--from-literal=POSTGRES_DB=thunder
Build & Deploy Docker Image
thunder build
thunder deploy
Check pod status:
kubectl get pods -n default
kubectl describe pod $NAME -n default
Register User
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}'
User Login
curl -k --http2 -X POST https://localhost:8080/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "newuser@example.com","password": "password123"}'
Sample protected
curl -k -X GET "https://localhost:8080/v1/auth/protected?text=hello" \
-H "Authorization: $token"
$token is returned by login
Go Documentation
gRPC
gRPC-Gateway
Prisma ORM
Kubernetes Docs