Module: Services & API Architectures
Below provides a brief explaination of the files included in this codebase.
db-init/: This folder will be binded to thedocker-entrypoint-initdb.d/folder inside thepostgrescontainer. All scripts in this folder will be executed during DB initialization. Checkcompose.yamlto see how it is used.init.sql: An SQL script to create all data tables and pre-insert the 3 products into the database.
src/: This main source code folder is where you implement the 3 microservices.api_service/: Implement the RESTful API Service as the main backend service. First, update theopenapi.yamlfile to clarify the APIs you will implement. Then, write a Flask/FastAPI service to implement all the APIs specified in youropenapi.yamlfile.db_service/: Implement the DB service with gRPC so that the API Service can interact with it. This folder initially contains alocal_manager.pyfile (with its dependency configured inrequirements.txt) to show how to interact from localhost with the PostgreSQL database inside thepostgrescontainer. You can consider this file as a tutorial of how to usepsycopg2. In your final submission, you should interact with the database from your DB Service container, not localhost!logging_service/: Implement the Logging Service with gRPC so that the API Service can send execution logs to it. This folder initially contains alocal_publisher.pyfile (with its dependency configured inrequirements.txt) to show how to push text messages from localhost to the Kafka topic inside thekafkacontainer. You can consider this file as a tutorial of how to useconfluent_kafka. In your final submission, you should push log messages from your Logging Service container, not localhost!
.env_example: An example of what your.envfile should look like. Refer to the next section to for setup..gitignore: Ignores.envso your DB user password is not recorded by Git.Makefile: Contains some utility commands for you. Check the corresponding section for more information.README.md: Hey, it's me!compose.yaml: The YAML file where you specify your service containers. We have already configured the PostgreSQL database and the Kafka topic for you and your job is to add your service containers here as well. This file will used by Docker Compose.
Duplicate .env_example and rename it to .env. Configure the PostgreSQL credentials inside this file. It will be used by compose.yaml.
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}We offer some utility bash commands in Makefile. Feel free to use them during your development & experiment.
setup-psqlusesapt installto configure thepsqlCLI and then starts a PostgreSQL server for its connection. Use this command if you want to connect to the database directly from localhost.how-to-psqlshows how to connect to the database from within thepostgrescontainer.how-to-relife-dbshows how to clean up the database (and its binded volume) when stopping the withdocker compose.how-to-stream-logshows how to connect to the Kafka topic and fetch logs from it in a streaming fashion. Essentially, we pop out a Kafka console consumer inside thekafkacontainer to connect to the topic.