Skip to content

Repository files navigation

Bluebricks Blueprint Service

This service provides a REST API for managing blueprints, along with a Go CLI tool for easy interaction.

A NestJS service for managing Bluebricks Blueprints. This service provides a RESTful API for storing, retrieving, updating, and deleting Blueprints in a PostgreSQL database.

Features

  • CRUD operations for Blueprints
  • PostgreSQL database storage
  • Input validation
  • Swagger API documentation
  • TypeScript support

Prerequisites

  • Node.js (v22+)
  • Docker and Docker Compose
  • npm

Database Setup

  1. Start the PostgreSQL database using Docker:
docker-compose up -d

This will start a PostgreSQL instance with the following configuration:

  • Host: localhost
  • Port: 5432
  • Database: bluebricks
  • Username: postgres
  • Password: postgres

To stop the database:

docker-compose down

To stop the database and remove all data:

docker-compose down -v

CLI Tool

A Go CLI tool is provided in the cli directory for interacting with the Blueprint service.

Prerequisites

  1. Install Go (1.20 or later)
    • Visit https://golang.org/dl/
    • Download and install Go for your operating system
    • Verify installation: go version

Building the CLI

cd cli
go build -o blueprint-cli

Using the CLI

The CLI supports the following commands:

  1. Create a Blueprint:
./blueprint-cli create --file blueprint.json
  1. Get a Blueprint by ID:
./blueprint-cli get --id <blueprint-id>
  1. List all Blueprints:
./blueprint-cli list
  1. Update a Blueprint:
./blueprint-cli update --id <blueprint-id> --file updated-blueprint.json
  1. Delete a Blueprint:
./blueprint-cli delete --id <blueprint-id>

Example JSON Format

When creating or updating a blueprint, use a JSON file with the following structure:

{
  "name": "Sample Blueprint",
  "description": "A sample blueprint",
  "content": "Blueprint content goes here",
  "version": "1.0.0"
}

An example file is provided at cli/example.json.

Installation

  1. Install dependencies:
npm ci
  1. Configure environment variables:
# Create .env file
cat > .env << EOL
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_DATABASE=bluebricks
PORT=3000
EOL

Running the Application

# Development mode
npm run start:dev

# Production mode
npm run build
npm run start:prod

The service will be available at http://localhost:3000 Swagger documentation will be available at http://localhost:3000/api

API Endpoints

Create Blueprint

POST /blueprints

curl -X POST http://localhost:3000/blueprints \
  -H "Content-Type: application/json" \
  -d @bricks.json

Get Blueprint

GET /blueprints/:id

curl http://localhost:3000/blueprints/123e4567-e89b-12d3-a456-426614174000

List Blueprints

GET /blueprints

# List all
curl http://localhost:3000/blueprints

# Filter by version
curl http://localhost:3000/blueprints?version=1.1.0

# Filter by author
curl http://localhost:3000/blueprints?author=pini@bluebricks.co

Update Blueprint

PUT /blueprints/:id

curl -X PUT http://localhost:3000/blueprints/123e4567-e89b-12d3-a456-426614174000 \
  -H "Content-Type: application/json" \
  -d @bricks.json

Delete Blueprint

DELETE /blueprints/:id

curl -X DELETE http://localhost:3000/blueprints/123e4567-e89b-12d3-a456-426614174000

Running Tests

# Unit tests
npm run test

# E2E tests
npm run test:e2e

# Test coverage
npm run test:cov

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages