A comprehensive food security platform leveraging AI technology to address SDG 2 (Zero Hunger) through innovative nutrition analysis, crop prediction, and community support systems.
- Nutrition Analysis: Advanced AI-driven meal analysis using OpenAI GPT models
- Crop Yield Prediction: Machine learning-based agricultural forecasting
- Personalized Recommendations: Tailored advice based on user profiles
- Real-time Analytics: Comprehensive food security insights
- IntaSend Gateway: Seamless mobile money and card payments
- Donation Platform: Support food security initiatives
- Marketplace: Direct farmer-to-consumer transactions
- Multi-currency Support: KES, USD, EUR, GBP
- JWT Authentication: Secure token-based authentication
- Rate Limiting: Protection against abuse and attacks
- Input Validation: Comprehensive data sanitization
- CSRF Protection: Cross-site request forgery prevention
- SQL Injection Prevention: Parameterized queries and ORM
- Responsive Design: Mobile-first approach
- Progressive Web App: Offline capabilities
- Accessibility: WCAG 2.1 compliant
- Real-time Updates: WebSocket integration
- Multi-language Support: Internationalization ready
- Backend: Python 3.8+, Flask 2.3+
- Database: MySQL 8.0+ with Redis caching
- Frontend: HTML5, CSS3, Vanilla JavaScript
- AI Services: OpenAI GPT-3.5/4, Hugging Face Transformers
- Payment: IntaSend API integration
- Deployment: Gunicorn, Nginx, Docker (optional)
- Python 3.8 or higher
- MySQL 8.0 or higher
- Redis 6.0+ (recommended)
- 2GB RAM minimum (4GB recommended)
- 10GB disk space
git clone https://github.com/yourusername/nutriguard.git
cd nutriguard# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# Create MySQL database
mysql -u root -p
CREATE DATABASE nutriguard;
exit
# Run database schema
mysql -u root -p nutriguard < database_setup.sql# Copy environment template
cp .env.example .env
# Edit .env with your configuration
nano .env# Development mode
python app.py
# Production mode
gunicorn --config gunicorn.conf.py app:app| Variable | Description | Required | Default |
|---|---|---|---|
SECRET_KEY |
Flask secret key | Yes | - |
DATABASE_URL |
MySQL connection string | Yes | - |
OPENAI_API_KEY |
OpenAI API key | Yes | - |
INTASEND_PUBLIC_KEY |
IntaSend public key | Yes | - |
INTASEND_SECRET_KEY |
IntaSend secret key | Yes | - |
REDIS_URL |
Redis connection string | No | redis://localhost:6379/0 |
FLASK_ENV |
Environment mode | No | development |
# Example DATABASE_URL formats
mysql://username:password@localhost/nutriguard
mysql://user:pass@hostname:3306/dbname- OpenAI: Get your API key from OpenAI Platform
- IntaSend: Register at IntaSend and get your keys
- Hugging Face (optional): Get token from Hugging Face
# Run all tests
python test_suite.py
# Run specific test class
python -m unittest test_suite.TestAuthentication
# Run with coverage
pip install coverage
coverage run test_suite.py
coverage report- Authentication Tests: User registration, login, JWT tokens
- AI Service Tests: Nutrition analysis, crop prediction
- Payment Tests: IntaSend integration, donation processing
- Security Tests: Input validation, rate limiting
- API Tests: Endpoint functionality, error handling
POST /api/register
Content-Type: application/json
{
"username": "farmer1",
"email": "farmer@example.com",
"password": "securepassword",
"user_type": "farmer",
"location": "Nairobi, Kenya",
"phone": "254712345678"
}POST /api/login
Content-Type: application/json
{
"username": "farmer1",
"password": "securepassword"
}POST /api/nutrition/analyze
Authorization: Bearer <token>
Content-Type: application/json
{
"meal_description": "Grilled chicken with steamed vegetables and brown rice"
}POST /api/crops/predict
Authorization: Bearer <token>
Content-Type: application/json
{
"crop_type": "maize",
"location": "Nairobi, Kenya",
"soil_data": {
"type": "loamy",
"ph": 6.5,
"organic_matter": "high"
},
"weather_data": {
"expected_rainfall": 800,
"temperature_range": "20-30Β°C"
}
}POST /api/donate
Authorization: Bearer <token>
Content-Type: application/json
{
"amount": 1000,
"phone_number": "254712345678",
"purpose": "Support smallholder farmers"
}# Run deployment script
python deploy.py --environment production
# Or for development
python deploy.py --environment developmentserver {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
alias /path/to/nutriguard/static;
expires 1y;
add_header Cache-Control "public, immutable";
}
}sudo certbot --nginx -d yourdomain.comsudo cp nutriguard.service /etc/systemd/system/
sudo systemctl enable nutriguard
sudo systemctl start nutriguardFROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["gunicorn", "--config", "gunicorn.conf.py", "app:app"]/health- Application health status/metrics- Prometheus metrics (if enabled)- Database connection monitoring
- Redis connection status
- Application logs:
logs/app.log - Access logs:
logs/access.log - Error logs:
logs/error.log - Deployment logs:
deployment.log
- Response time tracking
- Database query performance
- AI service latency
- Payment processing metrics
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Install development dependencies:
pip install -r requirements-dev.txt - Make your changes
- Run tests:
python test_suite.py - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow PEP 8 style guidelines
- Write comprehensive docstrings
- Add unit tests for new features
- Update documentation as needed
- Use type hints where appropriate
- Maintain >90% test coverage
- Write both unit and integration tests
- Mock external API calls
- Test error conditions
- Validate security measures
- Authentication: JWT tokens with expiration
- Authorization: Role-based access control
- Input Validation: Comprehensive sanitization
- SQL Injection: Parameterized queries
- XSS Protection: Content Security Policy
- CSRF Protection: Token validation
- Rate Limiting: Request throttling
- HTTPS Enforcement: SSL/TLS encryption
- Regular dependency updates
- Security header implementation
- Secure cookie configuration
- Password strength requirements
- Session management
- Audit logging
NutriGuard directly supports UN Sustainable Development Goal 2 (Zero Hunger) by:
- Improving nutrition through AI-powered meal analysis
- Supporting smallholder farmers with crop prediction
- Facilitating food access through marketplace integration
- Enabling community support through donation platform
- Promoting sustainable agriculture practices
- Users registered and active
- Nutrition analyses completed
- Crop predictions generated
- Donations processed
- Farmers supported
- Lives impacted
- Improved crop yields for smallholder farmers
- Better nutrition awareness in communities
- Successful donation campaigns
- Marketplace transaction growth
- Documentation: Check this README and docs folder
- Issues: Open a GitHub issue for bugs or feature requests
- Discussions: Use GitHub Discussions for questions
- Email: contact@nutriguard.com (if applicable)
- Join our community discussions
- Follow us on social media
- Contribute to the project
- Share your success stories
This project is licensed under the MIT License - see the LICENSE file for details.
- UN SDG 2: Zero Hunger initiative inspiration
- OpenAI: AI-powered nutrition analysis
- IntaSend: Payment processing partnership
- Flask Community: Web framework support
- Contributors: All developers who contributed to this project
Built with β€οΈ for SDG 2 Zero Hunger Initiative
"Technology for a hunger-free world"