A comprehensive REST API for piggery farm management built with CodeIgniter 3.x. Designed specifically for managing pig farms, livestock operations, breeding programs, feeding schedules, and farm business operations with JWT authentication.
- π Pig Management: Individual pig tracking, health records, and breeding history
- π Farm Operations: Facility management, pen assignments, and equipment tracking
- π Dashboard: Real-time farm analytics, production metrics, and health monitoring
- π° Farm Accounting: Financial tracking, feed costs, sales records, and profitability analysis
- π€ User Management: Role-based access control for farm workers and managers with JWT authentication
- π Scheduling: Feeding schedules, breeding programs, vaccination reminders, and farm activities
- π½οΈ Feed Management: Feed inventory, nutrition tracking, and feeding schedules
- π Reports: Production reports, health certificates, and breeding documentation
- RESTful API endpoints for all farm operations
- JWT token-based authentication for secure access
- File upload handling (pig photos, health certificates, breeding records, etc.)
- Cross-platform compatibility for mobile and web applications
- Comprehensive data validation for livestock data integrity
The system handles various farm documentation:
- Pig identification photos
- Health and vaccination certificates
- Breeding records and genealogy
- Feed quality certificates
- Facility inspection documents
- Sales and transfer records
- Insurance and compliance documentation
- PHP 7.0 or higher
- MySQL/MariaDB database
- Web server (Apache/Nginx)
- Composer (optional, for dependencies)
-
Clone the repository
git clone https://github.com/iframe23/piggery-api.git cd piggery-api -
Set up the database
-- Create database and import the schema CREATE DATABASE piggery; mysql -u your_username -p piggery < schema.sql
-
Configure the application
# Copy example configuration files cp application/config/database.example.php application/config/database.php cp application/config/config.example.php application/config/config.php -
Update configuration files
Database Configuration (
application/config/database.php):$db['default'] = array( 'hostname' => 'localhost', 'username' => 'your_db_username', 'password' => 'your_db_password', 'database' => 'piggery', // ... other settings );
Base Configuration (
application/config/config.php):$config['base_url'] = 'http://yourdomain.com/'; $config['encryption_key'] = 'your-32-character-secret-key';
-
Set directory permissions
# Make upload directories writable chmod 755 images/ chmod 755 application/logs/ chmod 755 application/cache/ -
Access the application Navigate to
http://yourdomain.com/in your browser to access the piggery management system.
POST /auth/login
Content-Type: application/json
{
"username": "farm_manager",
"password": "your_password"
}Response:
{
"status": "success",
"token": "jwt_token_here",
"user_data": {
"id": 1,
"username": "farm_manager",
"role": "manager"
}
}| Endpoint | Method | Description | Authentication |
|---|---|---|---|
/auth/login |
POST | Farm user authentication | No |
/user/* |
GET/POST/PUT/DELETE | Farm staff management | JWT |
/dashboard/* |
GET | Farm dashboard data & analytics | JWT |
/accounting/* |
GET/POST | Farm financial operations | JWT |
/pig/* |
GET/POST/PUT/DELETE | Individual pig management | JWT |
/schedule/* |
GET/POST/PUT/DELETE | Farm activity scheduling | JWT |
/feed/* |
GET/POST/PUT | Feed inventory & management | JWT |
Upload farm-related files:
POST /upload/pig_photo
POST /upload/health_certificate
POST /upload/breeding_record
Content-Type: multipart/form-data
Authorization: Bearer {jwt_token}Get all pigs:
GET /pig/list
Authorization: Bearer {jwt_token}Add new pig:
POST /pig/create
Content-Type: application/json
Authorization: Bearer {jwt_token}
{
"pig_id": "PIG001",
"breed_id": 1,
"birth_date": "2023-05-15",
"pen_number": "A-12",
"status": "healthy"
}Update pig information:
PUT /pig/update/{pig_id}
Content-Type: application/json
Authorization: Bearer {jwt_token}
{
"weight": 85.5,
"health_status": "healthy",
"last_checkup": "2023-11-10"
}For production deployment:
-
Security Settings
- Set
ENVIRONMENTtoproductioninindex.php - Enable CSRF protection in
config.php - Use HTTPS in production
- Set strong encryption keys
- Set
-
Database Optimization
- Configure database connection pooling
- Set appropriate cache settings
- Regular database maintenance
-
File Upload Security
- Validate file types and sizes
- Scan uploads for malware
- Limit upload directory access
Update application/libraries/ImplementJWT.php for JWT settings:
- Token expiration time
- Secret key for signing
- Refresh token logic
piggery-api/
βββ application/
β βββ config/ # Configuration files
β βββ controllers/ # API controllers (Pig, Feed, Schedule, etc.)
β βββ models/ # Data models (Pig_model, Feed_model, etc.)
β βββ libraries/ # Custom libraries (JWT, REST, PDF)
β βββ views/ # View templates for reports
βββ images/ # Farm file uploads (organized by type)
β βββ pig_pics/ # Individual pig photos
β βββ certifications/ # Health and breeding certificates
β βββ ... # Other farm documentation
βββ system/ # CodeIgniter core
βββ schema.sql # Database structure for piggery
βββ README.md # This file
-
API Testing Use tools like Postman or curl to test endpoints:
# Test farm manager login curl -X POST http://localhost/piggery-api/auth/login \ -H "Content-Type: application/json" \ -d '{"username":"farm_manager","password":"password"}' # Get pig list (requires JWT token) curl -X GET http://localhost/piggery-api/pig/list \ -H "Authorization: Bearer YOUR_JWT_TOKEN"
-
Database Testing Verify database connections and pig data queries work correctly.
- Authentication: JWT tokens for secure farm API access
- Authorization: Role-based access control (farm managers, workers, veterinarians)
- Data Protection: All pig and farm data inputs are sanitized
- File Upload Security: Restricted file types for farm documentation
- SQL Injection Prevention: Using CodeIgniter's Query Builder for database operations
- Farm Data Privacy: XSS protection enabled for sensitive livestock information
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Add pig health monitoring alerts
- Implement breeding program automation
- Add feed consumption analytics
- Mobile app integration for farm workers
- Advanced pig growth tracking dashboard
- Integration with veterinary systems
- Automated feeding schedule optimization
- Market price integration for sales planning
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in this repository
- Check the CodeIgniter documentation for framework-specific questions
- Review the API documentation above
The system uses the following main database tables for piggery management:
pigs- Individual pig records, health status, and trackingbreeds- Pig breed information and characteristicspens- Farm facility and pen managementfeeds- Feed inventory and nutrition dataschedules- Feeding schedules, breeding programs, and farm activitieshealth_records- Vaccination records, medical treatments, and health monitoringaccounting- Farm financial records, feed costs, and sales datausers- Farm staff accounts and access control
See schema.sql for complete database structure designed for pig farm operations.
Note: This is a comprehensive pig farm management system designed specifically for piggery operations. The API handles all aspects of pig farming including livestock tracking, breeding programs, feed management, health monitoring, and farm business operations. Ensure compliance with local agricultural regulations and animal welfare standards.