Welcome to Brain-Storm! This comprehensive guide takes you from setup to your first contribution.
- Prerequisites
- Initial Setup
- Project Structure Overview
- Development Workflow
- Debugging Tips
- Common Issues & FAQ
- Contribution Guidelines
Ensure you have the following installed:
| Tool | Version | Purpose |
|---|---|---|
| Node.js | v18+ | JavaScript runtime |
| npm | v9+ | Package manager |
| PostgreSQL | v12+ | Database |
| Rust | v1.75+ | Smart contract language |
| Stellar CLI | v21.5.0+ | Blockchain interaction |
| Docker | Latest | Containerization (optional) |
| Git | Latest | Version control |
Verify installations:
node --version
npm --version
psql --version
rustc --version
stellar --versiongit clone https://github.com/BrainTease/Brain-Storm.git
cd Brain-Storm
npm installcp .env.example .env
# Edit .env with your local settingsKey variables for local development:
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=brain_storm_dev
DATABASE_USERNAME=postgres
DATABASE_PASSWORD=your_password
JWT_SECRET=your-secret-key-min-32-chars
STELLAR_NETWORK=testnet
STELLAR_SECRET_KEY=your-testnet-key
NEXT_PUBLIC_API_URL=http://localhost:3000# Create database
createdb brain_storm_dev
# Run migrations
npm run db:migraterustup target add wasm32-unknown-unknownThe project includes a comprehensive seed script that creates realistic demo data for local development. The seed is idempotent — running it multiple times is safe (it cleans up before re-seeding).
cd apps/backend
npx ts-node src/database/seed.tsnpx ts-node src/database/seed.ts --with-reviewsnpx ts-node src/database/seed.ts --with-tipsnpx ts-node src/database/seed.ts --with-reviews --with-tipsnpx ts-node src/database/seed.ts --count=25| Option | Description | Default |
|---|---|---|
--with-reviews |
Include sample course reviews | Not included |
--with-tips |
Include sample BST tip transactions | Not included |
--count=N |
Number of courses/students to generate | 10 |
The seed script is guarded against running in production — it will exit immediately with an error if NODE_ENV=production is detected.
| Entity | Description |
|---|---|
| Admin | 1 admin account (admin@brainstorm.dev) |
| Instructors | Up to 5 instructor profiles with Stellar keys |
| Curators | 3 content curator accounts |
| Students | 20 student profiles (2x count) |
| Courses | 10 courses with realistic titles/descriptions |
| Modules | 3-6 modules per course |
| Lessons | 2-4 lessons per module with markdown content |
| Enrollments | Students enrolled in 1-4 courses each |
| Progress | Random progress records for enrollments |
| Notifications | Enrollment and tip notifications |
| Reviews | (Optional) Student reviews with ratings |
| Tips | (Optional) Sample BST tip transactions |
Terminal 1 - Backend:
npm run dev:backend
# API available at http://localhost:3000
# Swagger docs at http://localhost:3000/api/docsTerminal 2 - Frontend:
npm run dev:frontend
# App available at http://localhost:3001Terminal 3 - Smart Contracts (optional):
cd contracts
cargo build --target wasm32-unknown-unknownbrain-storm/
├── apps/
│ ├── backend/ # NestJS REST API
│ │ ├── src/
│ │ │ ├── auth/ # Authentication & JWT
│ │ │ ├── courses/ # Course management
│ │ │ ├── enrollments/ # Student enrollments
│ │ │ ├── progress/ # Progress tracking
│ │ │ ├── credentials/ # Certificate issuance
│ │ │ ├── stellar/ # Blockchain integration
│ │ │ ├── users/ # User management
│ │ │ ├── common/ # Shared utilities
│ │ │ └── main.ts # App entry point
│ │ ├── tests/ # Unit & integration tests
│ │ └── package.json
│ │
│ └── frontend/ # Next.js 14 App Router
│ ├── src/
│ │ ├── app/ # Route segments
│ │ ├── components/ # React components
│ │ ├── store/ # Zustand state
│ │ ├── lib/ # Utilities & API client
│ │ └── hooks/ # Custom hooks
│ ├── e2e/ # Playwright tests
│ └── package.json
│
├── contracts/ # Soroban smart contracts
│ ├── analytics/ # Progress tracking
│ ├── token/ # Reward tokens
│ ├── shared/ # RBAC & utilities
│ └── Cargo.toml
│
├── docs/ # Documentation
├── scripts/ # Build & deploy scripts
└── package.json # Workspace root
Backend (apps/backend/src/):
auth/— JWT, OAuth, Stellar authenticationcourses/— Course CRUD, modules, lessonsstellar/— Soroban contract calls, Horizon APIcommon/— Guards, pipes, filters, logger
Frontend (apps/frontend/src/):
app/— Next.js pages (App Router)components/ui/— Reusable UI primitivesstore/— Zustand stores for auth, courses, progresslib/— API client, helpers
Contracts (contracts/):
- Each contract is a Rust crate with
src/lib.rs - Tests in
#[cfg(test)]modules - Built to
wasm32-unknown-unknowntarget
git checkout -b feature/your-feature-nameUse conventional commit prefixes: feature/, fix/, docs/, chore/
Backend example:
cd apps/backend
npm run dev # Hot reload enabledFrontend example:
cd apps/frontend
npm run dev # Hot reload enabled# Backend unit tests
npm run test:backend
# Backend integration tests
npm run test:backend:integration
# Frontend tests
npm run test:frontend
# Smart contracts
cd contracts && cargo test# Format code
npm run format
# Lint
npm run lint
# Fix linting issues
npm run lint:fixgit add .
git commit -m "feat: add new feature"
git push -u origin feature/your-feature-nameFollow Conventional Commits.
- Use the PR template in
.github/pull_request_template.md - Link related issues
- Ensure all CI checks pass
- Request review from maintainers
Enable debug logs:
LOG_LEVEL=debugUse NestJS CLI:
npm run dev:backend -- --debugInspect database:
psql -h localhost -U postgres -d brain_storm_devCommon queries:
-- List all users
SELECT id, email, role FROM users;
-- Check enrollments
SELECT * FROM enrollments WHERE user_id = 'user-id';
-- View progress
SELECT * FROM progress WHERE user_id = 'user-id';React DevTools:
- Install React DevTools browser extension
- Inspect component state in Zustand stores
Network inspection:
- Open DevTools → Network tab
- Check API responses and request payloads
Console errors:
# Enable verbose logging
NEXT_PUBLIC_DEBUG=true npm run dev:frontendBuild with debug info:
cd contracts/analytics
cargo build --target wasm32-unknown-unknownRun tests with output:
cargo test -- --nocaptureInspect contract state:
stellar contract invoke \
--id <contract-id> \
--network testnet \
-- get_progress --user <user-id>Symptom: Error: connect ECONNREFUSED 127.0.0.1:5432
Solution:
# Check PostgreSQL is running
psql -h localhost -U postgres -c "SELECT 1"
# If not running, start it
brew services start postgresql # macOS
sudo systemctl start postgresql # LinuxSymptom: Error: listen EADDRINUSE :::3000
Solution:
# Find process using port 3000
lsof -i :3000
# Kill the process
kill -9 <PID>Symptom: Error: Network request failed
Solution:
# Verify testnet is accessible
curl https://horizon-testnet.stellar.org/
# Check your STELLAR_SECRET_KEY is valid
stellar keys listSymptom: error: could not compile 'analytics'
Solution:
# Update Rust
rustup update
# Clean build
cd contracts
cargo clean
cargo build --target wasm32-unknown-unknownSymptom: Inconsistent test results
Solution:
# Clear cache
npm run clean
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
# Run tests again
npm run testQ: How do I add a new API endpoint?
A: Create a new controller in apps/backend/src/, define the route, add guards/pipes, and write tests.
Q: How do I deploy a smart contract?
A: Use ./scripts/deploy.sh testnet <contract-name> for testnet or mainnet.
Q: Where do I find API documentation?
A: Visit http://localhost:3000/api/docs (Swagger UI) when the backend is running.
Q: How do I reset the database?
A: Run npm run db:reset (drops and recreates schema).
Q: Can I use Docker for development?
A: Yes, use docker compose up -d to start PostgreSQL, Redis, and backend.
- TypeScript: Use strict mode, avoid
anytypes - Naming: camelCase for variables/functions, PascalCase for classes/types
- Comments: Document complex logic, not obvious code
- Imports: Organize by external, internal, relative
- Unit tests for business logic (minimum 80% coverage)
- Integration tests for API endpoints
- E2E tests for critical user flows
- Smart contract tests for all public functions
- Tests pass locally (
npm run test) - Code formatted (
npm run format) - No linting errors (
npm run lint) - Commit messages follow conventions
- PR description explains changes
- Related issues linked
- No breaking changes (or documented)
- Automated checks (CI/CD)
- Code review (maintainers)
- Approval & merge
- Deployment (if applicable)
- Questions: Open a discussion in GitHub Discussions
- Bugs: File an issue with reproduction steps
- Security: Email security@brainstorm.dev (do not open public issues)
- Chat: Join our Discord community
- Set up your development environment (follow Initial Setup)
- Read the Architecture Overview
- Pick a good first issue
- Make your first contribution!
Welcome to the team! 🚀