Thank you for your interest in contributing to BlockGuardian! This guide will help you get started.
- Code of Conduct
- Getting Started
- Development Workflow
- Code Style Guidelines
- Testing Requirements
- Pull Request Process
- Documentation
- Community
BlockGuardian is committed to providing a welcoming and inclusive environment for all contributors.
Expected Behavior:
- Be respectful and considerate
- Provide constructive feedback
- Focus on what is best for the community
- Show empathy towards others
Unacceptable Behavior:
- Harassment or discrimination
- Trolling or insulting comments
- Publishing others' private information
- Other unprofessional conduct
- Python 3.9+
- Node.js 16+
- Docker & Docker Compose
- Git
- Code editor (VS Code recommended)
# Fork the repository on GitHub
# Then clone your fork
git clone https://github.com/YOUR_USERNAME/BlockGuardian.git
cd BlockGuardian
# Add upstream remote
git remote add upstream https://github.com/quantsingularity/BlockGuardian.git# Run setup script
./scripts/setup_blockguardian_env.sh
# Verify setup
./scripts/health_check.sh# Update main branch
git checkout main
git pull upstream main
# Create feature branch
git checkout -b feature/your-feature-name
# Or for bug fixes
git checkout -b fix/bug-descriptionBranch Naming Convention:
feature/feature-name- New featuresfix/bug-name- Bug fixesdocs/documentation-update- Documentationrefactor/component-name- Code refactoringtest/test-description- Test additions
Make your changes following our code style guidelines.
# Run all tests
./scripts/run_unified_tests.sh
# Run specific tests
cd code/backend && pytest tests/test_your_feature.py
cd code/blockchain && npx hardhat test
cd web-frontend && npm test# Stage changes
git add .
# Commit with descriptive message
git commit -m "feat: add portfolio rebalancing feature"Commit Message Convention:
Format: <type>: <subject>
Types:
feat: New featurefix: Bug fixdocs: Documentation onlystyle: Code style changes (formatting)refactor: Code refactoringtest: Adding testschore: Build process or auxiliary tools
Examples:
feat: add multi-factor authentication
fix: resolve portfolio calculation error
docs: update API documentation
test: add tests for compliance module
git push origin feature/your-feature-name- Go to your fork on GitHub
- Click "New Pull Request"
- Select your feature branch
- Fill out the PR template
- Submit the PR
Formatter: Black Linter: Flake8 Type Checker: MyPy
# Format code
black code/backend/src/
# Lint code
flake8 code/backend/src/
# Type check
mypy code/backend/src/Style Rules:
- Use 4 spaces for indentation
- Max line length: 88 characters
- Use type hints for function signatures
- Use docstrings for all functions and classes
Example:
def create_portfolio(
user_id: int,
name: str,
risk_tolerance: str
) -> Portfolio:
"""
Create a new investment portfolio.
Args:
user_id: The ID of the portfolio owner
name: Portfolio name
risk_tolerance: Risk level (low, moderate, high)
Returns:
Created Portfolio object
Raises:
ValidationError: If inputs are invalid
"""
# Implementation
passFormatter: Prettier Linter: ESLint
# Format code
npm run format
# Lint code
npm run lint
# Fix auto-fixable issues
npm run lint:fixStyle Rules:
- Use 2 spaces for indentation
- Use single quotes for strings
- Always use semicolons
- Use arrow functions for callbacks
- Use const/let, never var
Example:
// Good
const fetchPortfolios = async (userId) => {
try {
const response = await api.get(`/portfolios?user_id=${userId}`);
return response.data;
} catch (error) {
console.error("Failed to fetch portfolios:", error);
throw error;
}
};Linter: Solhint
# Lint contracts
cd code/blockchain
npm run lint:solStyle Rules:
- Use 4 spaces for indentation
- Max line length: 120 characters
- Use NatSpec comments
- Follow Solidity style guide
Example:
/**
* @notice Create a new portfolio
* @param _name Portfolio name
* @param _description Portfolio description
* @return portfolioId The ID of the created portfolio
*/
function createPortfolio(
string memory _name,
string memory _description
) external returns (uint256 portfolioId) {
// Implementation
}- Backend: Minimum 80% coverage
- Frontend: Minimum 70% coverage
- Smart Contracts: Minimum 90% coverage
Backend Tests (pytest):
def test_create_portfolio(client, auth_token):
"""Test portfolio creation endpoint."""
response = client.post(
'/api/portfolios',
headers={'Authorization': f'Bearer {auth_token}'},
json={
'name': 'Test Portfolio',
'risk_tolerance': 'moderate'
}
)
assert response.status_code == 201
data = response.get_json()
assert data['name'] == 'Test Portfolio'Frontend Tests (Jest + React Testing Library):
test("renders portfolio list", async () => {
render(<PortfolioList />);
await waitFor(() => {
expect(screen.getByText("My Portfolios")).toBeInTheDocument();
});
});Smart Contract Tests (Hardhat):
describe("PortfolioManager", function () {
it("Should create a portfolio", async function () {
const [owner] = await ethers.getSigners();
const tx = await portfolioManager.createPortfolio(
"Test Portfolio",
"Description",
);
await tx.wait();
const portfolios = await portfolioManager.getUserPortfolios(owner.address);
expect(portfolios.length).to.equal(1);
});
});# All tests with coverage
./scripts/run_unified_tests.sh --coverage
# Backend only
cd code/backend
pytest --cov=src --cov-report=html
# Frontend only
cd web-frontend
npm test -- --coverage
# Smart contracts only
cd code/blockchain
npx hardhat test
npx hardhat coverage- Code follows style guidelines
- Tests pass locally
- New tests added for new features
- Documentation updated
- Commit messages follow convention
- Branch is up to date with main
## Description
Brief description of changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## Testing
Describe the tests you ran
## Screenshots (if applicable)
Add screenshots for UI changes
## Checklist
- [ ] Tests pass
- [ ] Code follows style guidelines
- [ ] Documentation updated
- [ ] No breaking changes (or documented)- Automated checks must pass (CI/CD)
- At least one maintainer approval required
- All comments must be resolved
- Branch must be up to date with main
# Update your local main branch
git checkout main
git pull upstream main
# Delete feature branch
git branch -d feature/your-feature-name
git push origin --delete feature/your-feature-name- Adding new features
- Changing existing features
- Fixing significant bugs
- Updating configuration options
- Adding new APIs or endpoints
| Type | Location |
|---|---|
| API Reference | docs/API.md |
| User Guide | docs/USAGE.md |
| Configuration | docs/CONFIGURATION.md |
| Examples | docs/examples/ |
| Code Comments | Inline in source files |
- Use clear, concise language
- Include code examples
- Provide context and use cases
- Keep formatting consistent
- Use tables for structured data
# Create docs branch
git checkout -b docs/update-api-docs
# Make changes to docs/
# Test locally (if applicable)
cd docs && make html
# Commit and push
git add docs/
git commit -m "docs: update API documentation"
git push origin docs/update-api-docs
# Create PR- GitHub Issues: For bug reports and feature requests
- GitHub Discussions: For questions and general discussion
- Documentation: Check docs first
Use the bug report template:
**Describe the bug**
A clear description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior
**Expected behavior**
What you expected to happen
**Screenshots**
If applicable, add screenshots
**Environment**
- OS: [e.g., Ubuntu 20.04]
- Python version: [e.g., 3.9.7]
- Node.js version: [e.g., 18.12.0]
**Additional context**
Add any other contextUse the feature request template:
**Is your feature request related to a problem?**
A clear description of the problem
**Describe the solution you'd like**
A clear description of what you want to happen
**Describe alternatives you've considered**
Other solutions you've considered
**Additional context**
Add any other context or screenshotsContributors will be recognized in:
CONTRIBUTORS.mdfile- Release notes
- Project README
By contributing, you agree that your contributions will be licensed under the MIT License.