Tips¶
Project structure¶
If you want to use
SQLModel for Python database interaction (ORM)
Pydantic for data validation
PostgreSQL for data storage
the data structure could look like this:
fastapi-example
├── LICENSE
├── README.rst
├── alembic.ini
└── app
├── __init__.py
├── alembic
│ ├── README
│ ├── env.py
│ ├── script.py.mako
│ └── versions
│ └── 3512b954651e_initialize_models.py
├── api
│ ├── __init__.py
│ ├── deps.py
│ ├── main.py
│ └── routes
│ ├── __init__.py
│ ├── items.py
│ └── utils.py
├── core
│ ├── __init__.py
│ ├── config.py
│ └── db.py
├── crud.py
├── main.py
├── models.py
├── tests
│ ├── __init__.py
│ ├── api
│ │ ├── __init__.py
│ │ └── routes
│ │ ├── __init__.py
│ │ └── test_items.py
│ ├── conftest.py
│ └── crud
│ ├── __init__.py
│ └── test_items.py
└── pyproject.toml
app/Highest level of the app, contains the FastAPI app as well as the configuration, database connection and database migration steps
app/apiThe FastAPI app
models.pyThe database model
tests/Tests outside the application code
pyproject.tomlTests outside the application code