GrainBee is a comprehensive blockchain-based solution designed to manage and track the distribution of rations. The project leverages Hyperledger Fabric to ensure secure, transparent, and efficient ration management. Key components include a robust backend implemented in Go, a user-friendly frontend client app, and a set of APIs for interaction.
- Hyperledger Fabric: The core blockchain platform used for building the chaincode.
- Chaincode (CC) Tools: Utilities and libraries for developing and managing chaincode.
- Docker: Containerization technology for consistent development and deployment environments.
- Go Programming Language: The primary language used for backend development.
- Industry Best Practices and Optimizations: Implementation of best practices for performance and security.
- Version Control System (VCS) Usage: Git for version control and collaboration.
- Unit Testing Implementation: Comprehensive unit tests to ensure code reliability.
- Concurrent Programming with Go Routines and Channels: Efficient handling of concurrent operations.
- API Management System: Tools and practices for managing and documenting APIs.
The GrainBee system is built on a modular architecture that includes:
- Backend: Implemented in Go, the backend handles all blockchain interactions and business logic.
- Frontend: A client application that interacts with the backend via APIs to provide a user-friendly interface.
- API: A set of RESTful APIs that facilitate communication between the frontend and backend.
The components interact as follows:
- The frontend sends requests to the backend via the API.
- The backend processes these requests, interacts with the Hyperledger Fabric network, and returns responses to the frontend.
- Ration Management: Create, update, and delete rations.
- Member Management: Issue and update ration cards for members.
- Inventory Management: Replenish and track inventory levels.
- Distribution Point Management: Create and manage distribution points.
- Pickup Schedule Management: Set and retrieve pickup schedules.
- Concurrent Updates: Efficient handling of concurrent updates using Go routines and channels.
- Git
- cURL
- Go (version 1.16 or later)
- Docker
- Docker Compose
- Hyperledger Fabric (version 2.x)
-
Clone the Repository
git clone https://github.com/JonyBepary/Grainbee_Blockchain.git cd grainbee
-
Install Dependencies
go mod tidy
-
Download Fabric Binaries
If you don't have the Fabric binaries, download them:
curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh && chmod +x install-fabric.sh ./install-fabric.sh --fabric-version 2.5.3 binary rm install-fabric.sh
-
Package Chaincode
Package the chaincode using the following command:
peer lifecycle chaincode package grainbee.tar.gz --path ../chaincode --lang golang --label grainbee_0.1
-
Install Chaincode
Install the chaincode on the peer:
peer lifecycle chaincode install grainbee.tar.gz
-
Bring Up the Network
Start the Fabric network with the desired number of organizations (e.g., 3 organizations):
./network.sh up createChannel -n 3
-
** Package and Deploy Chaincode**
Deploy the chaincode to the network by following this tutorial.
-
To deploy this chaincode in Amazon Managed Blockchain
Follow the documentation in this link to create a network in Amazon Managed Blockchain and deploy chain code.
-
Start the Hyperledger Fabric Network
./startDev.sh -n 1
-
Run the Backend Server
go run main.go
-
Access the Frontend
- Open the frontend client app (access through http://localhost:3000).
-
Create a New Ration
curl -X POST http://localhost:8080/api/createRation -d '{"id": "ration1", "category": "rice", "description": "10kg rice", "package": "bag", "distributedBy": "dist1", "quantity": 10, "expiryDate": "2023-12-31", "mfgDate": "2023-01-01", "batchNumber": 1}'
-
Update Member Information
curl -X PUT http://localhost:8080/api/updateMemberInfo -d '{"nid": "12345", "name": "John Doe", "dateOfBirth": "1990-01-01", "height": 170, "address": "123 Main St", "contactInformation": "john@example.com", "familySize": 4, "income": 50000, "disabilityStatus": false, "rationCardNumber": "RC1234", "rationCardStatus": "active", "rationCardIssuedDate": "2023-01-01", "rationCardExpiryDate": "2023-12-31", "rationCardCategory": "general"}'
The GrainBee API provides endpoints for managing rations, members, inventory, distribution points, and pickup schedules.
- API Key: Include the API key in the
Authorization
header of your requests.
- Create Ration:
POST /api/createRation
- Update Member Info:
PUT /api/updateMemberInfo
- Replenish Inventory:
POST /api/replenishInventory
- Set Pickup Schedule:
POST /api/setPickupSchedule
- Get Pickup Schedule:
GET /api/getPickupSchedule
-
Navigate to the Project Directory
cd grainbee
-
Run the Tests
go test ./...
- Mock Tests: Utilize mock stubs to simulate blockchain interactions.
- Integration Tests: Ensure that the backend and frontend components interact correctly.
- Follow the existing code style and conventions.
- Write clear and concise commit messages.
- Include unit tests for new features and bug fixes.
-
Fork the Repository A fork is a new repository that shares code and visibility settings with the original “upstream” repository. follow this link to fork the repository.
-
Create a New Branch
git checkout -b feature/new-feature
-
Make Your Changes
- Implement the new feature or bug fix.
- Write unit tests for the new code.
- Update the documentation as needed.
-
Commit Your Changes
git commit -m "Add new feature"
-
Push Your Changes
git push origin feature/new-feature
-
Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.