Skip to content

Litestar Fullstack Reference Application with React, Vite, SQLAlchemy, Docker, Task Queues, and more!

License

Notifications You must be signed in to change notification settings

litestar-org/litestar-fullstack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Litestar Logo - Light Litestar Logo - Dark

Project Status
CI/CD Tests and Linting Documentation Building
Quality Coverage Quality Gate Status Maintainability Rating Reliability Rating Security Rating
Community Reddit Discord Matrix Medium Twitter Blog
Meta Litestar Project types - Mypy License - MIT Litestar Sponsors linting - Ruff code style - Black All Contributors

Litestar Fullstack Reference Application

This is a reference application that you can use to get your next Litestar application running quickly.

It contains most of the boilerplate required for a production web API with features like:

  • Latest Litestar configured with best practices
  • Integration with SQLAlchemy 2.0, SAQ (Simple Asynchronous Queue), Structlog, and Granian
  • Extends built-in Litestar click CLI
  • Frontend integrated with Vite and includes Jinja2 templates that integrate with Vite websocket/HMR support
  • Multi-stage Docker build using a minimal Python 3.12 runtime image.
    • Optional Multi-stage Distroless Docker build.
  • Pre-configured user model that includes teams and associated team roles
  • Examples of using guards for superuser and team-based auth.
  • Examples using raw SQL for more complex queries

Take what you need and adapt it to your own projects

Quick Start

To quickly get a development environment running, run the following:

make install
. .venv/bin/activate

Local Development

cp .env.local.example .env
make start-infra # this starts a database and redis instance only
# this will start the SAQ worker, Vite development process, and Litestar
uv run app run

# to stop the database and redis, run
make stop-infra

Docker

docker compose up

Details

We have documented the process to help you get the repository up and running. Check out the documentation for more information.

Command Examples

App Commands

โฏ app

 Usage: app [OPTIONS] COMMAND [ARGS]...

 Litestar CLI.

โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ --app          TEXT       Module path to a Litestar application (TEXT)       โ”‚
โ”‚ --app-dir      DIRECTORY  Look for APP in the specified directory, by adding โ”‚
โ”‚                           this to the PYTHONPATH. Defaults to the current    โ”‚
โ”‚                           working directory.                                 โ”‚
โ”‚                           (DIRECTORY)                                        โ”‚
โ”‚ --help     -h             Show this message and exit.                        โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
Using Litestar app from env: 'app.asgi:app'
Loading environment configuration from .env
โ•ญโ”€ Commands โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ assets       Manage Vite Tasks.                                              โ”‚
โ”‚ database     Manage SQLAlchemy database components.                          โ”‚
โ”‚ info         Show information about the detected Litestar app.               โ”‚
โ”‚ routes       Display information about the application's routes.             โ”‚
โ”‚ run          Run a Litestar app.                                             โ”‚
โ”‚ schema       Manage server-side OpenAPI schemas.                             โ”‚
โ”‚ sessions     Manage server-side sessions.                                    โ”‚
โ”‚ users        Manage application users and roles.                             โ”‚
โ”‚ version      Show the currently installed Litestar version.                  โ”‚
โ”‚ workers      Manage background task workers.                                 โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Database Commands

Alembic integration is built directly into the CLI under the database command.

โฏ app database
Using Litestar app from env: 'app.asgi:create_app'

 Usage: app database [OPTIONS] COMMAND [ARGS]...

 Manage SQLAlchemy database components.

โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ --help  -h    Show this message and exit.                                    โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ•ญโ”€ Commands โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ downgrade              Downgrade database to a specific revision.            โ”‚
โ”‚ init                   Initialize migrations for the project.                โ”‚
โ”‚ make-migrations        Create a new migration revision.                      โ”‚
โ”‚ merge-migrations       Merge multiple revisions into a single new revision.  โ”‚
โ”‚ show-current-revision  Shows the current revision for the database.          โ”‚
โ”‚ stamp-migration        Mark (Stamp) a specific revision as current without   โ”‚
โ”‚                        applying the migrations.                              โ”‚
โ”‚ upgrade                Upgrade database to a specific revision.              โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Upgrading the Database

โฏ app database upgrade
Using Litestar app from env: 'app.asgi:create_app'
Starting database upgrade process โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Are you sure you you want migrate the database to the "head" revision? [y/n]: y
2023-10-01T19:44:13.536101Z [debug    ] Using selector: EpollSelector
2023-10-01T19:44:13.623437Z [info     ] Context impl PostgresqlImpl.
2023-10-01T19:44:13.623617Z [info     ] Will assume transactional DDL.
2023-10-01T19:44:13.667920Z [info     ] Running upgrade  -> c3a9a11cc35d, init
2023-10-01T19:44:13.774932Z [debug    ] new branch insert c3a9a11cc35d
2023-10-01T19:44:13.783804Z [info     ] Pool disposed. Pool size: 5  Connections
 in pool: 0 Current Overflow: -5 Current Checked out connections: 0
2023-10-01T19:44:13.784013Z [info     ] Pool recreating

Worker Commands

โฏ app worker
Using Litestar app from env: 'app.asgi:create_app'

 Usage: app worker [OPTIONS] COMMAND [ARGS]...

 Manage application background workers.

โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ --help  -h    Show this message and exit.                                    โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ•ญโ”€ Commands โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ run       Starts the background workers.                                     โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Run Commands

To run the application through Granian (HTTP1 or HTTP2) using the standard Litestar CLI, you can use the following:

โฏ app run --help
Using Litestar app from env: 'app.asgi:app'
Loading environment configuration from .env

 Usage: app run [OPTIONS]

 Run a Litestar app.
 The app can be either passed as a module path in the form of <module
 name>.<submodule>:<app instance or factory>, set as an environment variable
 LITESTAR_APP with the same format or automatically discovered from one of
 these canonical paths: app.py, asgi.py, application.py or app/__init__.py.
 When auto-discovering application factories, functions with the name
 ``create_app`` are considered, or functions that are annotated as returning a
 ``Litestar`` instance.

โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ --port                   -p  INTEGER                 Serve under this port   โ”‚
โ”‚                                                      (INTEGER)               โ”‚
โ”‚                                                      [default: 8000]         โ”‚
โ”‚ --wc,--web-concurrencyโ€ฆ  -W  INTEGER RANGE           The number of processes โ”‚
โ”‚                              [1<=x<=7]               to start.               โ”‚
โ”‚                                                      (INTEGER RANGE)         โ”‚
โ”‚                                                      [default: 1; 1<=x<=7]   โ”‚
โ”‚ --threads                    INTEGER RANGE [x>=1]    The number of threads.  โ”‚
โ”‚                                                      (INTEGER RANGE)         โ”‚
โ”‚                                                      [default: 1; x>=1]      โ”‚
โ”‚ --blocking-threads           INTEGER RANGE [x>=1]    The number of blocking  โ”‚
โ”‚                                                      threads.                โ”‚
โ”‚                                                      (INTEGER RANGE)         โ”‚
โ”‚                                                      [default: 1; x>=1]      โ”‚
โ”‚ --threading-mode             THREADMODES             Threading mode to use.  โ”‚
โ”‚                                                      (THREADMODES)           โ”‚
โ”‚ --http                       HTTPMODES               HTTP Version to use     โ”‚
โ”‚                                                      (HTTP or HTTP2)         โ”‚
โ”‚                                                      (HTTPMODES)             โ”‚
โ”‚ --opt                                                Enable additional event โ”‚
โ”‚                                                      loop optimizations      โ”‚
โ”‚ --backlog                    INTEGER RANGE [x>=128]  Maximum number of       โ”‚
โ”‚                                                      connections to hold in  โ”‚
โ”‚                                                      backlog.                โ”‚
โ”‚                                                      (INTEGER RANGE)         โ”‚
โ”‚                                                      [default: 1024; x>=128] โ”‚
โ”‚ --host                   -H  TEXT                    Server under this host  โ”‚
โ”‚                                                      (TEXT)                  โ”‚
โ”‚                                                      [default: 127.0.0.1]    โ”‚
โ”‚ --ssl-keyfile                FILE                    SSL key file (FILE)     โ”‚
โ”‚ --ssl-certificate            FILE                    SSL certificate file    โ”‚
โ”‚                                                      (FILE)                  โ”‚
โ”‚ --create-self-signed-cโ€ฆ                              If certificate and key  โ”‚
โ”‚                                                      are not found at        โ”‚
โ”‚                                                      specified locations,    โ”‚
โ”‚                                                      create a self-signed    โ”‚
โ”‚                                                      certificate and a key   โ”‚
โ”‚ --http1-buffer-size          INTEGER RANGE           Set the maximum buffer  โ”‚
โ”‚                              [x>=8192]               size for HTTP/1         โ”‚
โ”‚                                                      connections             โ”‚
โ”‚                                                      (INTEGER RANGE)         โ”‚
โ”‚                                                      [default: 417792;       โ”‚
โ”‚                                                      x>=8192]                โ”‚
โ”‚ --http1-keep-alive/--nโ€ฆ                              Enables or disables     โ”‚
โ”‚                                                      HTTP/1 keep-alive       โ”‚
โ”‚                                                      [default:               โ”‚
โ”‚                                                      http1-keep-alive]       โ”‚
โ”‚ --http1-pipeline-flushโ€ฆ                              Aggregates HTTP/1       โ”‚
โ”‚                                                      flushes to better       โ”‚
โ”‚                                                      support pipelined       โ”‚
โ”‚                                                      responses               โ”‚
โ”‚                                                      (experimental)          โ”‚
โ”‚ --http2-adaptive-windoโ€ฆ                              Sets whether to use an  โ”‚
โ”‚                                                      adaptive flow control   โ”‚
โ”‚                                                      for HTTP2               โ”‚
โ”‚ --http2-initial-connecโ€ฆ      INTEGER                 Sets the max            โ”‚
โ”‚                                                      connection-level flow   โ”‚
โ”‚                                                      control for HTTP2       โ”‚
โ”‚                                                      (INTEGER)               โ”‚
โ”‚ --http2-initial-streamโ€ฆ      INTEGER                 Sets the                โ”‚
โ”‚                                                      `SETTINGS_INITIAL_WINDโ€ฆ โ”‚
โ”‚                                                      option for HTTP2        โ”‚
โ”‚                                                      stream-level flow       โ”‚
โ”‚                                                      control                 โ”‚
โ”‚                                                      (INTEGER)               โ”‚
โ”‚ --http2-keep-alive-intโ€ฆ      OPTIONAL                Sets an interval for    โ”‚
โ”‚                                                      HTTP2 Ping frames       โ”‚
โ”‚                                                      should be sent to keep  โ”‚
โ”‚                                                      a connection alive      โ”‚
โ”‚                                                      (OPTIONAL)              โ”‚
โ”‚ --http2-keep-alive-timโ€ฆ      INTEGER                 Sets a timeout for      โ”‚
โ”‚                                                      receiving an            โ”‚
โ”‚                                                      acknowledgement of the  โ”‚
โ”‚                                                      HTTP2 keep-alive ping   โ”‚
โ”‚                                                      (INTEGER)               โ”‚
โ”‚ --http2-max-concurrentโ€ฆ      INTEGER                 Sets the                โ”‚
โ”‚                                                      SETTINGS_MAX_CONCURRENโ€ฆ โ”‚
โ”‚                                                      option for HTTP2        โ”‚
โ”‚                                                      connections             โ”‚
โ”‚                                                      (INTEGER)               โ”‚
โ”‚ --http2-max-frame-size       INTEGER                 Sets the maximum frame  โ”‚
โ”‚                                                      size to use for HTTP2   โ”‚
โ”‚                                                      (INTEGER)               โ”‚
โ”‚ --http2-max-headers-siโ€ฆ      INTEGER                 Sets the max size of    โ”‚
โ”‚                                                      received header frames  โ”‚
โ”‚                                                      (INTEGER)               โ”‚
โ”‚ --http2-max-send-buffeโ€ฆ      INTEGER                 Set the maximum write   โ”‚
โ”‚                                                      buffer size for each    โ”‚
โ”‚                                                      HTTP/2 stream           โ”‚
โ”‚                                                      (INTEGER)               โ”‚
โ”‚ --url-path-prefix            TEXT                    URL path prefix the app โ”‚
โ”‚                                                      is mounted on           โ”‚
โ”‚                                                      (TEXT)                  โ”‚
โ”‚ --debug                  -d                          Run app in debug mode   โ”‚
โ”‚ --pdb,--use-pdb          -P                          Drop into PDB on an     โ”‚
โ”‚                                                      exception               โ”‚
โ”‚ --respawn-failed-workeโ€ฆ                              Enable workers respawn  โ”‚
โ”‚                                                      on unexpected exit      โ”‚
โ”‚ --reload                 -r                          Reload server on        โ”‚
โ”‚                                                      changes                 โ”‚
โ”‚ --help                   -h                          Show this message and   โ”‚
โ”‚                                                      exit.                   โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ