BAPBA Protocol
Contributing

Development Setup

Set up a local development environment for Burning Ash Protocol.

Development Setup

This guide covers setting up a local development environment for BAP.

Prerequisites

ToolVersionPurpose
Go1.21+Backend development
Node.js18+Frontend development
Docker24.0+Containerization
Git2.0+Version control
PostgreSQL (opt)17+Production testing

Repository Setup

Clone

git clone https://github.com/baprotocol/bap.git
cd bap

Structure

bap/
├── api/                  # Go backend
│   ├── cmd/api/          # Entry point
│   ├── internal/         # Packages
│   └── migrations/       # DB migrations
├── web/                  # Next.js frontend
│   ├── src/
│   └── ...
├── docs/                 # Documentation
├── docker-compose.yml    # Orchestration
└── .env.example          # Env template

Backend Setup

Go Installation

# Install Go (Linux/macOS)
curl -sL https://go.dev/dl/go1.21.linux-amd64.tar.gz | sudo tar -C /usr/local -xz

# Verify
go version

Dependencies

cd api
go mod download

Database

SQLite (Default)

# Create data directory
mkdir -p data

# Database created automatically

PostgreSQL (Optional)

# Using Docker
docker run -d \
  --name bap-postgres \
  -e POSTGRES_DB=bap \
  -e POSTGRES_USER=bap \
  -e POSTGRES_PASSWORD=dev \
  -p 5432:5432 \
  postgres:17-alpine

# Set environment
export DATABASE_URL=postgresql://bap:dev@localhost:5432/bap?sslmode=disable

Configuration

# Copy environment template
cp .env.example .env

# Edit .env
JWT_SECRET=development-secret-at-least-32-characters-long
MASTER_KEY=$(openssl rand -hex 32)
DB_TYPE=sqlite
DATABASE_PATH=./data/bap.db

Run Backend

cd api
go run ./cmd/api

API runs at http://localhost:8080

Frontend Setup

Node.js

# Using nvm (recommended)
nvm install 18
nvm use 18

# Verify
node --version

Dependencies

cd web
npm install

Configuration

# Create .env.local
NEXT_PUBLIC_API_URL=http://localhost:8080/api

Run Frontend

# Development
npm run dev

# Production build
npm run build
npm start

Frontend runs at http://localhost:3000

Docker Development

Quick Start

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop
docker-compose down

Hot Reload

Backend and frontend support hot reload:

  • Backend: go run watches for changes
  • Frontend: Next.js dev server

Database Tools

Migration

# Run migrations
cd api
go run ./cmd/api migrate

# Create new migration
go run ./cmd/api migrate create add_new_table

CLI

# SQLite CLI
sqlite3 data/bap.db

# PostgreSQL CLI
docker exec -it bap-postgres-1 psql -U bap -d bap

Testing

Backend Tests

cd api
go test ./...

Frontend Tests

cd web
npm test

Integration Tests

# Using Docker
docker-compose -f docker-compose.test.yml up

Code Quality

Linting

# Go
cd api
go fmt ./...
go vet ./...

# Frontend
cd web
npm run lint

Pre-commit Hooks

# Install pre-commit
pip install pre-commit

# Enable
cd api
pre-commit install

Common Issues

Port Already in Use

# Find process
lsof -i :8080

# Kill
kill <PID>

Database Locked

# Remove SQLite journal
rm data/bap.db-journal

Module Errors

# Clean and re-download
cd api
go clean -modcache
go mod download

Next Steps

On this page