{"id":13289034,"url":"https://github.com/pamelafox/flask-db-quiz-example","last_synced_at":"2025-07-22T19:33:33.794Z","repository":{"id":138633420,"uuid":"555594971","full_name":"pamelafox/flask-db-quiz-example","owner":"pamelafox","description":"A Python Flask web app serving a quiz with high scores (made for demo purposes). Designed for deployment to Azure App Service with Azure Developer CLI.","archived":false,"fork":false,"pushed_at":"2025-03-31T07:21:58.000Z","size":231,"stargazers_count":6,"open_issues_count":5,"forks_count":9,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T18:27:19.939Z","etag":null,"topics":["app-service","azd-templates","azure","flask"],"latest_commit_sha":null,"homepage":"","language":"Bicep","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pamelafox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-10-21T22:38:41.000Z","updated_at":"2025-03-25T06:07:30.000Z","dependencies_parsed_at":"2024-02-12T16:31:44.513Z","dependency_job_id":"d9886ab6-e86e-4110-a1b3-14f20024a580","html_url":"https://github.com/pamelafox/flask-db-quiz-example","commit_stats":{"total_commits":122,"total_committers":3,"mean_commits":"40.666666666666664","dds":"0.38524590163934425","last_synced_commit":"18816739a92bb7a447107280fc0cfdf1f9874bb1"},"previous_names":[],"tags_count":0,"template":true,"template_full_name":"pamelafox/simple-flask-server-example","purl":"pkg:github/pamelafox/flask-db-quiz-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pamelafox%2Fflask-db-quiz-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pamelafox%2Fflask-db-quiz-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pamelafox%2Fflask-db-quiz-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pamelafox%2Fflask-db-quiz-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pamelafox","download_url":"https://codeload.github.com/pamelafox/flask-db-quiz-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pamelafox%2Fflask-db-quiz-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266561321,"owners_count":23948625,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["app-service","azd-templates","azure","flask"],"created_at":"2024-07-29T17:00:18.211Z","updated_at":"2025-07-22T19:33:33.746Z","avatar_url":"https://github.com/pamelafox.png","language":"Bicep","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Open in GitHub Codespaces](https://img.shields.io/static/v1?style=for-the-badge\u0026label=GitHub+Codespaces\u0026message=Open\u0026color=brightgreen\u0026logo=github)](https://github.com/codespaces/new?hide_repo_select=true\u0026ref=main\u0026repo=pamelafox%2Fflask-db-quiz-example\u0026machine=standardLinux32gb\u0026devcontainer_path=.devcontainer%2Fdevcontainer.json\u0026location=WestUs2)\n[![Open in Remote - Containers](https://img.shields.io/static/v1?style=for-the-badge\u0026label=Remote%20-%20Containers\u0026message=Open\u0026color=blue\u0026logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com%2Fpamelafox%2Fflask-db-quiz-example)\n\nThis repository includes a small Python Flask web site, made for demonstration purposes only.\n\n## Opening the project\n\nThis project has [Dev Container support](https://code.visualstudio.com/docs/devcontainers/containers), so it will be be setup automatically if you open it in Github Codespaces or in local VS Code with the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).\n\nIf you're not using one of those options for opening the project, then you'll need to:\n\n1. Create a [Python virtual environment](https://docs.python.org/3/tutorial/venv.html#creating-virtual-environments) and activate it.\n\n2. Install the requirements:\n\n    ```shell\n    python3 -m pip install -r requirements-dev.txt\n    ```\n\n3. Install the pre-commit hooks:\n\n    ```shell\n    pre-commit install\n    ```\n\n## Local development\n\n\n1. Create an `.env` file using `.env.sample` as a guide. Set the value of `DBNAME` to the name of an existing database in your local PostgreSQL instance. Set the values of `DBHOST`, `DBUSER`, and `DBPASS` as appropriate for your local PostgreSQL instance. If you're in the Dev Container, copy the values exactly from `.env.sample`.\n\n2. Apply migrations to database:\n\n```console\npython3 -m flask db upgrade --directory src/flaskapp/migrations\n```\n\n3. Load in seed data (to create first quiz):\n\n```console\npython3 -m flask seed\n```\n\n4. Run the server:\n\n```console\npython3 -m flask --debug run --port 50505\n```\n\n5. Click 'http://127.0.0.1:50505' in the terminal, which should open the website in a new tab.\n6. Open the quiz linked from the index page.\n7. Answer the quiz and submit, notice the high scores update below.\n\n## Tests\n\n1. Install the development requirements:\n\n```console\npython3 -m pip install -r requirements-dev.txt\nplaywright install --with-deps\n```\n\n2. Run the tests:\n\n```console\npython3 -m pytest\n```\n\n## Deployment\n\nThis repository is set up for deployment on Azure using the configuration files in the `infra` folder.\n\n![Architecture diagram: App Service, PostgreSQL Flexible server, Log Analytics](readme_diagram.png)\n\n1. Sign up for a [free Azure account](https://azure.microsoft.com/free/?WT.mc_id=python-79461-pamelafox)\n2. Install the [Azure Dev CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd?WT.mc_id=python-79461-pamelafox). (If you open this repository in Codespaces or with the VS Code Dev Containers extension, that part will be done for you.)\n3. Initialize a new `azd` environment:\n\n    ```shell\n    azd init\n    ```\n\n    It will prompt you to provide a name (like \"flask-app\") that will later be used in the name of the deployed resources.\n\n4. Provision and deploy all the resources:\n\n    ```shell\n    azd up\n    ```\n\n    It will prompt you to login, pick a subscription, and provide a location (like \"eastus\"). Then it will provision the resources in your account and deploy the latest code. If you get an error with deployment, changing the location (like to \"centralus\") can help, as there may be availability constraints for some of the resources.\n\n5. When azd has finished deploying, you'll see an endpoint URI in the command output. Visit that URI and you should see the quiz! 🎉\n\n6. When you've made any changes to the app code, you can just run:\n\n    ```shell\n    azd deploy\n    ```\n\n### CI/CD pipeline\n\nThis project includes a Github workflow for deploying the resources to Azure\non every push to main. That workflow requires several Azure-related authentication secrets\nto be stored as Github action secrets. To set that up, run:\n\n```shell\nazd pipeline config\n```\n\n### Security\n\n#### Database\n\nIt is important to secure the databases in web applications to prevent unwanted data access.\nThis infrastructure uses the following mechanisms to secure the PostgreSQL database:\n\n* Azure Firewall: The database is accessible only from other Azure IPs, not from public IPs. (Note that includes other customers using Azure).\n* Admin Username: A unique string generated based on the resource name (*not* random, but not a standard name, either).\n* Admin Password: Randomly generated and updated on each deploy.\n* PostgreSQL Version: Latest available on Azure, version 14, which includes security improvements.\n\n⚠️ To make your database connection more secure, consider:\n\n1. Storing username/password in Key Vault. See [the django-quiz-app project](https://github.com/pamelafox/django-quiz-app) for example infrastructure files.\n2. Using an Azure Virtual Network to connect the Web App to the Database. See [the django-on-azure project](https://github.com/tonybaloney/django-on-azure) for example infrastructure files.\n\n#### Sessions\n\nThis Flask app does not currently use [sessions](https://flask.palletsprojects.com/en/2.3.x/quickstart/#sessions), so it doesn't require a secret key. However, if you do add a secret key in the future, you should store that securely in Key Vault. See [the django-quiz-app project](https://github.com/pamelafox/django-quiz-app) for infrastructure files that store secrets in Key Vault.\n\n### Costs\n\nPricing varies per region and usage, so it isn't possible to predict exact costs for your usage.\n\nYou can try the [Azure pricing calculator](https://azure.com/e/6bf1c15e609249b3b223ca3ceadeba94) for the resources:\n\n- Azure App Service: Free Tier with shared CPU cores, 1 GB RAM. [Pricing](https://azure.microsoft.com/pricing/details/app-service/linux/)\n- PostgreSQL Flexible Server: Burstable Tier with 1 CPU core, 32GB storage. Pricing is hourly. [Pricing](https://azure.microsoft.com/pricing/details/postgresql/flexible-server/)\n- Log analytics: Pay-as-you-go tier. Costs based on data ingested. [Pricing](https://azure.microsoft.com/pricing/details/monitor/)\n\n⚠️ To avoid unnecessary costs, remember to take down your app if it's no longer in use,\neither by deleting the resource group in the Portal or running `azd down`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpamelafox%2Fflask-db-quiz-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpamelafox%2Fflask-db-quiz-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpamelafox%2Fflask-db-quiz-example/lists"}