A FastAPI-based backend service for managing agricultural supply chain operations with a focus on medicinal plants and Ayurvedic products.
This backend service provides REST APIs to handle:
- User registration and profile management across multiple roles (Farmers, Processors, Labs, etc.)
- Supply chain transaction tracking
- Validation of medicinal plant harvesting and processing
- Integration with MongoDB for data persistence
- FHIR-compliant data structures
- QR code-based batch tracking
- Python 3.8+
- MongoDB
- Environment variables configured
- Clone the repository:
git clone https://github.com/herbtrace/backend.git
cd backend- Create and activate virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: .\venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables in
.env:
MONGO_URI=your_mongodb_connection_stringbackend/
├── main.py # FastAPI application entry point
├── requirements.txt # Project dependencies
├── validation.json # Medicinal plant validation rules
├── models/
│ ├── signup.py # User profile models
│ └── stages.py # Supply chain stage models
└── routes/
├── profile.py # User profile management endpoints
└── transaction.py # Supply chain transaction endpoints
POST /profiles/create- Create new user profilePOST /profiles/login- SCM admin loginGET /profiles/get- Get all profilesGET /profiles/user_login- User login via profile IDGET /profiles/check_if_user_exists- Check profile existence
POST /start- Initialize crop transactionGET /get- Retrieve profile dataPOST /transactions- Process supply chain transaction
- Farmer
- Wild Collector
- Processor
- Laboratory
- Manufacturer
- Packer
- Storage
- Collection Event
- Transport Event
- Processing Event
- Quality Test
- Manufacturing Event
- Packing Event
The system includes validation rules for medicinal plants (validation.json) covering:
- Approved collection regions
- Harvesting seasons
- Quality parameters
- Processing requirements
- Sustainability guidelines
- Start the FastAPI server:
uvicorn main:app --reload --host 0.0.0.0 --port 8000- Access the API documentation:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
- Role-based Access Control: Different user roles with specific permissions
- Supply Chain Tracking: Complete tracking of medicinal plants from collection to packaging
- Data Validation: Comprehensive validation rules for medicinal plant processing
- FHIR Compliance: Healthcare data standard compatibility
- QR Code Integration: Batch tracking through QR codes
- MongoDB Integration: Scalable data storage solution
- CORS enabled
- Authentication tokens
- Role-based access control
- Secure password handling
- Input validation
The API implements proper error handling with appropriate HTTP status codes and error messages for:
- Invalid requests
- Authentication failures
- Database errors
- Validation failures
- Fork the repository
- Create a feature branch
- Commit changes
- Push to the branch
- Create a Pull Request