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

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

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.*

[![Go Version](https://img.shields.io/badge/Go-1.21-blue)](https://golang.org)
[![License](https://img.shields.io/github/license/Raezil/Thunder)](LICENSE)
[![Stars](https://img.shields.io/github/stars/Raezil/Thunder)](https://github.com/Raezil/Thunder/stargazers)
[![Issues](https://img.shields.io/github/issues/Raezil/Thunder)](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.md

This 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).