A comprehensive REST API for monitoring aquaculture pools and sensor readings. This system tracks various water quality parameters, fish behavior, and environmental conditions to help maintain optimal conditions for aquaculture operations.
- Pool Management: Create, read, update pools with fish and capacity information
- Multi-Sensor Monitoring: Track 13+ different sensor types including water quality, fish behavior, and environmental parameters
- Real-time Data: Get current sensor values and latest readings
- Data Aggregation: Daily sensor summaries with min/max/average values
- Alert System: Configurable sensor limits and thresholds
- Water Quality Assessment: Automated water purity calculations
- Interactive API Documentation: Swagger UI for easy API exploration
- pH - Water acidity/alkalinity (0-14 scale)
- Ammonia - Toxic ammonia levels (PPM)
- Nitrite - Nitrite nitrogen levels (PPM)
- Nitrate - Nitrate nitrogen levels (PPM)
- Dissolved Oxygen - Oxygen levels (PPM) and saturation percentage
- ORP - Oxidation-reduction potential (mV)
- Salinity - Salt concentration (PPT)
- Temperature - Water temperature (°C)
- Turbidity - Water clarity (NTU)
- TOC - Total Organic Carbon (PPM)
- Water Level - Water height (cm) and flow rate (LPM)
- Fish Activity - Activity level, movement count, and speed
- Feeding Response - Strike rate percentage and response time
- Bacteria Density - Bacteria count (CFU/ml), pathogenic/beneficial ratios
- Water Purity - Calculated overall water quality assessment
- Clone the repository
git clone <repository-url>
cd mainapi- Install dependencies
npm install- Initialize the database
npm run init-db- Start the server
npm startFor development with auto-reload:
npm run devOnce the server is running, access the interactive Swagger UI documentation at:
- Full Documentation: http://localhost:3000/api-docs
- Quick Access: http://localhost:3000/docs
http://localhost:3000/api
GET /api/pools- Get all poolsPOST /api/pools- Create a new poolGET /api/pools/{id}- Get pool by IDPUT /api/pools/{id}- Update pool
Each sensor type follows the same pattern:
GET /api/{sensor-type}-readings- Get all readings (with filtering)POST /api/{sensor-type}-readings- Create new readingGET /api/{sensor-type}-readings/{pool_id}- Get readings for specific pool
Available sensor types:
ph-readingstemperature-readingsammonia-readingsnitrite-readingsnitrate-readingsdissolved-oxygen-readingsorp-readingssalinity-readingsturbidity-readingswater-level-readingstoc-readingsfish-activity-readingsfeeding-response-readingsbacteria-density-readings
GET /api/current-sensor-values/latest/{pool_id}- Get latest readings from all sensorsGET /api/daily-sensor-summary- Get daily aggregated dataPOST /api/daily-sensor-summary- Create daily summary
GET /api/water-purity-readings- Get all water purity readingsGET /api/water-purity-readings/pool/{pool_id}- Get readings for specific poolGET /api/water-purity-readings/pool/{pool_id}/latest- Get latest calculation
GET /api/norms- Get sensor limits/thresholdsPUT /api/norms- Update sensor limits/thresholds
Most GET endpoints support these parameters:
pool_id- Filter by pool IDlimit- Number of records to return (default: 100)offset- Number of records to skip (default: 0)start_date- Start date filter (YYYY-MM-DD)end_date- End date filter (YYYY-MM-DD)
The system uses SQLite by default. Database files are stored in the database/ directory.
Configure sensor thresholds via the /api/norms endpoint. The system will trigger alerts when readings exceed these limits.
- Water purity calculations run every 5 minutes automatically
- Daily summaries can be generated via API calls
curl -X POST http://localhost:3000/api/pools \
-H "Content-Type: application/json" \
-d '{
"number_of_fish": 150,
"age_of_fish": 30,
"capacity_liters": 5000,
"name": "Main Tank A",
"location": "Building 1"
}'curl -X POST http://localhost:3000/api/temperature-readings \
-H "Content-Type: application/json" \
-d '{
"pool_id": 1,
"temperature_celsius": 24.5,
"notes": "Morning reading"
}'curl http://localhost:3000/api/current-sensor-values/latest/1curl "http://localhost:3000/api/daily-sensor-summary?pool_id=1&sensor_type=temperature&start_date=2024-01-01"All responses are in JSON format:
Success Response:
{
"reading_id": 1,
"pool_id": 1,
"temperature_celsius": 24.5,
"reading_timestamp": "2024-01-15T10:30:00.000Z",
"Pool": {
"pool_id": 1,
"name": "Main Tank A",
"capacity_liters": 5000
}
}Error Response:
{
"error": "Pool not found"
}The API uses standard HTTP status codes:
200- Success201- Created400- Bad Request404- Not Found409- Conflict500- Internal Server Error
- Range: -5°C to 50°C
- Required:
pool_id,temperature_celsius
- Range: 0-14
- Required:
pool_id,ph_value
- All readings require valid
pool_id - Timestamps are automatically generated
- Notes are optional for all readings
The system includes an alert system that:
- Monitors sensor readings against configured limits
- Triggers alerts when thresholds are exceeded
- Supports SMS notifications (see SMS_IMPLEMENTATION_SUMMARY.md)
- Provides configurable sensor limits via the norms endpoint
The API is designed to work with web dashboards, mobile apps, and IoT devices. All endpoints return JSON and support CORS.
Sensors can POST readings directly to the appropriate endpoints. The system handles validation and alert triggering automatically.
Use the daily summary endpoints to export aggregated data for reporting and analysis.
- Input validation on all endpoints
- SQL injection protection via Sequelize ORM
- Error handling to prevent information leakage
- Rate limiting can be implemented via middleware
npm start- Start production servernpm run dev- Start development server with auto-reloadnpm run init-db- Initialize databasenpm run wipe-db- Wipe and recreate database
node scripts/inject_dummy_data.py- Add test data- Database schemas are managed via Sequelize
API endpoints can be tested using:
- Swagger UI (http://localhost:3000/api-docs)
- Postman
- curl commands
- Automated test scripts
For technical support or questions:
- Check the interactive API documentation at
/api-docs - Review the code in the
routes/directory - Check the alert system documentation in
ALERT_SYSTEM.md - Review SMS implementation in
SMS_IMPLEMENTATION_SUMMARY.md
The application can be deployed to any Node.js hosting platform:
- Set
PORTenvironment variable - Ensure database directory is writable
- Configure any required environment variables
- Use
npm startto run in production
Current version: 1.0.0
This API is actively maintained and regularly updated with new features and improvements.