A microservice that analyzes soil and environmental data to calculate crop water stress and provide irrigation recommendations.
- Backend: FastAPI (Python 3.11)
- Database: PostgreSQL 15
- ORM: SQLAlchemy
- Containerization: Docker & Docker Compose
- Docker Desktop installed and running
docker compose up --buildThis starts two containers:
| Container | Description | Port |
|---|---|---|
irrigation-app |
FastAPI application | 8000 |
irrigation-db |
PostgreSQL 15 database | 5433 |
- Health check: http://localhost:8000/health
- Swagger UI: http://localhost:8000/docs
All endpoints (except /health) require a JWT Bearer token. Register a user, log in to get a token, then include it in requests.
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/register |
Create account (username, password) |
| POST | /auth/login |
Get JWT token (form-urlencoded) |
# Register
curl -X POST http://localhost:8000/auth/register \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "pass123"}'
# Login
curl -X POST http://localhost:8000/auth/login \
-d "username=admin&password=pass123"
# Use token on protected endpoints
curl http://localhost:8000/crops \
-H "Authorization: Bearer <your_token>"In Swagger UI (/docs), click the Authorize button and paste the token.
The frontend handles auth automatically — register and sign in, then use the app normally.
| Method | Endpoint | Description |
|---|---|---|
| POST | /crops |
Register a new crop |
| GET | /crops |
List all crops |
| GET | /crops/{crop_id} |
Get a specific crop |
| Method | Endpoint | Description |
|---|---|---|
| POST | /sensor-data |
Submit new sensor readings |
| GET | /sensor-data |
List sensor readings |
| GET | /sensor-data/{sensor_id} |
Get specific sensor data |
| Method | Endpoint | Description |
|---|---|---|
| POST | /decisions/evaluate/{sensor_data_id} |
Analyze data and generate decision |
| GET | /decisions |
List irrigation decisions |
| PATCH | /decisions/{decision_id} |
Update decision status |
The application uses three main tables:
- users — Registered users with hashed passwords
- crops — Crop information with moisture and temperature thresholds
- sensor_data — Environmental and soil sensor readings
- irrigation_decisions — Generated irrigation recommendations with stress analysis
├── app/
│ ├── database/
│ │ ├── __init__.py
│ │ └── connection.py
│ ├── interfaces/
│ │ ├── __init__.py
│ │ ├── api.py
│ │ └── auth_routes.py
│ ├── models/
│ │ ├── __init__.py
│ │ └── models.py
│ ├── schemas/
│ │ ├── __init__.py
│ │ └── schemas.py
│ ├── services/
│ │ ├── __init__.py
│ │ └── irrigation_service.py
│ ├── __init__.py
│ ├── auth.py
│ └── main.py
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── README.md
A minimal HTML frontend is included in the frontend/ directory.
The interface allows users to:
- Register a crop with its environmental thresholds
- Submit sensor data for a crop
- Evaluate irrigation decisions based on sensor readings
- Start the backend service:
docker compose up --build
- Open the frontend from file explorer:
frontend/index.html
- Use the interface in this order:
- Register an account and sign in
- Create a crop
- Submit sensor data
- Enter the returned sensor ID
- Click Evaluate Decision
The frontend communicates with the FastAPI microservice using REST API calls.
| Name | GitHub |
|---|---|
| Nazanin Niazi | @NazaninNiazi11 |
| Shada Daab | @shadatr |
| Özge Zelal Küçük | @ozge-devops |
| Danya Eusmanaga | @danyaosman |
Special Topics in Software Development