)
    * [ Encoders - ` jsonable_encoder ` ](../../reference/encoders/)
    * [ Static Files - ` StaticFiles ` ](../../reference/staticfiles/)
    * [ Templating - ` Jinja2Templates ` ](../../reference/templating/)
    * [ Test Client - ` TestClient ` ](../../reference/testclient/)
  * [ FastAPI People  ](../../fastapi-people/)
  * [ Resources  ](../../resources/)

Resources

    * [ Full Stack FastAPI Template  ](../../project-generation/)
    * [ External Links and Articles  ](../../external-links/)
    * [ FastAPI and friends newsletter  ](../../newsletter/)
  * [ About  ](../../about/)

About

    * [ Alternatives, Inspiration and Comparisons  ](../../alternatives/)
    * [ History, Design and Future  ](../../history-design-future/)
    * [ Benchmarks  ](../../benchmarks/)
  * [ Help  ](../../help/)

Help

    * [ Help FastAPI - Get Help  ](../../help-fastapi/)
    * [ Development - Contributing  ](../../contributing/)
  * [ Release Notes  ](../../release-notes/)

Table of contents

  * An example file structure 
  * ` APIRouter `
    * Import ` APIRouter `
    * _Path operations_ with ` APIRouter `
  * Dependencies 
  * Another module with ` APIRouter `
    * Import the dependencies 
      * How relative imports work 
    * Add some custom ` tags ` , ` responses ` , and ` dependencies `
  * The main ` FastAPI `
    * Import ` FastAPI `
    * Import the ` APIRouter `
    * How the importing works 
    * Avoid name collisions 
    * Include the ` APIRouter ` s for ` users ` and ` items `
    * Include an ` APIRouter ` with a custom ` prefix ` , ` tags ` , ` responses ` , and ` dependencies `
    * Include a _path operation_
  * Check the automatic API docs 
  * Include the same router multiple times with different ` prefix `
  * Include an ` APIRouter ` in another 

  1. [ FastAPI  ](../..)
  2. [ Learn  ](../../learn/)
  3. [ Tutorial - User Guide  ](../)

#  Bigger Applications - Multiple Files  ¶

If you are building an application or a web API, it's rarely the case that you
can put everything on a single file.

**FastAPI** provides a convenience tool to structure your application while
keeping all the flexibility.

Info

If you come from Flask, this would be the equivalent of Flask's Blueprints.

##  An example file structure  ¶

Let's say you have a file structure like this:

    
    
    .
    ├── app
    │   ├── __init__.py
    │   ├── main.py
    │   ├── dependencies.py
    │   └── routers
    │   │   ├── __init__.py
    │   │   ├── items.py
    │   │   └── users.py
    │   └── internal
    │       ├── __init__.py
    │       └── admin.py
    

Tip

There are several ` __init__.py ` files: one in each directory or
subdirectory.

This is what allows importing code from one file into another.

For example, in ` app/main.py ` you could have a line like:

    
    
    from app.routers import items
    

  * The ` app ` directory contains everything. And it has an empty file ` app/__init__.py ` , so it is a "Python package" (a collection of "Python modules"): ` app ` . 
  * It contains an ` app/main.py ` file. As it is inside a Python package (a directory with a file ` __init__.py ` ), it is a "module" of that package: ` app.main ` . 
  * There's also an ` app/dependencies.py ` file, just like ` app/main.py ` , it is a "module": ` app.dependencies ` . 
  * There's a subdirectory ` app/routers/ ` with another file ` __init__.py ` , so it's a "Python subpackage": ` app.routers ` . 
  * The file ` app/routers/items.py ` is inside a package, ` app/routers/ ` , so, it's a submodule: ` app.routers.items ` . 
  * The same with ` app/routers/users.py ` , it's another submodule: ` app.routers.users ` . 
  * There's also a subdirectory ` app/internal/ ` with another file ` __init__.py ` , so it's another "Python subpackage": ` app.internal ` . 
  * And the file ` app/internal/admin.py ` is another submodule: ` app.internal.admin ` . 

![](/img/tutorial/bigger-applications/package.svg)

The same file structure with comments: