Effortlessly Start Your FastAPI Project with a Structured Boilerplate

Tejaksha K
3 min readMay 30, 2023

Introduction

Starting a new project can be overwhelming, especially when it comes to setting up the initial folder structure and organizing your codebase. In the case of a FastAPI project, having a systematic folder hierarchy can greatly enhance maintainability and development efficiency. In this blog post, we’ll explore how to quickly create a FastAPI project boilerplate with a well-defined folder structure using a simple shell script.

Getting Started with FastAPI Boilerplate

To streamline the process of setting up a structured folder hierarchy for your FastAPI project, we provide a convenient shell script. By executing this script, you’ll have the necessary folders and files in place, allowing you to dive straight into development.

Step 1: Download or Clone the Repository

Begin by downloading or cloning the project repository from the desired source. This can be achieved through the provided repository link or by using Git commands in your terminal.

Step 2: Running the Shell Script

Once you have the repository on your local machine, navigate to the project’s root directory in your terminal or command prompt. Here, you’ll find the schema.sh shell script. Execute the script by running the following command:

  • Provide the script with suitable permission
chmod +x /in/the/path/of/schema.sh 
  • RUN the sh file
./schema.sh

Sit back and relax while the script takes care of creating the necessary folders and files for your FastAPI project.

Exploring the Folder Structure

After the shell script completes its execution, you’ll have a neatly organized folder structure tailored for your FastAPI project. Let’s take a closer look at what each folder and file represents:

  • app/: This folder serves as the core of your FastAPI application, containing essential code files
  • api/: This directory houses all the API-related code, including routers and endpoints.
  • models/: Here, you'll find data models and schemas for your application.
  • services/: This folder holds services responsible for handling the business logic.
  • utils/: It contains utility functions and helper modules to assist in your development.
  • main.py: The entry point for your FastAPI application resides here.
  • tests/: This folder is dedicated to housing test cases for your application. You can use it to write unit tests and ensure the quality of your code.
  • docs/: Although optional, this folder can be utilized for storing documentation files related to your FastAPI project.
  • schema.sh: The shell script itself, responsible for automating the creation of the structured folder hierarchy.
  • info/: You can add the information about your project which will reflect in the swagger docs.

Start Developing Your FastAPI Project

With the FastAPI boilerplate in place, you’re now ready to kick-start your development journey. Open the main.py file in the app/ directory, which serves as the entry point for your FastAPI application. Explore the provided examples and refer to the generated folder structure to understand how to structure your code and create API endpoints efficiently.

Feel free to customize the generated code to fit your specific project requirements. Add additional files or folders as needed and modify the existing ones to suit your application’s architecture.

Conclusion

Setting up a well-organized folder structure is crucial for maintaining code quality and promoting collaboration within a FastAPI project. By utilizing the provided shell script, you can effortlessly generate a boilerplate that adheres to a systematic folder hierarchy. This saves you time and effort, allowing you to focus on building the core functionalities of your FastAPI application.

Get started with the FastAPI boilerplate today, and enjoy a streamlined development experience from the very beginning. Happy coding!

We hope you find this blog post helpful in your FastAPI project endeavors. If you have any questions or feedback, feel free to leave a comment below.

--

--

Tejaksha K

I'm a Full Stack Developer & Cloud Expert with experience in Google Cloud Platform & AWS. Passionate about learning & expanding my skills in Web Development.