- DefiFundr - A Decentralized Payroll Platform
DefiFundr is a revolutionary decentralized payroll and invoice management system that bridges the gap between traditional financial systems and blockchain technology. The platform provides a seamless, secure, and transparent solution for businesses to manage employee payments, handle freelancer invoices, and automate salary disbursements across both fiat and cryptocurrency channels.
- Automated Payroll Management: Schedule and automate regular salary payments
- Multi-currency Support: Pay in both fiat and cryptocurrency
- Invoice Processing: Create, manage, and process invoices efficiently
- Secure Authentication: PASETO token-based authentication with robust password hashing
- User Management: Comprehensive user account management with KYC verification
- Transaction History: Detailed tracking of all financial transactions
- Smart Contract Integration: Direct interaction with Ethereum-based smart contracts
- API-First Design: RESTful API architecture for seamless integration
DefiFundr implements a Hexagonal Architecture (also known as Ports and Adapters) to achieve:
- Separation of business logic from external concerns
- Improved testability through clear boundaries
- Greater flexibility in replacing components
- Enhanced maintainability with well-defined interfaces
- Core Domain (internal/core): Business rules and entities
- Ports (internal/core/ports): Interface definitions
- Adapters (internal/adapters): Implementation of interfaces
- Infrastructure (infrastructure/): Cross-cutting concerns
defifundr_backend/ βββ cmd/ # Application entry points β βββ api/ # API server β β βββ docs/ # Swagger documentation β β βββ main.go # API server entry point β βββ seed/ # Database seeding βββ config/ # Configuration management βββ db/ # Database related code β βββ migrations/ # SQL migrations β βββ query/ # SQL queries β βββ sqlc/ # Generated Go code βββ docs/ # Project documentation βββ infrastructure/ # Cross-cutting concerns β βββ common/ # Shared utilities β βββ hash/ # Password hashing β βββ middleware/ # HTTP middleware βββ internal/ # Application core code β βββ adapters/ # Ports implementation β βββ core/ # Business logic and domain β βββ domain/ # Domain models β βββ ports/ # Interface definitions β βββ services/ # Business logic βββ pkg/ # Reusable packages βββ scripts/ # Utility scripts βββ test/ # Test suites - Go: Main programming language
- PostgreSQL: Primary database
- Docker: Containerization
- SQLC: Type-safe SQL query generation
- Goose: Database migration management
- Swagger: API documentation
- PASETO: Modern security token framework
- Solidity: Smart contract development
- Go 1.21+
- Docker and Docker Compose
- PostgreSQL 14+
- Make
- Git
-
Clone the repository:
git clone https://github.com/DefiFundr-Labs/defifundr_backend.git cd defifundr_backend -
Install required tools:
make install-tools
-
Set up the development environment:
make docker-up
-
Set up the database:
make postgres make createdb make migrate-up
-
Generate SQL code:
make sqlc
-
Run the server:
make server
Create a .env file in the project root:
DB_SOURCE=postgres://root:secret@localhost:5433/defi?sslmode=disable SERVER_ADDRESS=0.0.0.0:8080 TOKEN_SYMMETRIC_KEY=your-secret-key-at-least-32-bytes-long ACCESS_TOKEN_DURATION=15m REFRESH_TOKEN_DURATION=24h You can run the application in several ways:
# Standard mode make server # Hot reload mode (recommended for development) make air # Using Docker make docker-upRun make help to see a list of all available commands. Key commands include:
# Database commands make postgres # Start PostgreSQL make createdb # Create the database make dropdb # Drop the database # Migration commands make migrate-up # Apply migrations make migrate-down # Revert migrations make migrate-create # Create a new migration # Development commands make sqlc # Generate SQL code make mock # Generate mock code make test # Run tests make lint # Run linter make swagger # Generate Swagger documentation# Create a new migration cd scripts sh create_migration.sh# Apply all pending migrations cd scripts sh migrate_up.sh# Revert the last migration cd scripts sh migrate_down.sh# Reset Migrations cd scripts sh migrate_reset.sh# Migration Status cd scripts sh migrate_status.sh# Run migrations up to the latest version cd scripts sh migrate.shDefiFundr provides comprehensive API documentation using Swagger.
-
Generate the Swagger documentation:
make swagger
-
Access the Swagger UI:
http://localhost:8080/swagger/index.html
The API follows RESTful principles with these main endpoints:
- Authentication:
/v1/auth/*(register, login, refresh, logout) - Users:
/v1/users/*(user management) - Transactions:
/v1/transactions/*(payment operations) - KYC:
/v1/kyc/*(verification processes)
For detailed API specifications, see API_DOCUMENTATION.md.
DefiFundr uses Goose for database migrations and SQLC for type-safe SQL queries.
make migrate-create # When prompted, enter a descriptive name# Apply all pending migrations make migrate-up # Revert the last migration make migrate-down # Check migration status make migrate-statusAfter adding or modifying queries in the db/query/ directory:
make sqlcFor more details, see DATABASE.md.
- Unit Tests: Located alongside the code being tested
- Integration Tests: In the
test/integration/directory - End-to-End Tests: In the
test/e2e/directory
For detailed testing information, see TESTING.md.
We welcome contributions to DefiFundr! Please review our CONTRIBUTING.md for guidelines on how to contribute.
- Create a feature branch from
main - Implement your changes with appropriate tests
- Ensure all tests pass with
make test - Create a pull request following our PR guidelines
This project is licensed under the MIT License - see the LICENSE file for details.
DefiFundr - Revolutionizing Payroll with Blockchain Technology