Getting started¶
Prerequisites¶
Install the CLI¶
This installs two commands: bluefox and bfx (a shorter alias).
Create a project¶
This will:
- Create the
myapp/directory with all project files - Run
uv initto set up the Python project - Run
uv add bluefox-core>=0.4.0 bluefox-auth>=0.9.0 bluefox-components alembic asyncpgfor runtime dependencies - Run
uv add --dev bluefox-test pytestfor test dependencies
Generate the initial migration¶
The generated project includes models from both bluefox-auth (users, sessions) and the example items/ module. Generate a migration before starting the app:
This spins up a temporary Postgres container, runs Alembic autogenerate to detect all model tables, and stops the container. The migration file is written to migrations/versions/.
Start developing¶
Docker Compose starts Postgres, Redis, runs Alembic migrations, and launches the FastAPI app with --reload. Visit http://localhost:8000 to see the interactive welcome page with system status, a message playground, and an auth panel where you can register and log in.
Project structure¶
myapp/
main.py # App factory with auth (welcome=True)
models.py # Root-level models (auto-discovered)
items/ # Example module (auto-discovered)
__init__.py
api.py # Router → auto-mounted at /items
models.py # Item model → auto-discovered
.env # Dev environment variables
.env.example # Template for production
Makefile # Dev workflow commands
Dockerfile # Multi-stage production build
docker-compose.yml # Production compose
docker-compose.dev.yml # Dev compose (Postgres + Redis)
alembic.ini # Migration config
migrations/
env.py # One-line Alembic setup
script.py.mako # Migration file template
versions/ # Migration files
tests/
conftest.py # Test fixtures
test_health.py # Smoke test
test_items.py # Auth-protected endpoint tests
pyproject.toml # Dependencies
Auto-discovery¶
bluefox-core automatically discovers your code by convention:
- Models: any
models.pyor*/models.pyfile is imported, registering tables inBluefoxBase.metadata - Routers: any
api.pyor*/api.pyfile with arouter = APIRouter()is mounted at/{dirname}
No manual imports or registration needed. Just create a module directory, add api.py and/or models.py, and it works.
Authentication¶
The generated app includes bluefox-auth out of the box. The welcome page has a built-in auth panel where you can register users and log in. Auth endpoints are available at:
POST /auth/register— create a new userPOST /auth/login— log in (returns JWT + sets cookie)POST /auth/logout— log outGET /auth/me— get current user
Run tests¶
Tests use bluefox-test with real Postgres via testcontainers. Each test runs inside a SAVEPOINT — no cleanup needed. You can also use make test as a shortcut.
The generated test_items.py includes three tests out of the box:
- Public endpoint —
GET /items/returns 200 - Auth required —
GET /items/mereturns 401 without a token - Authenticated flow — registers a user, logs in, and accesses the protected endpoint with a Bearer token
Next steps¶
- Add a new module: create
users/api.pywith arouterandusers/models.py— they're auto-discovered - See Generated files for details on each file
- See CLI commands for all available commands
- See Deployment for deploying with Bluefox Cloud