Managing the directory structure of a large scale FastAPI App
Abdulla Ansari
Posted on January 22, 2023
Managing the directory structure of a large scale FastAPI app can be a daunting task. However, by following a few best practices and conventions, it is possible to keep your app organised and easy to maintain. In this article, we will discuss some tips and strategies for managing the directory structure of a large scale FastAPI app.
- Use a consistent naming convention: Consistency is key when it comes to managing a large scale app. By using a consistent naming convention, it will be easier to find and understand the different components of your app. This can include using a specific naming convention for folders, files, and even variables.
2.
Group related functionality: Grouping related functionality together in the same folder will make it easier to understand the different parts of your app. For example, you can create a folder for controllers, a folder for models, and a folder for views. This way, it will be easy to find and understand the different components of your app.
3.
Use subfolders for specific functionality: For larger apps, it is often useful to use subfolders to group related functionality. For example, you can create a folder for authentication and another folder for user management. This way, it will be easy to find and understand the different components of your app.
4.
Use a separate folder for shared code: Shared code is code that is used by multiple parts of your app. A good practice is to keep shared code in a separate folder. This way, it will be easy to find and understand the different components of your app.
5.
Use a separate folder for test code: Keeping test code in a separate folder will make it easy to find and understand the different components of your app. This way, it will be easy to find and understand the different components of your app.
6.
Keep the main file simple: The main file of your app should be kept simple. It should only contain the code necessary to run the app. This way, it will be easy to find and understand the different components of your app.
Conclusion
In conclusion, managing the directory structure of a large scale FastAPI app requires a consistent naming convention, grouping related functionality, and using subfolders for specific functionality. By following these best practices, it will be easier to find and understand the different components of your app, making it more maintainable.
Mostly Followed Structure by me#
Here "\" declares as directory.
alembic\
app\
scripts\
background-scripts\
Dockerfile
docker-compose.yml
.env
.gitignore
pytest.ini
I am not starting with alembic because it will generate automatic when you will run alembic command.
app\
__init__.py
main.py
config\
controllers\
models\
routes\
schemas\
tests\
utils\
Config Dir Structure
config\
__init__.py
env_config.py
db_config.py
general_config.py
Controllers specific to Routes
controllers\
user_controller.py
auth_controller.py
register_controller.py
...
...
etc.
Models specific
models\
model.py
user_model.py
register_model.py
...
...
etc.
Routes specific
routes\
base_routes.py
user_route.py
register_route.py
...
...
etc.
Schema specific
schema\
user_schema.py
auth_schema.py
register_schema.py
...
...
etc.
Tests specific
tests\
conftest.py
test_routes/
test_auth.py
test_register.py
...
...
etc.
Thanks for your valuable time. You can like my post and
you can.
Posted on January 22, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.