The Australian Agricultural Traceability Protocol (AATP) is a system developed to interact with ACA-PY compatible agents for agricultural traceability. This documentation covers the main components of the AATP system, including the API server, command-line interface, and user interface.
- AATP-Based Agri Passport Design
- Creating and managing schemas
- Creating and querying credential definitions
- Issuing credentials
- Managing connections and invitations
- Sending and querying messages
- Tracing agricultural products through ACA-PY compatible agents
server.py
: Functions for checking the status of the service.aatp-cli.py
: Backend API for interacting with ACA-PY agents.aatp-ui.py
: Flask-based HTTP server containing frontend API.config.py
: Configuration file with API URL and authentication token.connections.py
: Functions for managing connections and invitations.credential.py
: Functions for handling credential-related operations.curl.py
: Utility function for making API calls.messages.py
: Functions for sending and querying messages.schema.py
: Functions for creating and retrieving schemas.
It's recommended to use a Python virtual environment when working with the AATP system. Follow these steps to set up and activate a virtual environment:
-
Open a terminal and navigate to the project directory.
-
Create a new virtual environment:
python -m venv aatp_env
-
Activate the virtual environment:
- On Windows:
aatp_env\Scripts\activate
- On macOS and Linux:
source aatp_env/bin/activate
- On Windows:
-
Install the required dependencies:
pip install -r requirements.txt
-
When you're done working on the project, deactivate the virtual environment:
deactivate
The AATP system relies on several Python libraries, including:
Flask
(for the web interface)requests
(for making API calls)qrcode
(for generating QR codes)argparse
(for command-line argument parsing)
Ensure these dependencies are installed in your virtual environment before running the AATP system.
The AATP system can be used through the backend API (aatp-cli.py
) for interacting with ACA-PY agents or the frontend API (aatp-ui.py
) which provides a web interface. Both interfaces provide access to the core functionality of the system, including:
- Creating and managing schemas
- Creating and querying credential definitions
- Issuing credentials
- Managing connections and invitations
- Sending and querying messages
- Tracing products
To use the backend API, run:
python aatp-cli.py
with the appropriate arguments or in interactive mode. To use the frontend API, run the Flask application in aatp-ui.py
and access it through a web browser.
Before using the AATP system, ensure that the config.py
file is properly set up with the correct API URL and authentication token.
The AATP system includes a comprehensive test suite to ensure the reliability and correctness of its components. The test files are located in the tests/
directory and cover various aspects of the system. The tests use Python's built-in unittest
framework.
To run the tests, follow these steps:
-
Ensure you have activated your Python virtual environment.
-
Navigate to the project root directory.
-
Run the tests using the unittest module:
python -m unittest discover tests
This command will discover and run all test files in the tests/
directory.
test_aatp_cli.py
: Tests for the backend API functionality.test_aatp_ui.py
: Tests for the frontend API functionality.test_credential.py
: Tests for credential-related operations.test_curl.py
: Tests for the API call utility function.test_schema.py
: Tests for schema creation and retrieval.test_connections.py
: Tests for connection and invitation management.
When adding new features or modifying existing ones, make sure to update or add corresponding tests. Follow these guidelines:
- Create new test files in the
tests/
directory. - Name your test classes as
TestClassName(unittest.TestCase)
. - Use meaningful names for test methods, prefixed with
test_
. - Use
setUp()
andtearDown()
methods for setup and cleanup operations. - Use unittest assertions (e.g.,
self.assertEqual()
,self.assertTrue()
) for verifications. - Aim for high test coverage to ensure system reliability.
The AATP project is organized into several key files and directories:
- Core Components: The core functionality is implemented in files such as
server.py
,aatp-cli.py
,aatp-ui.py
,connections.py
,credential.py
,messages.py
,schema.py
, andcurl.py
. - Configuration:
config.py
contains essential configuration settings. - Tests: All test-related files are located in the
tests/
directory.
To maintain code quality and consistency throughout the AATP system, adhere to the following guidelines:
- Follow PEP 8 for Python code style.
- Use meaningful variable and function names that clearly describe their purpose.
- Include docstrings for all functions and classes.
- Maintain consistent indentation (4 spaces per level).
- Avoid large functions; break them into smaller, reusable components.
- Use Python's built-in
logging
module for tracking the execution of the code. Logging helps in debugging and provides useful information when running in production. - Add logging statements at the start and end of functions, and before key actions, to trace the flow of execution.
- Set different logging levels (
DEBUG
,INFO
,WARNING
,ERROR
,CRITICAL
) based on the importance of the message.
Example:
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.info("Starting the application")
The AATP system is designed to be modular and extensible. To extend the system, follow these guidelines:
- Adding New Features: When adding a new feature, create a separate Python module if it does not fit into any existing files. Ensure it follows the same code structure and style guidelines.
- Integrating with ACA-PY: Use the existing structure in
aatp-cli.py
andaatp-ui.py
as examples for integrating new commands or routes. - Testing: Always write unit tests for new features. Refer to the
tests/
directory for examples of existing tests.
To get started with the AATP system, you'll need to set up a traction tenant agent. This is essential for interacting with ACA-PY compatible agents. Follow the steps below, adapted from the ACA-Py Workshop:
-
Access the Traction Console: Navigate to the Traction Console and sign up for a tenant agent.
-
Create a Tenant: Use the provided interface to create a new tenant. This tenant will represent your entity within the AATP system.
-
Configure the Tenant: After creating the tenant, note down the configuration details such as
tenant_id
,agent_endpoint
, and any authentication tokens provided. -
Download Mobile Wallet: You may also need a mobile wallet to interact with your tenant. Download and set up a compatible mobile wallet app (e.g., Trinsic or Lissi). Follow the instructions to link your mobile wallet to the tenant agent.
-
Test the Connection: Use the tenant console to generate a connection invitation. Scan this invitation using your mobile wallet to establish a connection. This will verify that your tenant is successfully set up.
These steps will prepare you to begin working with ACA-PY agents for agricultural traceability using the AATP system.
To obtain the API key for the AATP system, follow these steps:
-
Navigate to the API Key Management Section: Log in to your AATP console and find the API Key Management section in the settings.
-
Generate a New API Key: Click on the "Generate API Key" button. This will create a new API key for your account.
-
Copy the API Key: Once the key is generated, make sure to copy it immediately. You will not be able to see it again after you navigate away from the page.
-
Store the API Key Securely: Store your API key in a secure location, such as a password manager or an environment variable, to prevent unauthorized access.
-
Use the API Key in Your Application: When making API calls, include the API key in the request headers for authentication. For example:
import requests url = "https://api.example.com/endpoint" headers = { "Authorization": "Bearer YOUR_API_KEY" } response = requests.get(url, headers=headers)
By following these steps, you will be able to successfully generate and use your API key for the AATP system.
Schema IDs:
- 13ZM7KEfAzLC12q1R1SiTS:2:AATP_UserSchema:1.0
- 13ZM7KEfAzLC12q1R1SiTS:2:AATP_ProducerSchema:1.1
- 13ZM7KEfAzLC12q1R1SiTS:2:AATP_CertifyingAuthoritySchema:1.0
- 13ZM7KEfAzLC12q1R1SiTS:2:AATP_ProductSchema:1.0
- 13ZM7KEfAzLC12q1R1SiTS:2:AATP_RetailerSchema:1.0
- 13ZM7KEfAzLC12q1R1SiTS:2:AATP_ConsumerSchema:1.0
- 13ZM7KEfAzLC12q1R1SiTS:2:AATP_PackagingSchema:1.0
- 13ZM7KEfAzLC12q1R1SiTS:2:AATP_TransportationSchema:1.1
- 13ZM7KEfAzLC12q1R1SiTS:2:AATP_RecallSchema:1.0
- 13ZM7KEfAzLC12q1R1SiTS:2:AATP_CertificationSchema:1.0
Credential Definition IDs:
- 13ZM7KEfAzLC12q1R1SiTS:3:CL:2308153:User
- 13ZM7KEfAzLC12q1R1SiTS:3:CL:2308155:Producer
- 13ZM7KEfAzLC12q1R1SiTS:3:CL:2308156:CertifyingAuthority
- 13ZM7KEfAzLC12q1R1SiTS:3:CL:2308157:Product
- 13ZM7KEfAzLC12q1R1SiTS:3:CL:2308159:Retailer
- 13ZM7KEfAzLC12q1R1SiTS:3:CL:2308160:Packaging
- 13ZM7KEfAzLC12q1R1SiTS:3:CL:2308438:Transportation
- 13ZM7KEfAzLC12q1R1SiTS:3:CL:2308162:Recall
- 13ZM7KEfAzLC12q1R1SiTS:3:CL:2308158:Consumer
- 13ZM7KEfAzLC12q1R1SiTS:3:CL:2308259:Certification
Sequence 1: Issue credential to producer, retailer (Pre-registered) and certifying authority (Pre-registered)
- Producer downloads Wallet app
- Producer scans QR code to connect to AATP_Tenant
- Producer requests a User credential from AATP_Tenant at 127.0.0.1:5000/new-user (Use connection ID: f5f80243-cce2-4e90-9193-e8c039620e05)
- AATP_Tenant issues a User credential to Producer
- Producer requests a Producer credential from AATP_Tenant at 127.0.0.1:5000/new-producer (Use connection ID: f5f80243-cce2-4e90-9193-e8c039620e05)
- AATP_Tenant issues a Producer credential to Producer
- Producer stores both credentials in Wallet
- Producer requests a Certification credential from AATP_Tenant at 127.0.0.1:5000/new-certification (Use connection ID: f5f80243-cce2-4e90-9193-e8c039620e05)
- AATP_Tenant issues a Certification credential to Producer
- Producer requests a Product credential from AATP_Tenant at 127.0.0.1:5000/new-product (Use connection ID: f5f80243-cce2-4e90-9193-e8c039620e05)
- AATP_Tenant issues a Product credential to Producer
- Producer requests a Packaging credential from AATP_Tenant at 127.0.0.1:5000/new-packaging (Use connection ID: f5f80243-cce2-4e90-9193-e8c039620e05)
- AATP_Tenant issues a Packaging credential to Producer
- Producer requests a Transportation credential from AATP_Tenant at 127.0.0.1:5000/new-transportation (Use connection ID: f5f80243-cce2-4e90-9193-e8c039620e05)
- AATP_Tenant issues a Transportation credential to Producer
- Consumer scans the QR code on the product
- AATP_UI is invoked at 127.0.0.1:5000/product-trace
- AATP_UI displays the product's journey from production to packaging to transportation to retailer
The AATP_CertificationSchema is used to capture certification details for a producer. The schema includes the following attributes:
certification_id
: Unique identifier for the certification.producer_id
: Identifier for the producer receiving the certification.certification_date
: Date of certification.certification_authority_id
: Identifier of the certifying authority.certification_status
: Status of the certification (e.g., active, expired).
The AATP_CertifyingAuthoritySchema defines information about certifying authorities. The schema includes:
authority_id
: Unique identifier for the certifying authority.user_id
: Identifier for the user associated with the authority.authority_type
: Type of the certifying authority.
The AATP_ConsumerSchema represents consumer information. The attributes are:
consumer_id
: Unique identifier for the consumer.user_id
: Identifier for the user associated with the consumer.
The AATP_PackagingSchema captures details about product packaging. Attributes include:
packaging_id
: Unique identifier for the packaging.product_id
: Identifier for the product being packaged.packaging_date
: Date when packaging was done.packaging_facility_id
: Identifier for the facility where packaging took place.packaging_conditions
: Conditions under which the product was packaged.batch_number
: Batch number associated with the packaging.
The AATP_ProducerSchema defines information about the producer. The schema includes:
producer_id
: Unique identifier for the producer.user_id
: Identifier for the user associated with the producer.organization_type
: Type of the producer's organization.
The AATP_ProductSchema represents product details. The attributes are:
product_id
: Unique identifier for the product.product_name
: Name of the product.producer_id
: Identifier of the producer of the product.production_date
: Date of product production.expiration_date
: Expiration date of the product.
The AATP_RecallSchema captures information about product recalls. The schema includes:
recall_id
: Unique identifier for the recall.recall_reason
: Reason for recalling the product.affected_product_id
: Identifier of the affected product.recall_date
: Date of the recall.issuer_id
: Identifier of the recall issuer.
The AATP_RetailerSchema defines information about retailers. Attributes include:
retailer_id
: Unique identifier for the retailer.user_id
: Identifier for the user associated with the retailer.store_location
: Location of the retail store.
The AATP_TransportationSchema represents transportation details for product shipments. The attributes are:
shipment_id
: Unique identifier for the shipment.product_id
: Identifier for the product being transported.origin_location
: Location from which the shipment originated.destination_location
: Destination location for the shipment.shipment_date
: Date of shipment.transport_conditions
: Conditions under which the product is transported.
The AATP_UserSchema defines basic user information. Attributes include:
user_id
: Unique identifier for the user.name
: Name of the user.email
: Email address of the user.
Contributions are welcome! If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix:
git checkout -b feature-name
- Make your changes and commit them:
git commit -m "Description of feature or fix"
- Push your branch to your fork:
git push origin feature-name
- Submit a pull request to the main repository.
Please ensure your code follows the project's style guide and includes relevant tests.
This project is licensed under the MIT License. See the LICENSE file for more information.