Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ fastapi-craft

A CLI scaffolding tool for FastAPI + SQLModel projects. Stop writing boilerplate — generate models, services, and routers in one command.

craft make:crud User
app/
  models/user.py           ← SQLModel table + Pydantic schemas
  services/user_services.py ← OOP service with business logic
  routers/user_router.py   ← Clean FastAPI router

Installation

With uv (recommended)

# Install globally as a tool
uv tool install git+https://github.com/Mroshan15200/fastapi-craft

# Or add to your project
uv add git+https://github.com/Mroshan15200/fastapi-craft

With pip

pip install git+https://github.com/Mroshan15200/fastapi-craft

Once installed, the craft command is available anywhere.


Commands

make:crud — Full CRUD scaffold

Generates a model, service, and router for a resource.

craft make:crud User
craft make:crud Product --force        # overwrite existing files
craft make:crud Order --no-router      # skip router generation

Generated files:

app/models/user.py

class UserBase(SQLModel): ...          # shared fields
class User(UserBase, table=True): ...  # DB table
class UserCreate(UserBase): ...
class UserUpdate(SQLModel): ...
class UserResponse(UserBase): ...

app/services/user_services.py

class UserService:
    def get(self, db, user_id) -> User: ...
    def get_all(self, db, skip, limit) -> List[User]: ...
    def create(self, db, data) -> User: ...
    def update(self, db, user_id, data) -> User: ...
    def delete(self, db, user_id) -> None: ...

user_service = UserService()

app/routers/user_router.py

GET    /users/list all
GET    /users/{id}    → get one
POST   /users/create
PUT    /users/{id}    → update
DELETE /users/{id}    → delete

Then register in main.py:

from app.routers.user_router import router as users_router
app.include_router(users_router)

make:model — Model only

Generates just the model file when you don't need a full CRUD setup.

craft make:model Tag
craft make:model AuditLog --no-schemas   # table only, no Create/Update/Response

make:service — Standalone service

Generates a service file for non-CRUD logic.

craft make:service Auth --type auth
craft make:service Recommender --type ml
craft make:service Email                  # generic (default)
Type What you get
auth hash_password, verify_password, create_access_token, create_refresh_token, decode_token, get_current_user dependency
ml load(model_path), predict(inputs), health()
generic Clean class shell with a run() stub

Auth service — protecting routes

After running craft make:service Auth --type auth:

  1. Uncomment the User import at the top of auth_service.py
  2. Uncomment get_current_user()
  3. Use it in any router:
from app.services.auth_service import get_current_user

@router.get("/me")
def get_me(current_user: User = Depends(get_current_user)):
    return current_user

@router.delete("/{id}")
def delete_item(id: int, current_user: User = Depends(get_current_user), db: Session = Depends(get_db)):
    ...

All options

Flag Commands Description
--force all Overwrite existing files
--no-router make:crud Skip router generation
--no-schemas make:model Skip Create/Update/Response schemas
--type make:service auth | ml | generic

Expected project structure

craft assumes your project looks like this:

your-project/
├── app/
│   ├── database.py        ← Session / get_db dependency
│   ├── models/
│   ├── services/
│   └── routers/
├── main.py
└── pyproject.toml

app/database.py should expose a get_db dependency:

from sqlmodel import Session, create_engine

engine = create_engine("sqlite:///db.sqlite3")

def get_db():
    with Session(engine) as session:
        yield session

Tech stack of generated code

  • FastAPI — web framework
  • SQLModel — ORM + Pydantic schemas in one
  • uv — package manager (recommended)

Contributing

PRs welcome! To work on craft locally:

git clone https://github.com/Mroshan15200/fastapi-craft
cd fastapi-craft
uv sync
uv run craft --help

License

MIT

About

CLI scaffolding for FastAPI + SQLModel projects

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages