Calmag
A simple calculator to calculate the optimal calcium and magnesium concentration for your nutrient solutions.
Install / Use
/learn @Webklex/CalmagREADME
CalMag Calculator
A simple calculator to calculate the optimal calcium and magnesium concentration for your nutrient solutions. You can find a demo of the calculator here.

Table of Contents
Installation
1.) Clone the repository:
git clone https://github.com/webklex/calmag.git
2.) Install the dependencies:
composer install
3.) Start the development server:
php -S localhost:8000 -t public
Requirements
- PHP >= 8.1
- Composer
Docker
You can run the app using Docker for a quick and isolated setup:
Build system architecture
docker buildx build -t webklex-calmag:dev .
docker run -d -p 8000:8000 --name webklex-calmag webklex-calmag:dev
Build AMD64 architecture
AMD64 (works in general but emulating on ARM)
docker buildx build --platform linux/amd64 -t webklex-calmag:dev-amd64 .
Build ARM64 architecture
docker buildx build --platform linux/arm64 -t webklex-calmag:dev-arm64 .
A precompiled image maintained by @manfredsteger can be found here: https://hub.docker.com/r/manfredsteger/webklex-calmag
Configuration
All configuration files are located in the src/config directory.
Additives
The src/config/additives.php file contains all available additives. You can add new additives or modify existing ones. Make sure to keep the array structure.
Fertilizers
The src/config/fertilizers.php file contains all available fertilizers. You can add new fertilizers or modify existing ones. Make sure to keep the array structure.
Languages
All language files are located in the resources/lang directory. You can add new languages or modify existing ones. Make sure to keep structure and naming conventions - misinterpretation can lead to unexpected behavior.
The user specific language is determined by the Accept-Language header. If the language is not available, the default language will be used.
API
The CalMag Calculator provides a JSON API that allows you to programmatically access the calculator's functionality.
Endpoints
The API provides the following endpoints:
POST|GET/ - Calculate nutrient solutions based on provided parametersGET/?method=additives - Get a list of available additivesGET/?method=fertilizers - Get a list of available fertilizersGET/?method=models - Get a list of available models
Request Format
The API accepts both GET and POST requests. For POST requests, the data should be sent as JSON in the request body. For GET requests, parameters can be passed in the URL query string or as a base64-encoded JSON payload in the p parameter.
To specify that you want a JSON response, set the Accept or Content-Type header to application/json.
Response Format
All API responses are in JSON format and include a version field with the current application version.
/ Response
{
"version": "3.4.0",
"result": {
...
}
}
/?method=additives Response
{
"version": "3.4.0",
"additives": {
"calcium": {
"CaNO3": {
"elements": {
"calcium": 24.43,
"nitrogen": 17.08,
"magnesium": 0
},
"concentration": 10,
"real": {
"calcium": 24.430000000000003,
"magnesium": 0,
"nitrogen": 17.08
},
"name": "Calcium nitrate"
}
},
"magnesium": {
"MgSO4-7H20": {
"elements": {
"magnesium": 9.86,
"sulfur": 13.01,
"calcium": 0
},
"concentration": 10,
"real": {
"calcium": 0,
"magnesium": 9.86,
"sulfur": 13.01
},
"name": "Epsom salt - Magnesiumsulfate-Heptahydrate"
}
}
}
}
/?method=fertilizers Response
{
"version": "3.4.0",
"fertilizers": {
"Canna - CalMag Agent": {
"name": "CalMag Agent",
"elements": {
"calcium": 7.0447999999999995,
"magnesium": 2.1386,
"nitrogen": 4.12624
},
"density": 1.258,
"ph": 7,
"schedule": false,
"link": {
"de": "https://www.canna-de.com/calmag-agent",
"us": "https://www.canna-uk.com/calmag-agent"
},
"brand": "Canna",
"ratio": 3.2941176470588234
},
"BioBizz - CalMag": {
"name": "CalMag",
"elements": {
"calcium": {
"CaO": 4.5654
},
"magnesium": {
"MgO": 1.8478999999999999
}
},
"density": 1.087,
"ph": 7,
"schedule": false,
"link": {
"de": "https://www.biobizz.com/de/producto/calmag/",
"us": "https://www.biobizz.com/producto/calmag/"
},
"brand": "BioBizz",
"ratio": 2.9256319238570767
}
}
}
Examples
Example 1: Get available fertilizers
curl -H "Accept: application/json" "https://www.calmag.eu/?method=fertilizers"
Example 2: Calculate nutrient solution (GET with encoded payload)
# Base64-encoded JSON payload
curl -H "Accept: application/json" "https://www.calmag.eu/?expert=1&p=eyJmZXJ0aWxpemVyIjoiIiwiYWRkaXRpdmUiOnsiY2FsY2l1bSI6IkNhTk8zIiwibWFnbmVzaXVtIjoiQ2FubmEgTW9ubyBNYWduZXNpdW0ifSwiYWRkaXRpdmVfY29uY2VudHJhdGlvbiI6eyJjYWxjaXVtIjoxMCwibWFnbmVzaXVtIjoxMDB9LCJhZGRpdGl2ZV91bml0cyI6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H0sInRhcmdldF9tYWduZXNpdW0iOnsiMSI6MCwiMiI6MCwiMyI6MCwiNCI6MCwiNSI6MCwiNiI6MCwiNyI6MCwiOCI6MCwiOSI6MCwiMTAiOjAsIjExIjowLCIxMiI6MH19"
Build
To build the project you can use the following command:
npm install
npm run production
npm run build:tailwind
npm run watch:tailwind
Support
If you encounter any problems or if you find a bug, please don't hesitate to create a new issue. However, please be aware that it might take some time to get an answer.
If you need immediate or commercial support, feel free to send me a mail at github@webklex.com.
Change log
Please see CHANGELOG for more information what has changed recently.
Security
If you discover any security related issues, please email github@webklex.com instead of using the issue tracker.
Credits
- Fumu <3
- Webklex
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
