Metadata-Version: 2.4
Name: fastapi-prod
Version: 1.0.0
Summary: Production-ready FastAPI backend project generator (django-admin / nest / rails new, for FastAPI)
Project-URL: Homepage, https://github.com/tarunkumarhp72/fastapi-prod
Project-URL: Repository, https://github.com/tarunkumarhp72/fastapi-prod
Author: Tarun Kumar
License: MIT
License-File: LICENSE
Keywords: boilerplate,cli,fastapi,generator,project-generator,scaffold
Classifier: Environment :: Console
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Code Generators
Requires-Python: >=3.10
Requires-Dist: jinja2>=3.1.0
Requires-Dist: questionary>=2.0.0
Requires-Dist: rich>=13.0.0
Requires-Dist: typer>=0.12.0
Description-Content-Type: text/markdown

# fastapi-prod

A production-ready FastAPI backend **project generator** — like `django-admin startproject`, `nest new`, `ng new`, or `rails new`, but for FastAPI.

`fastapi-prod` is not a template you clone. It's a CLI you install once, and reuse to scaffold every new FastAPI service with a consistent, production-grade architecture.

## Install

With `pip`:

```bash
pip install fastapi-prod
```

With `uv`:

```bash
uv add fastapi-prod
# or, to just run it without adding it as a project dependency:
uvx fastapi-prod create ecommerce
```

## Usage

```bash
fastapi-prod create ecommerce
```

This launches an interactive wizard:

```
Project name: ecommerce
Database: PostgreSQL / MySQL / SQLite
Use Redis? (Y/N)
Use Celery? (Y/N)
Use Docker? (Y/N)
```

All options can also be passed as flags, skipping the corresponding prompt:

```bash
fastapi-prod create ecommerce --database postgres --redis --celery --docker
fastapi-prod create internal_tool --database sqlite --no-redis --no-celery --no-docker
```

Once generated:

```bash
cd ecommerce
cp .env.example .env

# with Docker
docker compose up --build

# without Docker (pip)
pip install -e ".[dev]"
alembic revision --autogenerate -m "init"
alembic upgrade head
uvicorn app.main:app --reload

# without Docker (uv)
uv pip install -e ".[dev]"
uv run alembic revision --autogenerate -m "init"
uv run alembic upgrade head
uv run uvicorn app.main:app --reload
```

## What you get

- **Layered architecture**: `Route -> Service -> Repository -> Database`. Routes never touch the database directly.
- **FastAPI** app factory with lifespan events, request logging middleware, and a centralized exception handler.
- **SQLAlchemy 2.x** (async) + **Alembic** (async migrations), pre-wired for PostgreSQL, MySQL, or SQLite.
- **Pydantic Settings** based configuration, loaded from `.env`.
- A working `GET /health` endpoint and a full sample CRUD resource (model, schema, repository, service, routes) to copy for your own resources.
- Optional **Redis** client, optional **Celery** worker (Redis-backed), optional **Docker** + `docker-compose.yml` — only generated when you opt in.
- `pytest` test suite, `ruff` / `black` / `isort` / `mypy` configuration, and a `Makefile` with `run`, `test`, `lint`, `format`, `revision`, `migrate`.

## Developing this package locally

Clone the repo, then install it in editable mode so `fastapi-prod` picks up code changes immediately.

### With pip

```bash
git clone https://github.com/tarunkumarhp72/fastapi-prod.git
cd fastapi-prod
python -m venv venv
venv\Scripts\activate        # Windows
# source venv/bin/activate   # macOS/Linux
pip install -e .
```

### With uv

```bash
git clone https://github.com/tarunkumarhp72/fastapi-prod.git
cd fastapi-prod
uv venv
uv pip install -e .
# or skip the venv step entirely and just:
uv run fastapi-prod --help
```

### Verifying the install actually works

```bash
# CLI is on PATH and importable
fastapi-prod --help

# generate a throwaway project
fastapi-prod create smoke_test --database sqlite --no-redis --no-celery --no-docker

# prove the generated project itself is valid
cd smoke_test
cp .env.example .env
pip install -e ".[dev]"        # or: uv pip install -e ".[dev]"
python -m pytest -v            # should show 1 passed (test_health.py)
alembic revision --autogenerate -m "init"
alembic upgrade head
uvicorn app.main:app --reload
```

Then visit `http://127.0.0.1:8000/docs` and `http://127.0.0.1:8000/api/v1/health`.

## Architecture of this package

```
src/fastapi_prod/
  cli/            # Typer commands (create.py, main.py)
  config/         # ProjectConfig — the single source of truth for a generation run
  prompts/        # Interactive wizard
  generators/     # One generator per concern: project (core), redis, celery, docker
  renderers/      # Jinja2 rendering
  utils/          # Generic template-tree file writer, shared errors/paths
  templates/
    base/         # Always generated (core FastAPI app, DB-agnostic)
    redis/        # Only rendered if Redis is selected
    celery/       # Only rendered if Celery is selected
    docker/       # Only rendered if Docker is selected
```

Every generator implements the same tiny `BaseGenerator.generate(context)` interface, and all of them reuse a single generic `render_template_tree()` helper. Adding a new optional feature later (auth, email, websockets, RabbitMQ, Kafka, monitoring, ...) means adding a new template folder + a new generator + a new CLI command — no existing generator or template needs to change.

## Roadmap

`fastapi-prod create` is the only command in v1.0. Future versions add `fastapi-prod add <feature>` commands (auth, email, websocket, rabbitmq, kafka, monitoring, sentry, aws, kubernetes) on top of the same architecture, without breaking v1 projects.

## License

MIT
