Monorepo for all backend microservices.
Refer to each component's section for detailed startup instructions for local development.
- API Server - Microservice that provides APIs for watersense-ui.
- Ingestion Module - Microservice that saves incoming message stream from RabbitMQ broker from sensor origin.
- MongoDB - NoSQL DB to store data streamed from sensor. This folder serves as a docker volume to persist data on the local container instance. Delete the data folder to reset all data.
- RabbitMQ - Messaging broker. This folder serves as a docker volume to persist data on the local container instance. Delete the data folder to reset all data.
This runs all components as docker containers.
- Install Docker.
- Install Python Poetry. This is to handle python envs.
- Run the command to start up all components.
$ docker compose up
- You should see this on first start up. The ingestion-module relies on an exchange to be created. The sensor handles the creation of this exchange, the ingestion module only subscribes to the exchange. Since the exchange is not created yet, the ingestion-module will crash.
- Open a new terminal and navigate to the ingestion-module.
$ cd ingestion-module
- Install the ingestion-module dependencies.
$ poetry install
- Activate the virtual env.
$ poetry shell
- Run the sample producer that simulates data being streamed from the sensor.
$ python src/mock_sensor.py
Ingestion module will stop crashing and you should see this. - Go to the RabbitMQ console to verify that RabbitMQ is working. http://localhost:15672.
Username: root, Password: root
- Go to the MongoDB admin console to verify that MongoDB is working. http://localhost:8081.
Username: root, Password: root
- Go to the api-server swagger docs to test available apis. http://localhost:8080/swagger.
Deployed server at https://watersense-api-watersense-seanjin97.cloud.okteto.net/swagger
Running api-server locally.
- Start watersense-backend. Refer to steps above.
- Modify source code, the docker container will hot reload on code change. # Note: if new env variables or dependencies are added, the docker image will need to be rebuilt. Stop the docker compose with
$ docker compose down
, followed by deleting thewatersense-backend_api
image. Finally, re-run the docker compose.
- Start watersense-backend. Refer to steps above
- Stop the
watersense-backend-api-1
container since you'll be running the server on command line. $ cd api-server
$ poetry install
$ poetry shell
$ python src/main.py
Outline of api-server microservice.
api-server
src
.env
main.py - app entrypoint.
config
config.py - reads values from .env file.
db.py - connects to DB.
dao
sensor.py - functions to interact with the DB.
models - pydantic models for FastAPI.
Running ingestion-module locally.
- Start watersense-backend. Refer to steps above
- Stop the
watersense-backend-ingestion-module-1
container since you'll be running the server on command line. $ cd ingestion-module
$ poetry install
$ poetry shell
$ python src/main.py
Outline of api-server microservice.
ingestion-module
src
.env
main.py - app entrypoint.
ampq_sample_producer.py - to simulate sensor sending data.
config
config.py - reads values from .env file.
db.py - connects to DB.
amqp.py - connects to rabbitmq.
dao
sensor.py - functions to interact with the DB.