Project structure

FastAPI project structure.

FastAPI leaves the layout to you. Most projects that grow past one file end up with the same shape: an app package, one router per area, shared dependencies, models and settings. This page lays it out, then shows the official full-stack template mapped by Nodeway.

Free to start. macOS (Apple silicon and Intel), Windows and Linux.

The conventional layout

Close to the structure in the FastAPI documentation, with the parts most projects add:

  • app/A Python package, so its modules can import each other.
  • main.pyCreates FastAPI() and includes the routers.
  • dependencies.pyShared dependencies, such as the current user or a database session.
  • routers/One APIRouter per area, each with its path operations.
  • users.py, items.py@router.get, @router.post and the rest.
  • models.pyDatabase models, for example with SQLModel or SQLAlchemy.
  • core/config.pySettings read from the environment.
  • alembic/Database migrations, when the project uses Alembic.
  • tests/Tests, often with FastAPI's TestClient.
  • pyproject.tomlDependencies and tool settings.

Habits that keep it readable

  • Keep path operations thin. Put database work in its own module (a crud.py or a services package) so routes read as a list of endpoints.
  • Pass shared things in with Depends rather than importing globals, so each route says what it needs.
  • Give each router a prefix and tags in one place, where it is included, so URLs are easy to find.

A real example: Full Stack FastAPI Template

fastapi/full-stack-fastapi-template is a full-stack web app template with a FastAPI backend and a React frontend. Nodeway mapped it at commit f8c6c14, from 26 November 2026. Most of it is TypeScript: 96 files of 132, followed by Python (28) and Shell (8).

The backend lives under backend/app, with its routers in api/routes, and the React frontend under frontend.

Source files
132
Functions and classes
349
Confirmed calls
257
Routes
23
Tables
2

Its folders

  • frontend/package88 files
  • src/85 files
  • backend/package30 files23 routes · 2 tables
  • app/package25 files23 routes · 2 tables
  • scripts/5 files
  • packages/react-email/package8 files
  • ui/5 files
  • emails/3 files
  • scripts/5 files
  • hooks/1 file

Routes

Nodeway found 23 routes and linked 23 to the function that handles them. They by HTTP method: POST 10, GET 6, DELETE 3, PATCH 3, PUT 1. All are under backend/app (23).

Some of them

RouteMethod
/api/v1/itemsread_items · backend/app/api/routes/items.pyGET
/api/v1/usersread_users · backend/app/api/routes/users.pyGET
/api/v1/private/userscreate_user · backend/app/api/routes/private.pyPOST
/api/v1/reset-passwordreset_password · backend/app/api/routes/login.pyPOST
/api/v1/utils/test-emailtest_email · backend/app/api/routes/utils.pyPOST
/api/v1/itemscreate_item · backend/app/api/routes/items.pyPOST
/api/v1/userscreate_user · backend/app/api/routes/users.pyPOST
/api/v1/users/meread_user_me · backend/app/api/routes/users.pyGET

Data model

Nodeway found 2 database tables, defined with SQLModel. Code in the repository reads or writes 2 of them. The most used:

TableUsed by
user2 columns · backend/app/models.py5 read2 write
item3 columns · backend/app/models.py2 read3 write

The full map, with its entry points, a traced request and the most-called code, is on the Full Stack FastAPI Template architecture page.

See your own project's structure

Nodeway reads a FastAPI project on your own computer and draws its folders, files, functions, routes and tables, with the imports and calls between them. Open a folder and the map is drawn locally; nothing is uploaded. The getting started guide covers installing it, and the repo maps show 31 open-source projects mapped the same way.

Questions

How do I split a FastAPI app into several files?

Give each area its own APIRouter in its own module, such as routers/users.py, and add them to the app in main.py with app.include_router. A router can carry its own prefix, tags and dependencies.

Where should database models go in FastAPI?

FastAPI does not decide. Small projects keep them in one models.py; larger ones use a models package. Request and response shapes, such as Pydantic models, often sit beside them or in a schemas module.

Does FastAPI need a specific folder structure?

No. Any layout works as long as Python can import it. The layout in the FastAPI documentation's Bigger Applications chapter is a common starting point.

See your whole codebase in minutes.

Open a folder and Nodeway maps it on your own computer. No account, and nothing is uploaded.

More guides