This guide will help you set up your development environment for contributing to DefiFundr.
Before you begin, make sure you have the following installed:
- Go (version 1.21 or higher)
- Docker and Docker Compose
- Git
- Solidity Compiler (for smart contract development)
- Node.js and npm (for smart contract tools)
-
Clone the repository:
git clone https://github.com/your-org/defifundr.git cd defifundr -
Install required development tools:
make install-tools
This command installs:
air- Live reload for Go applicationsgoose- Database migration toolsqlc- SQL compiler for Gomockgen- Mock generation for testinggolangci-lint- Linting tool for Go
-
Set up environment variables:
cp .env.example .env
Edit the
.envfile to configure your development environment. At minimum, set:DB_SOURCE- Database connection stringJWT_SECRET- Secret key for JWT tokensETHEREUM_RPC_URL- Ethereum node URL
-
Start a PostgreSQL container:
make postgres
-
Create the database:
make createdb
-
Run migrations to set up the schema:
make migrate-up
-
(Optional) Seed the database with test data:
make seed
-
Generate Go bindings for smart contracts:
make gencontract
This compiles the Solidity contracts and generates Go interfaces.
-
Start all required Docker containers:
make docker-up
-
Generate SQL code:
make sqlc
-
Start the API server:
# Option 1: Standard mode make server # Option 2: Hot reload mode (recommended for development) make air
-
Generate API documentation:
make swagger
Access the Swagger UI at http://localhost:8080/swagger/index.html
-
Check that the database is running:
make docker-ps
-
Verify database migrations are applied:
make migrate-status
-
Run tests to ensure everything is working:
make test
Once your environment is set up, follow this workflow for development:
-
Create a feature branch:
git checkout -b feat/your-feature-name
-
Make your changes and write tests.
-
Run linting:
make lint
-
Run tests:
make test -
Generate any updated documentation:
make swagger
-
Commit your changes using conventional commits format.
-
Submit a pull request following the guidelines in CONTRIBUTING.md.
If you encounter database connection errors:
# Check if PostgreSQL container is running
make docker-ps
# View PostgreSQL logs
make dockerlogs
# Restart the PostgreSQL container
make docker-restartIf smart contract generation fails:
- Ensure solc (Solidity Compiler) is correctly installed
- Check contract syntax for errors
- Verify the correct paths in the Makefile
If you encounter Go module issues:
# Clear Go module cache
go clean -modcache
# Update dependencies
go mod tidyIf you need further assistance, refer to:
- Project-specific documentation in the
docsdirectory - Open an issue on GitHub
- Contact the project maintainers