This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Brebaje is a zero-knowledge proof ceremony management platform built with a NestJS backend and Next.js frontend. The project manages trusted setup ceremonies for zkSNARK circuits, handling user authentication, ceremony coordination, and participant contributions.
This is a monorepo using pnpm workspaces with three main applications:
- Backend (
apps/backend/): NestJS API with SQLite database using Sequelize ORM - Frontend (
apps/frontend/): Next.js application with TailwindCSS and React Query - CLI (
apps/cli/): Command-line interface for complete ceremony management using Commander.js
The system revolves around zero-knowledge proof ceremonies:
- Users: Authenticated via GitHub OAuth, stored with provider info
- Projects: Container for related ceremonies, managed by coordinators
- Ceremonies: Time-bounded events with phases (SCHEDULED → OPENED → CLOSED → FINALIZED)
- Circuits: Individual zkSNARK circuits within ceremonies requiring trusted setup
- Participants: Users enrolled in ceremonies with contribution tracking
- Contributions: Cryptographic contributions to circuit trusted setup
The database schema is defined in apps/backend/src/database/diagram.dbml and automatically generates:
- TypeScript enums (
src/types/enums.ts) - Sequelize models
- Database migration SQL
Uses GitHub device flow OAuth:
- Frontend gets GitHub client ID from backend
- User completes GitHub OAuth device flow
- Backend exchanges token for user info, creates/finds user record
- JWT token issued for session management
The CLI provides complete command-line access to Brebaje functionality including authentication, user management, projects, ceremonies, and contributions. It communicates with the backend via HTTP API calls and handles GitHub OAuth authentication.
apps/cli/
├── src/
│ ├── index.ts # Entry point with Commander.js
│ ├── utils/
│ │ └── logger.ts # ScriptLogger for consistent logging
│ ├── auth/
│ │ ├── index.ts # setUpAuthCommands()
│ │ └── github.ts # GitHub OAuth implementation
│ ├── ceremonies/
│ │ ├── index.ts # setUpCeremonyCommands()
│ │ ├── list.ts # List ceremonies
│ │ ├── create.ts # Create ceremonies (coordinators)
│ │ ├── contribute.ts # Contribute to ceremonies
│ │ └── finalize.ts # Finalize ceremonies (coordinators)
│ ├── participants/
│ │ ├── index.ts # setUpParticipantCommands()
│ │ └── list.ts # List participants
│ ├── perpetual-powers-of-tau/
│ │ ├── index.ts # setUpPerpetualPowersOfTauCommands()
│ │ ├── auto-contribute.ts # Automated contribution flow
│ │ ├── beacon.ts # Beacon randomness generation
│ │ ├── contribute.ts # Manual contribution
│ │ ├── download.ts # Download challenge files
│ │ ├── generate-download-url.ts # Generate download URLs
│ │ ├── generate-upload-url.ts # Generate upload URLs
│ │ ├── generate-urls.ts # Generate both URLs
│ │ ├── new.ts # Start new ceremony
│ │ ├── post-record.ts # Post contribution records
│ │ ├── upload.ts # Upload contribution files
│ │ └── verify.ts # Verify contributions
│ └── setup/
│ ├── index.ts # setUpSetupCommands()
│ └── token.ts # GitHub token configuration
├── build/ # Compiled JavaScript
├── images/ # Documentation images
├── output/ # Generated ceremony files
├── package.json # Dependencies (Commander.js)
└── tsconfig.json # TypeScript ES modules config
brebaje-cli auth login # GitHub OAuth device flow
brebaje-cli auth logout # Clear stored authentication
brebaje-cli auth status # Check if logged in
brebaje-cli auth whoami # Show current user infobrebaje-cli user profile # Show user profile details
brebaje-cli user ceremonies # List user's ceremonies
brebaje-cli user contributions # List user's contributionsbrebaje-cli projects list # List all projects
brebaje-cli projects create [options] # Create new project
brebaje-cli projects show <id> # Show project detailsbrebaje-cli ceremonies list # List all ceremonies
brebaje-cli ceremonies show <id> # Show ceremony details
brebaje-cli ceremonies create [options] # Create ceremony (coordinators)
brebaje-cli ceremonies contribute <id> # Contribute to ceremony
brebaje-cli ceremonies finalize <id> # Finalize ceremony (coordinators)brebaje-cli participants list <ceremony-id> # List ceremony participants
brebaje-cli participants add <ceremony-id> <user-id> # Add participantbrebaje-cli contributions list [ceremony-id] # List contributions
brebaje-cli contributions verify <id> # Verify contributionbrebaje-cli setup gh-token <github_classic_token> # Configure GitHub token for contribution records# Basic ceremony operations
brebaje-cli ppot new # Initialize new ceremony
brebaje-cli ppot download <url> # Download challenge file from URL
brebaje-cli ppot contribute # Make contribution manually
brebaje-cli ppot upload <uploadUrl> # Upload contribution file
brebaje-cli ppot verify <ptauFile> # Verify Powers of Tau file
brebaje-cli ppot post-record [-t <token>] # Post contribution record to GitHub Gist
# Automated contribution flow
brebaje-cli ppot auto-contribute [jsonPath] # Complete flow: download → contribute → upload → post-record
# Coordinator tools
brebaje-cli ppot generate-upload-url <filename> [-e <minutes>] # Generate upload URL
brebaje-cli ppot generate-download-url <filename> [-e <minutes>] # Generate download URL
brebaje-cli ppot generate-urls <downloadFilename> [options] # Generate both URLs with JSON output
brebaje-cli ppot beacon <inputFile> <beacon> <iterations> <name> # Apply beacon to finalize ceremonycd apps/cli
# Install dependencies
pnpm install
# Build the CLI
pnpm build
# Test locally (without global install)
node ./build/index.js --help
node ./build/index.js auth status
node ./build/index.js ceremonies list
# Install globally for system-wide access
pnpm link --global
brebaje-cli --helpThe CLI implements GitHub OAuth device flow:
brebaje-cli auth loginstarts device flow- User visits GitHub URL and enters device code
- CLI polls for authorization completion
- JWT token stored locally for subsequent commands
- All API calls include
Authorization: Bearer <token>header
Each command uses ScriptLogger for consistent output:
import { ScriptLogger } from "../utils/logger.js";
const logger = new ScriptLogger("CLI:CommandName");
// Available log types:
logger.log("Info message");
logger.success("Success message ✅");
logger.error("Error message", error);
logger.warn("Warning message");
logger.failure("Failure message ❌");Output format:
[2025-09-23T00:06:42.675Z] [CLI:Auth] Starting GitHub OAuth flow...
[2025-09-23T00:06:42.677Z] [CLI:Auth] ✅ Authentication successful!
TypeScript (ES Modules):
{
"compilerOptions": {
"module": "ES2022",
"moduleResolution": "node",
"target": "ES2022",
"outDir": "./build",
"rootDir": "./src"
}
}Package.json:
{
"type": "module",
"bin": {
"brebaje-cli": "./build/index.js"
},
"dependencies": {
"commander": "^11.0.0",
"dotenv": "^16.0.0"
}
}# .env file in apps/cli/
BREBAJE_API_URL=http://localhost:8067
BREBAJE_AUTH_TOKEN_PATH=~/.brebaje/token# Install dependencies
pnpm install
# Run linting across all packages
pnpm lint
# Run tests across all packages
pnpm test
# Format code across all packages
pnpm prettier:fixcd apps/backend
# Start development server with hot reload
pnpm start:dev
# Build the application
pnpm build
# Run tests
pnpm test
# Run tests with coverage
pnpm test:cov
# Run E2E tests
pnpm test:e2e
# Lint TypeScript files
pnpm lint
# Database schema operations
pnpm convert # Convert DBML to SQL
pnpm setup-dml-to-database # Generate models from schemacd apps/frontend
# Start development server
pnpm dev
# Build for production
pnpm build
# Start production server
pnpm start
# Lint code
pnpm lint
# Format code
pnpm format- Database Changes: Update
apps/backend/src/database/diagram.dbmlthen runpnpm convertandpnpm setup-dml-to-database - API Development: Follow NestJS module pattern - create controller, service, DTOs, and tests
- Frontend Features: Use React Query hooks for API calls, TailwindCSS for styling
- Testing: Write unit tests alongside new features, run E2E tests for critical flows
- NestJS: Main framework with decorators and dependency injection
- Sequelize: ORM with TypeScript support via sequelize-typescript
- JWT: Authentication tokens via @nestjs/jwt
- SQLite: Development database (sqlite3)
- Next.js 14: React framework with app router
- TanStack Query: Server state management and caching
- TailwindCSS: Utility-first CSS framework
- Lucide React: Icon library
- Backend follows standard NestJS module structure with feature-based organization
- Frontend uses Next.js app router with components organized by feature
- CLI uses modular command structure with Commander.js and TypeScript ES modules
- Database models are auto-generated from DBML schema
- Shared types are centralized in
apps/backend/src/types/ - API routes follow RESTful conventions with OpenAPI documentation
- CLI basic structure implemented with ceremonies and participants commands
- Logger system with consistent formatting (
ScriptLogger) - TypeScript compilation with ES modules
- Global installation capability via
pnpm link --global - Auth command structure with GitHub OAuth implementation
- Perpetual Powers of Tau full implementation with 12 commands:
- Complete ceremony workflow (new, download, contribute, upload, verify, post-record)
- Automated contribution flow (
auto-contribute) - Coordinator tools (generate URLs, beacon application)
- Social media integration (Twitter/X sharing)
- Setup commands for GitHub token configuration
- File organization with proper module separation
- Documentation images and output directories
- Implement auth commands (login, logout, status, whoami)
- Implement user commands (profile, ceremonies, contributions)
- Implement projects commands (list, create, show)
- Expand ceremonies commands (show, better create/finalize)
- Implement contributions commands (list, verify)
- dotenv dependency to package.json
- Create comprehensive API client (
src/utils/api.ts) - Implement authentication token management (
src/utils/auth.ts) - Configure environment variables for backend URL
- Implement GitHub OAuth device flow in CLI
- Add secure token storage (file-based)
- Implement automatic token refresh
- Add authentication middleware for protected commands
- Connect backend integration commands to their respective endpoints
- Implement proper error handling for network requests
- Add request/response validation
- Handle authentication errors gracefully
- Test complete authentication flow with backend
- Test all backend integration commands with running backend (port 8067)
- Validate data persistence in SQLite database
- Add comprehensive command-line argument validation
- Add interactive command modes
- Implement ceremony status monitoring
- Add batch operation capabilities
- Create ceremony template system
Authentication:
POST /auth/github- GitHub OAuth authenticationGET /auth/me- Get current user info
Users:
GET /users/profile- User profileGET /users/ceremonies- User's ceremoniesGET /users/contributions- User's contributions
Projects:
GET /projects- List projectsPOST /projects- Create projectGET /projects/:id- Project details
Ceremonies:
GET /ceremonies- List ceremoniesPOST /ceremonies- Create ceremonyGET /ceremonies/:id- Ceremony detailsPATCH /ceremonies/:id- Update ceremonyDELETE /ceremonies/:id- Delete ceremony
Participants:
GET /ceremonies/:id/participants- List participantsPOST /ceremonies/:id/participants- Add participant
Contributions:
GET /contributions- List contributionsPOST /contributions- Create contributionGET /contributions/:id/verify- Verify contribution
# Start backend
cd apps/backend && pnpm start:dev
# Authentication flow
brebaje-cli auth login # Complete GitHub OAuth
brebaje-cli auth whoami # Verify login
# Project management
brebaje-cli projects create --name "My ZK Project"
brebaje-cli projects list
# Ceremony management
brebaje-cli ceremonies create --project-id 1 --name "Test Ceremony"
brebaje-cli ceremonies list
brebaje-cli ceremonies contribute 1 --entropy "my-secret"
# User activities
brebaje-cli user ceremonies
brebaje-cli user contributions- GitHub tokens stored in plain text files without encryption
- No secure credential management system
- Risk: Token exposure in filesystem, logs, or process memory
- Inconsistent error handling across commands
- Network operations lack proper timeout/retry logic
- File operations missing validation and cleanup
- No proper cleanup of temporary files
- Large file operations could exhaust disk space
- Missing file lock mechanisms for concurrent operations
- Hardcoded default values scattered across files
- No centralized configuration validation
- Missing environment variable documentation
- No upload progress tracking for large files
- Missing retry logic for failed uploads
- No validation of pre-signed URL expiration
- Secure token storage using OS keychain/credential manager
- Comprehensive error handling with retry logic and user-friendly messages
- File cleanup mechanisms and disk space checks
- Upload progress tracking and resume capability
- Configuration validation and centralized env management
- Command input validation and sanitization
- Concurrent operation safety with file locking
- Better logging with different verbosity levels
- Health checks for external dependencies (snarkjs, network)
- Interactive prompts for better UX
- Command aliases and shortcuts
- Configuration wizard for first-time setup