Skip to main content
In this lesson we’ll prepare the project structure for the Image Optimizer application: a Flask backend and a React frontend. We’ll scaffold a simple Flask backend, create recommended directories and files, initialize a Git repository, and generate a requirements.txt file so others can reproduce the environment.
A presentation slide titled "Setting up our Project Structure" with the word "Demo" in large blue text on a dark curved shape to the right. The slide has a light background and a small "© Copyright KodeKloud" note in the bottom left.
Overview — what we’ll do
  • 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.
Quick checklist

1) Create and activate a virtual environment

Create a virtual environment (recommended) to isolate dependencies:
Optional: verify the Python REPL briefly:
Keeping your dependencies isolated with a virtual environment prevents version conflicts when running or deploying the app.

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 called imageoptimizer.app:
Create the recommended directory layout and files. You can create directories and files manually, or run the following to scaffold everything at once:
A typical Flask-style layout we’re following looks like this:
Notes on files/folders
  • 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 to requirements.txt:
A minimal example of what 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:
Example .gitignore for a Python/Flask project:
After creating .gitignore, add and commit the initial code:
If the remote already has commits and your push is rejected, pull remote changes first using rebase and then push:

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.
References and further reading That’s it — the project structure and repository are ready. In the next lesson we’ll build the Flask API endpoints and wire them up to the React frontend.

Watch Video