Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the README.md and Enhanced Integration Tests #51

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# Build and up targets for all profiles in development environment
dev-all: dev-all dev-up-all

integration-test: ### Run docker-compose with integration test
bash ./integration-test.sh
dev-up-all:
docker-compose -f dev.docker-compose.yml --profile all build
docker-compose -f dev.docker-compose.yml --profile all up -d

.PHONY: integration-test
dev-up-starlabs:
docker-compose -f dev.docker-compose.yml --profile starlabs build
docker-compose -f dev.docker-compose.yml --profile starlabs up -d

dev-up-tests:
@echo "Building containers for tests..."
@docker-compose -f dev.docker-compose.yml --profile tests build > /dev/null 2>&1 || (echo "Container build failed!" && exit 1)
@echo "Starting containers for tests..."
@docker-compose -f dev.docker-compose.yml --profile tests up -d > /dev/null 2>&1 || (echo "Starting containers failed!" && exit 1)
@echo "Starting the integration test..."
@docker-compose -f dev.docker-compose.yml logs -f integration
@echo "Removing containers..."
@docker-compose -f dev.docker-compose.yml down --remove-orphans > /dev/null 2>&1


dev-up-kafka:
docker-compose -f dev.docker-compose.yml --profile kafka build
docker-compose -f dev.docker-compose.yml --profile kafka up -d

dev-up-backend:
docker-compose -f dev.docker-compose.yml --profile backend build
docker-compose -f dev.docker-compose.yml --profile backend up -d

dev-up-frontend:
docker-compose -f dev.docker-compose.yml --profile frontend build
docker-compose -f dev.docker-compose.yml --profile frontend up -d

dev-stop:
docker-compose -f dev.docker-compose.yml down --remove-orphans

dev-destroy:
docker-compose -f dev.docker-compose.yml down -v --remove-orphans

.PHONY: dev-all dev-up-all dev-up-starlabs dev-up-tests dev-up-kafka dev-up-backend dev-up-frontend dev-stop dev-destroy
122 changes: 121 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,121 @@
# token-factory-v2
# Cheesecake Stellar Token Factory - V2

Cheesecake Stellar Token Factory - V2 is a multifaceted system, designed to enable the creation, management of Stellar-based tokens.
The version 2 architecture leverages a blend of cutting-edge technologies to offer a scalable, secure, and user-friendly solution.

## Components

- **Postgres:** Utilized as the primary relational database for all structured data management needs.
- **Apache Kafka:** Deployed as a distributed event store to enable real-time data processing and insights.
- **UI for Apache Kafka:** An intuitive open-source web UI that provides detailed monitoring and management functions for Apache Kafka clusters.
- **Frontend:** A sleek and interactive React Web application offering a front-facing user interface.
- **Backend:** A Golang backend handling the business logic, encompassing everything from API endpoints to core Stellar token functionalities.
- **Starlabs:** A specialized Stellar service, integrated as a git submodule and written in Go, to further enrich the platform's capabilities.
wjuniorbh92 marked this conversation as resolved.
Show resolved Hide resolved
- **KMS:** The CKL Key Management Service (KMS), also a git submodule in Go, safeguarding the security of cryptographic keys and other sensitive data.

### Topics

Further details on the various functionalities, system requirements, and guides to set up and use the Cheesecake Stellar Token Factory - V2 can be found in the following sections:

- [Development Environment with Makefile](#development-environment-with-makefile)
- [API Documentation](#api-documentation)
- [Kafka Topics & Communication Flows](#kafka-topics--communication-flows)

## Development Environment with Makefile

The Makefile included in the project simplifies the development environment management using Docker Compose, providing a collection of easy-to-use commands tailored for the Cheesecake Stellar Token Factory - V2 development workflow.

### Build and Start All Services

```bash
make dev-up-all
```

### Build and Start Individual Services

You can build and start individual services by appending the service name to `make dev-up-starlabs`. For example:

- Starlabs: `make dev-up-starlabs`
- Tests: `make dev-up-tests`
- Kafka: `make dev-up-kafka`
- Backend: `make dev-up-backend`
- Frontend: `make dev-up-frontend`

### Stop All Services (Development Backend)

```bash
make dev-stop
```

### Stop and Remove Volumes (Development Backend)

**Warning**: This command will delete all data in your development environment.

```bash
make dev-destroy
```

These commands streamline the process of building, starting, and managing the development environment, allowing developers to concentrate on coding. Customize the `dev.docker-compose.yml` file to adapt the configuration of the Docker containers to your specific requirements.

### **API Documentation**

The backend is equipped with Swagger documentation to provide an interactive interface for understanding and testing the API endpoints.

#### Accessing the Swagger UI:

You can access the Swagger interface by navigating to:

[http://localhost:8080/v1/swagger/index.html](http://localhost:8080/v1/swagger/index.html)

Here, you'll find detailed information about each API route, including required parameters, request/response formats, and the ability to test the endpoints directly from the browser.
The Kafka Topics section you've provided gives a detailed flow between various components using Kafka topics. However, to make it more structured and improve readability, you can consider the following improvements:
wjuniorbh92 marked this conversation as resolved.
Show resolved Hide resolved

### **Kafka Topics & Communication Flows**

Apache Kafka is instrumental in "Cheesecake Stellar Token Factory - V2" for facilitating asynchronous data processing and streamlining communication between various components. The following elucidates the primary Kafka topics and the flow of communication between associated services:

#### **Backend to Stellar KMS**:

- **`generateKeypair`**:
- **Purpose**: Handles requests to generate a new Stellar key pair.
- **Usage**: Whenever a component or service needs a new key pair, a message is produced to this topic.

#### **Stellar KMS to Backend**:

- **`generatedKeypairs`**:
- **Purpose**: Announces the generation of a new key pair.
- **Usage**: Once a key pair is produced, it's dispatched to this topic allowing subscribers to process new key pairs for secure storage or any subsequent activities.
wjuniorbh92 marked this conversation as resolved.
Show resolved Hide resolved

#### **Starlabs to KMS**:

- **`signEnvelope`**:
- **Purpose**: Manages signing requests for transaction envelopes.
- **Usage**: It receives the unsigned transaction envelope with the pertinent details needed for the signing process.

#### **KMS to Starlabs**:

- **`signedEnvelopes`**:
- **Purpose**: Communicates the status of a successfully signed transaction envelope.
wjuniorbh92 marked this conversation as resolved.
Show resolved Hide resolved
- **Usage**: Services, particularly those monitoring or processing signed envelopes, subscribe to this topic.

#### **Backend to Starlabs**:

- **`createEnvelope`**:
wjuniorbh92 marked this conversation as resolved.
Show resolved Hide resolved

- **Purpose**: Deals with transaction envelope creation requests.
- **Usage**: This topic may contain specific transaction details like payment operations, account merges, or asset issuances.
wjuniorbh92 marked this conversation as resolved.
Show resolved Hide resolved

- **`horizonRequest`**:
- **Purpose**: Manages any request destined for the Stellar Horizon server.
wjuniorbh92 marked this conversation as resolved.
Show resolved Hide resolved
- **Usage**: Typical requests include fetching account details or initiating transactions.
wjuniorbh92 marked this conversation as resolved.
Show resolved Hide resolved

#### **Starlabs to Backend**:

- **`horizonResponse`**:

- **Purpose**: Conveys responses from the Stellar Horizon server.
- **Usage**: It relays data from fetched accounts, transaction submission outcomes, and all other responses from Horizon.
wjuniorbh92 marked this conversation as resolved.
Show resolved Hide resolved

- **`submitResponse`**:
- **Purpose**: Reports the outcome of transactions submitted to the Stellar network.
- **Usage**: After submitting a transaction to the Stellar network, this topic communicates the result, be it a success or a failure.
39 changes: 23 additions & 16 deletions backend/integration-test/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,57 +1,64 @@
package integration_test

import (
"fmt"
"log"
"net/http"
"os"
"testing"
"time"

. "github.com/Eun/go-hit"
)

type errrorResponse struct {
Message string `json:"message"`
Error string `json:"error,omitempty"`
}

const (
// Attempts connection
host = "backend:8080"
host = "localhost:8080"
healthPath = "http://" + host + "/healthz"
attempts = 20

// HTTP REST
basePath = "http://" + host + "/v1"

// Kafka
kafkaHost = "kafka:9092"
consumerTopic = "consumer_topic"
producerTopic = "producer_topic"
)

func TestMain(t *testing.M) {
func TestMain(m *testing.M) {
err := healthCheck(attempts)
if err != nil {
log.Fatalf("Integration tests: host %s is not available: %s", host, err)
}

log.Printf("Integration tests: host %s is available", host)

code := t.Run()
code := m.Run()
os.Exit(code)
}

func healthCheck(attempts int) error {
var err error
client := &http.Client{}

for attempts > 0 {
err = Do(Get(healthPath), Expect().Status().Equal(http.StatusOK))
if err == nil {
req, err := http.NewRequest(http.MethodGet, healthPath, nil)
if err != nil {
return err
}

resp, err := client.Do(req)
if err == nil && resp.StatusCode == http.StatusOK {
return nil
}

log.Printf("Integration tests: url %s is not available, attempts left: %d", healthPath, attempts)
if err != nil {
log.Printf("Integration tests: error connecting to %s: %s", healthPath, err)
} else {
log.Printf("Integration tests: url %s returned status %d, attempts left: %d", healthPath, resp.StatusCode, attempts)
}

time.Sleep(time.Second)

attempts--
}

return err
return fmt.Errorf("Integration tests: failed to connect to %s after %d attempts", healthPath, attempts)
}
Loading