{"id":23391485,"url":"https://github.com/uj5ghare/flask-twotier-app","last_synced_at":"2026-05-06T04:05:40.352Z","repository":{"id":209466441,"uuid":"720052560","full_name":"Uj5Ghare/Flask-Twotier-App","owner":"Uj5Ghare","description":"Two tier application with Python:3.9-slim \u0026 mysql:5.7","archived":false,"fork":false,"pushed_at":"2024-02-28T15:35:25.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T11:22:23.672Z","etag":null,"topics":["docker","docker-compose","flask","mysql"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Uj5Ghare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-11-17T13:31:45.000Z","updated_at":"2024-11-03T07:00:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"c3c15258-b5c3-4ffb-9b84-80ac6114486e","html_url":"https://github.com/Uj5Ghare/Flask-Twotier-App","commit_stats":null,"previous_names":["uj5ghare/flask-twotier-app"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Uj5Ghare%2FFlask-Twotier-App","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Uj5Ghare%2FFlask-Twotier-App/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Uj5Ghare%2FFlask-Twotier-App/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Uj5Ghare%2FFlask-Twotier-App/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Uj5Ghare","download_url":"https://codeload.github.com/Uj5Ghare/Flask-Twotier-App/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247866130,"owners_count":21009238,"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","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":["docker","docker-compose","flask","mysql"],"created_at":"2024-12-22T04:17:49.765Z","updated_at":"2026-05-06T04:05:40.298Z","avatar_url":"https://github.com/Uj5Ghare.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":" \n# Flask App with MySQL Docker Setup\n\nThis is a simple Flask app that interacts with a MySQL database. The app allows users to submit messages, which are then stored in the database and displayed on the frontend.\n\n## Prerequisites\n\nBefore you begin, make sure you have the following installed:\n\n- Docker\n- Git (optional, for cloning the repository)\n\n## Setup\n\n1. Clone this repository (if you haven't already):\n\n   ```bash\n   git clone https://github.com/your-username/your-repo-name.git\n   ```\n\n2. Navigate to the project directory:\n\n   ```bash\n   cd your-repo-name\n   ```\n\n3. Create a `.env` file in the project directory to store your MySQL environment variables:\n\n   ```bash\n   touch .env\n   ```\n\n4. Open the `.env` file and add your MySQL configuration:\n\n   ```\n   MYSQL_HOST=mysql\n   MYSQL_USER=your_username\n   MYSQL_PASSWORD=your_password\n   MYSQL_DB=your_database\n   ```\n\n## Usage\n\n1. Start the containers using Docker Compose:\n\n   ```bash\n   docker-compose up --build\n   ```\n\n2. Access the Flask app in your web browser:\n\n   - Frontend: http://localhost\n   - Backend: http://localhost:5000\n\n3. Create the `messages` table in your MySQL database:\n\n   - Use a MySQL client or tool (e.g., phpMyAdmin) to execute the following SQL commands:\n   \n     ```sql\n     CREATE TABLE messages (\n         id INT AUTO_INCREMENT PRIMARY KEY,\n         message TEXT\n     );\n     ```\n\n4. Interact with the app:\n\n   - Visit http://localhost to see the frontend. You can submit new messages using the form.\n   - Visit http://localhost:5000/insert_sql to insert a message directly into the `messages` table via an SQL query.\n\n## Cleaning Up\n\nTo stop and remove the Docker containers, press `Ctrl+C` in the terminal where the containers are running, or use the following command:\n\n```bash\ndocker-compose down\n```\n\n## To run this two-tier application using  without docker-compose\n\n- First create a docker image from Dockerfile\n```bash\ndocker build -t flask .\n```\n\n- Now, make sure that you have created a network using following command\n```bash\ndocker network create net\n```\n\n- Attach both the containers in the same network, so that they can communicate with each other\n\ni) MySQL container \n```bash\ndocker run -d --name mysql --net net -e MYSQL_ROOT_PASSWORD=\"admin\" -e MYSQL_DATABASE=\"db\" -v ./message.sql:/docker-entrypoint-initdb.d/message.sql -p 3306:3306 --rm mysql:5.7\n```\nii) Backend container\n```bash\n docker run -d --name flask --net net -e MYSQL_DB=\"db\" -e MYSQL_USER=\"root\" -e MYSQL_HOST=\"mysql\" -e MYSQL_PASSWORD=\"admin\"  -p 5000:5000 flask:latest\n```\n\n## Notes\n\n- Make sure to replace placeholders (e.g., `your_username`, `your_password`, `your_database`) with your actual MySQL configuration.\n\n- This is a basic setup for demonstration purposes. In a production environment, you should follow best practices for security and performance.\n\n- Be cautious when executing SQL queries directly. Validate and sanitize user inputs to prevent vulnerabilities like SQL injection.\n\n- If you encounter issues, check Docker logs and error messages for troubleshooting.\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuj5ghare%2Fflask-twotier-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuj5ghare%2Fflask-twotier-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuj5ghare%2Fflask-twotier-app/lists"}