FastAPI backend generator: schema to REST API

Auxen, by Auxen Prime, generates a FastAPI (Python) backend from your database schema or a plain-English description. The output is an ordinary FastAPI project that you download and own. Install the requirements and run it with Uvicorn.

What you get

The table is read from a real generated project (102 files for the example schema). The last column is the file in that project.

AreaWhat is generatedWhere in the project
REST APICreate, read, update and delete endpoints for each entity, under /api/<entity>app/routers/customer.py
AuthenticationRegistration and login with JWT in this example. The builder also offers OAuth2, Session, API Key, Basic Auth and OpenID Connect.app/routers/auth.py
RBACRole and permission tables, and a permission check on the protected routesapp/dependencies/rbac.py
MigrationsAn initial migration for the schemaalembic/versions/V1__initial_schema.sql
Tests3 test files in the example (unit and integration)tests/test_customer.py
DockerfileBuilds the image and runs the app as a non-root user (uid 10001)Dockerfile
docker-composeRuns the app with a PostgreSQL database beside itdocker-compose.yml
CI pipelineA GitHub Actions workflow, when you choose it.github/workflows/ci.yml
API descriptionAn OpenAPI description of the APIapp/main.py
Health checkA health endpointapp/main.py
ConfigurationAn .env.example listing the settings.env.example

The example it was generated from

Entities Customer and Invoice, with Invoice many-to-one Customer, on PostgreSQL, JWT with RBAC. Options: unit tests, integration tests, Docker, GitHub Actions pipeline and migrations. Auxen adds the authentication tables (users, roles, permissions, sessions and others) around them.

Folder layout, with file counts
.github/workflows/  1 file
alembic/versions/  1 file
app/  84 files
app/core/  2 files
app/dependencies/  3 files
app/migrations/  1 file
app/models/  14 files
app/queries/  14 files
app/repositories/  14 files
app/routers/  9 files
app/schemas/  15 files
app/seeds/  2 files
app/services/  3 files
app/utils/  4 files
docs/  2 files
tests/  5 files
(project root)  9 files

Real excerpts

A generated controller app/routers/customer.py
@router.get("/", response_model=PaginatedResponse)
@require_permission("CUSTOMER_READ")
def get_all(
    page: int = Query(1, ge=1, description="Page number"),
    limit: int = Query(20, ge=1, le=100, description="Items per page"),
    sort_by: str = Query("customer_id", description="Field to sort by"),
    sort_order: str = Query("asc", pattern="^(asc|desc)$", description="Sort order"),
    db: Session = Depends(get_db), current_user: User = Depends(get_current_user)
):
    # Get total count
    total = db.query(Customer).count()

    # Apply sorting (whitelist sort_by to prevent column injection)
    safe_sort_by = sort_by if sort_by in SORTABLE_FIELDS else "customer_id"
The RBAC check app/dependencies/rbac.py
def require_permission(permission_name: str):
    """
    Route decorator that checks the authenticated user has the given permission
    (matched by permission_name, e.g. "CUSTOMER_CREATE"); the ADMIN role bypasses.
    The wrapped handler must declare current_user + db dependencies; they're
    injected by FastAPI and read here from kwargs.

    Usage:
        @router.get("/")
        @require_permission("CUSTOMER_READ")
        async def get_all(..., db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
    """
The first migration, for Customer alembic/versions/V1__initial_schema.sql
CREATE TABLE IF NOT EXISTS "customer" (
    customer_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    customer_name VARCHAR(255) NOT NULL,
    customer_email VARCHAR(255) UNIQUE NOT NULL,
    customer_birthday DATE,
    customer_active BOOLEAN NOT NULL,
    customer_gender VARCHAR(255) NOT NULL,
    customer_notes TEXT,
    customer_created_at TIMESTAMP NOT NULL
);
The Dockerfile Dockerfile
FROM python:3.11-slim
# The root filesystem is read-only under the Helm chart: write no __pycache__.
ENV PYTHONDONTWRITEBYTECODE=1
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Run as an unprivileged user (uid and gid 10001) that owns /app.
RUN groupadd --system --gid 10001 app && useradd --system --no-create-home --gid app --uid 10001 app && chown -R app:app /app
USER 10001:10001
EXPOSE 8000
# The port: PORT when the platform sets one (Heroku, Cloud Run), else 8000.
CMD ["sh", "-c", "exec uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-8000}"]
A generated test tests/test_customer.py
class TestCustomer:
    def test_create(self, api):
        row = api.create(Customer)
        assert row["customer_id"]

    def test_list(self, api):
        row = api.create(Customer)
        res = api.get(f"{PATH}/")
        assert res.status_code == 200, res.text
        assert row["customer_id"] in [item["customer_id"] for item in res.json()["data"]]

    def test_get_by_id(self, api):

What it is built on

Read from the generated manifest: FastAPI (requirements.txt), SQLAlchemy (requirements.txt), Pydantic (requirements.txt), PyJWT (requirements.txt), pytest (requirements-dev.txt).

Databases

FastAPI generates for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, MongoDB and Amazon Redshift.

How the generator is tested

These checks live in the Auxen repository and run against the generators themselves. They are listed here as what they do, not as a guarantee about every schema you might write.

  • Generation test (npm run test:gen): generates this stack for several example schemas, then checks the syntax of the result with Python.
  • Runtime test (npm run test:runtime): starts the generated application, connects it to a real database, registers a user, logs in, then creates and lists records over HTTP.
  • Security scan: the generated project, including its Dockerfile and CI files, is scanned with Trivy for vulnerabilities, secrets and misconfiguration. The check fails on any secret, and on any high or critical finding that has a fix.
  • Docker build test (npm run test:docker, run on demand): builds each stack's own Dockerfile.

Running and deploying it

Install the requirements and run it with Uvicorn. You download the project and deploy it wherever you run software. Auxen does not deploy the generated backend for you yet. It has a hosted sandbox where you can run the code and try its API before you download it.

Review the code before it carries real traffic, as you would any code you did not write. The terms of service say the same: generated code is provided as is, and you are responsible for reviewing, testing and securing it.

More

Auxen is made by Auxen Prime Technologies Limited and lives at auxenprime.com. It is not affiliated with other companies that use the name Auxen.