|
| 1 | +# FastAPI Domain Starter |
| 2 | + |
| 3 | +Modern, domain-oriented FastAPI starter — the recommended default for |
| 4 | +medium-sized API projects. |
| 5 | + |
| 6 | +> Generated project: **<project_name>** — <description> |
| 7 | + |
| 8 | +## When to choose this starter |
| 9 | + |
| 10 | +Pick this template when you want: |
| 11 | + |
| 12 | +- A **domain-oriented layout** (one folder per business concept under |
| 13 | + `src/app/domains/`) rather than the layered `routes/ + crud/ + schemas/` |
| 14 | + split. Domains scale better as the API grows. |
| 15 | +- A clear separation between **transport** (`router.py`), **business |
| 16 | + logic** (`service.py`), and **data access** (`repository.py`) so each |
| 17 | + layer can evolve independently. |
| 18 | +- A **`pyproject.toml`-first** project (PEP 621) compatible with `uv`, |
| 19 | + `pdm`, or `poetry` out of the box — no `setup.py` to maintain. |
| 20 | +- Sensible defaults for settings, testing, formatting, and a built-in |
| 21 | + `/health` probe. |
| 22 | + |
| 23 | +If you only need a quick CRUD demo, start with `fastapi-default`. If you |
| 24 | +need PostgreSQL, start with `fastapi-psql-orm`. If you want a single-file |
| 25 | +sandbox, use `fastapi-single-module`. |
| 26 | + |
| 27 | +## Project structure |
| 28 | + |
| 29 | +``` |
| 30 | +. |
| 31 | +├── README.md |
| 32 | +├── pyproject.toml |
| 33 | +├── .env |
| 34 | +├── .gitignore |
| 35 | +├── scripts/ |
| 36 | +│ ├── format.sh |
| 37 | +│ ├── lint.sh |
| 38 | +│ ├── run-server.sh |
| 39 | +│ └── test.sh |
| 40 | +├── src/ |
| 41 | +│ └── app/ |
| 42 | +│ ├── main.py # FastAPI app entry point |
| 43 | +│ ├── core/ |
| 44 | +│ │ └── config.py # pydantic-settings configuration |
| 45 | +│ ├── db/ |
| 46 | +│ │ └── memory.py # in-memory store stand-in for a real DB |
| 47 | +│ ├── api/ |
| 48 | +│ │ ├── router.py # aggregates health + every domain router |
| 49 | +│ │ └── health.py # GET /health |
| 50 | +│ └── domains/ |
| 51 | +│ └── items/ # example domain (CRUD over an item entity) |
| 52 | +│ ├── models.py # entity dataclass |
| 53 | +│ ├── schemas.py # API I/O schemas (pydantic) |
| 54 | +│ ├── repository.py # data access layer |
| 55 | +│ ├── service.py # business logic |
| 56 | +│ └── router.py # FastAPI router for the domain |
| 57 | +└── tests/ |
| 58 | + ├── conftest.py |
| 59 | + ├── test_health.py |
| 60 | + └── test_items.py |
| 61 | +``` |
| 62 | + |
| 63 | +The recipe for adding a new domain is: |
| 64 | + |
| 65 | +1. Create `src/app/domains/<your_domain>/`. |
| 66 | +2. Mirror the `items` layout (`models.py`, `schemas.py`, `repository.py`, |
| 67 | + `service.py`, `router.py`). |
| 68 | +3. Register the router in `src/app/api/router.py`. |
| 69 | +4. Add tests under `tests/test_<your_domain>.py`. |
| 70 | + |
| 71 | +## Running the app |
| 72 | + |
| 73 | +```bash |
| 74 | +# create a virtualenv and install dependencies |
| 75 | +$ uv sync # or: pip install -e ".[dev]" |
| 76 | + |
| 77 | +# launch the dev server |
| 78 | +$ bash scripts/run-server.sh |
| 79 | +# or directly: |
| 80 | +$ uvicorn src.app.main:app --reload |
| 81 | +``` |
| 82 | + |
| 83 | +API docs are then served at: |
| 84 | + |
| 85 | +- Swagger UI: <http://127.0.0.1:8000/docs> |
| 86 | +- ReDoc: <http://127.0.0.1:8000/redoc> |
| 87 | + |
| 88 | +## API endpoints |
| 89 | + |
| 90 | +| Method | Endpoint | Description | |
| 91 | +|--------|---------------------------|------------------------------| |
| 92 | +| GET | `/api/v1/health` | Liveness probe | |
| 93 | +| GET | `/api/v1/items` | List items | |
| 94 | +| GET | `/api/v1/items/{item_id}` | Read a single item | |
| 95 | +| POST | `/api/v1/items` | Create an item | |
| 96 | +| PUT | `/api/v1/items/{item_id}` | Replace an item | |
| 97 | +| DELETE | `/api/v1/items/{item_id}` | Delete an item | |
| 98 | + |
| 99 | +## Running tests |
| 100 | + |
| 101 | +```bash |
| 102 | +$ bash scripts/test.sh |
| 103 | +# or directly: |
| 104 | +$ pytest |
| 105 | +``` |
| 106 | + |
| 107 | +## Configuration |
| 108 | + |
| 109 | +`src/app/core/config.py` reads settings from environment variables (or a |
| 110 | +local `.env` file). The provided `.env` only sets a placeholder |
| 111 | +`SECRET_KEY` — replace it before deploying. |
| 112 | + |
| 113 | +## Project Origin |
| 114 | + |
| 115 | +This project was created from the **`fastapi-domain-starter`** template |
| 116 | +shipped with [FastAPI-fastkit](https://github.com/bnbong/FastAPI-fastkit). |
| 117 | + |
| 118 | +The `FastAPI-fastkit` is an open-source project that helps Python and |
| 119 | +FastAPI beginners quickly set up a FastAPI-based application development |
| 120 | +environment in a framework-like structure. |
| 121 | + |
| 122 | +### Template Information |
| 123 | +- Template creator: [bnbong](mailto:bbbong9@gmail.com) |
| 124 | +- FastAPI-fastkit project maintainer: [bnbong](mailto:bbbong9@gmail.com) |
0 commit comments