What You Will Build
By the end of this tutorial you will have a production-ready FastAPI codebase for a B2B SaaS, generated from a one-paragraph description. The generated app includes:
- Async end-to-end —
async defroute handlers, async SQLAlchemy 2.0 sessions - Pydantic v2 schemas for every request and response
- JWT authentication with httpOnly cookies (not localStorage)
- Organisation-scoped multi-tenancy — every query filtered by
org_idat the session layer - Automatic interactive OpenAPI docs at
/docs(Swagger UI) and/redoc - Alembic migrations for every model
- A working
docker-compose.yml
You will not hand-write a single Pydantic model or wire a single dependency. Archiet generates it from your requirements.
Prerequisites
- An Archiet account (free at archiet.com/register)
- Docker installed locally
- 10 minutes
Step 1: Write a Minimal PRD
You do not need a long document. A paragraph is enough:
DealDesk is a B2B SaaS for sales teams to track deals. Teams (organisations)
sign up and invite members. Each member creates deals with a name, value,
stage (lead / qualified / won / lost), and owner. Only members of an
organisation can see that organisation's deals. We need registration, login,
email verification, and forgot-password. The API will be consumed by a
separate frontend and a mobile app, so it must be a clean JSON API.
Archiet extracts the entities (Organisation, User, Deal), the relationships, the auth requirements, and the "clean JSON API" constraint that makes FastAPI a natural fit.
Step 2: Open the Blueprint Wizard
- Log in at archiet.com/login
- Click New Blueprint
- Paste your PRD text
- Click Analyse — Archiet shows the proposed model: entities Organisation, User, Deal; JWT auth with email verification; a JSON-API surface.
Review the model and correct anything before generating.
Step 3: Choose FastAPI
On the Generate screen:
- Stack: select FastAPI
- Compliance overlays: check SOC 2 Starter if you want access-control logging and an audit-trail model
- Click Generate
Generation runs for 60–90 seconds through a deterministic pipeline — the same PRD always produces the same code.
Step 4: What You Get
Download and unzip:
dealdesk/
├── app/
│ ├── main.py # FastAPI app + router registration
│ ├── api/
│ │ ├── deps.py # get_current_user, get_db dependencies
│ │ └── routes/
│ │ ├── auth.py
│ │ └── deals.py
│ ├── models/ # SQLAlchemy 2.0 ORM models
│ │ ├── organisation.py
│ │ ├── user.py
│ │ └── deal.py
│ └── schemas/ # Pydantic v2 schemas
│ ├── deal.py
│ └── user.py
├── alembic/ # migrations
├── docker-compose.yml
├── .env.example
└── openapi.json # generated OpenAPI 3.1 spec
The Pydantic schema and the async route read like idiomatic FastAPI:
# app/schemas/deal.py
from pydantic import BaseModel, ConfigDict
from enum import Enum
class DealStage(str, Enum):
lead = "lead"
qualified = "qualified"
won = "won"
lost = "lost"
class DealCreate(BaseModel):
name: str
value: float
stage: DealStage = DealStage.lead
class DealRead(DealCreate):
model_config = ConfigDict(from_attributes=True)
id: str
org_id: str
# app/api/routes/deals.py
@router.get("/deals", response_model=list[DealRead])
async def list_deals(
db: AsyncSession = Depends(get_db),
user: User = Depends(get_current_user),
):
result = await db.execute(
select(Deal).where(Deal.org_id == user.org_id)
)
return result.scalars().all()
Note the where(Deal.org_id == user.org_id) — multi-tenancy is enforced in the query, not hoped for in the UI.
Step 5: Run It Locally
cd dealdesk
cp .env.example .env
docker compose up -d
Open http://localhost:8000/docs. Every endpoint is documented with request and response schemas generated from your Pydantic models. Register an account, authenticate, and try the deals endpoints directly from Swagger UI.
What to Do Next
Extend with your AI editor: drop the generated ARCHITECTURE.md into Cursor or Copilot context. Because the app is fully typed (Pydantic + SQLAlchemy 2.0 typed models), your editor's suggestions are checked against real types.
Add async background work: FastAPI pairs naturally with async task queues. The generated structure leaves a clean seam for adding Celery or arq workers.
Other Python stacks: FastAPI is Archiet's recommended Python stack for API-first and AI/ML teams. If you want a batteries-included web framework with an admin, generate the same PRD as Django. For a microframework, choose Flask.
The DELIVERY_RECEIPT.md in the ZIP lists every generated file with its quality score. Any file flagged below threshold is named there with the reason.