requirements.txt file so others can reproduce the environment.

- Create and activate a Python virtual environment (
venv). - Scaffold the Flask application layout.
- Install Flask and export dependencies to
requirements.txt. - Initialize a Git repository and add a sensible
.gitignore.
1) Create and activate a virtual environment
Create a virtual environment (recommended) to isolate dependencies:2) Change into the backend project directory and scaffold the app
From your project root, switch into the backend folder. In this course the backend is calledimageoptimizer.app:
app/— application package containing blueprints, routes, models, forms, templates, etc.instance/— holds configuration that should not be checked into VCS (e.g., secret keys).run.py— simple entrypoint to start the Flask app in development.requirements.txt— pinned dependencies for reproducible installs.
Do not commit sensitive secrets (API keys, DB passwords) to the repository. Put them in
instance/config.py or use environment variables, and ensure they are excluded by your .gitignore.3) Install Flask and record dependencies
Install Flask into your activated virtual environment and export installed packages torequirements.txt:
requirements.txt might contain (versions will vary per environment):
Maintain
requirements.txt by running pip freeze > requirements.txt whenever you add or update Python packages. When collaborators or CI need to recreate the environment, they can run pip install -r requirements.txt.4) Initialize Git and add a .gitignore
Initialize a new Git repository and add a remote (example remote shown here). Then create a.gitignore so virtual environments and sensitive local files are not committed.
Initialize the repository and add the remote:
.gitignore for a Python/Flask project:
.gitignore, add and commit the initial code:
5) Next steps
- Implement Flask routes and API endpoints that the React frontend will consume (we’ll cover creating endpoints and request/response formats next).
- Add basic tests and a simple CI workflow (GitHub Actions or similar) to validate API behavior on push.
- When integrating the frontend, plan CORS, authentication, and how images are uploaded/served.
- Flask Documentation: https://flask.palletsprojects.com/
- Python venv docs: https://docs.python.org/3/library/venv.html
- Git documentation: https://git-scm.com/doc