fastapi-struct 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastapi_struct-0.2.0/PKG-INFO +256 -0
- fastapi_struct-0.2.0/README.md +243 -0
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/pyproject.toml +5 -2
- fastapi_struct-0.2.0/src/create_fastapi_app/__init__.py +1 -0
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/src/create_fastapi_app/generator.py +44 -33
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/.env +4 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/.env.example +4 -0
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/src/create_fastapi_app/templates/basic/.gitignore +3 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/README.md +35 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/api/v1/api.py +6 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/api/v1/routes/items.py +23 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/api/v1/routes/users.py +26 -0
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/src/create_fastapi_app/templates/basic/app/core/config.py +3 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/core/database.py +8 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/core/security.py +13 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/main.py +24 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/models/item.py +9 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/models/user.py +10 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/repositories/__init__.py +0 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/repositories/item_repository.py +35 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/repositories/user_repository.py +36 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/schemas/__init__.py +0 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/schemas/item.py +17 -0
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/src/create_fastapi_app/templates/basic/app/schemas/user.py +7 -4
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/services/__init__.py +0 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/services/item_service.py +21 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/services/user_service.py +26 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/utils/__init__.py +0 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/utils/email.py +8 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/pyproject.toml +22 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/requirements.txt +7 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/tests/__init__.py +0 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/tests/conftest.py +9 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/tests/test_items.py +22 -0
- fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/tests/test_users.py +28 -0
- fastapi_struct-0.2.0/src/fastapi_struct.egg-info/PKG-INFO +256 -0
- fastapi_struct-0.2.0/src/fastapi_struct.egg-info/SOURCES.txt +48 -0
- fastapi_struct-0.1.0/PKG-INFO +0 -47
- fastapi_struct-0.1.0/README.md +0 -34
- fastapi_struct-0.1.0/src/create_fastapi_app/__init__.py +0 -1
- fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/.env.example +0 -2
- fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/README.md +0 -23
- fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/app/db/database.py +0 -1
- fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/app/dependencies.py +0 -1
- fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/app/main.py +0 -19
- fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/app/models/__init__.py +0 -1
- fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/app/routers/health.py +0 -8
- fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/app/routers/users.py +0 -33
- fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/app/services/__init__.py +0 -1
- fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/pyproject.toml +0 -21
- fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/tests/test_main.py +0 -15
- fastapi_struct-0.1.0/src/fastapi_struct.egg-info/PKG-INFO +0 -47
- fastapi_struct-0.1.0/src/fastapi_struct.egg-info/SOURCES.txt +0 -32
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/MANIFEST.in +0 -0
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/setup.cfg +0 -0
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/src/create_fastapi_app/cli.py +0 -0
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/src/create_fastapi_app/templates/basic/app/__init__.py +0 -0
- {fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/app/core → fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/api}/__init__.py +0 -0
- {fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/app/db → fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/api/v1}/__init__.py +0 -0
- {fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/app/routers → fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/api/v1/routes}/__init__.py +0 -0
- {fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/app/schemas → fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/core}/__init__.py +0 -0
- {fastapi_struct-0.1.0/src/create_fastapi_app/templates/basic/tests → fastapi_struct-0.2.0/src/create_fastapi_app/templates/basic/app/models}/__init__.py +0 -0
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/src/fastapi_struct.egg-info/dependency_links.txt +0 -0
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/src/fastapi_struct.egg-info/entry_points.txt +0 -0
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/src/fastapi_struct.egg-info/top_level.txt +0 -0
- {fastapi_struct-0.1.0 → fastapi_struct-0.2.0}/tests/test_generator.py +0 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastapi-struct
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: CLI tool to generate standard, layered enterprise folder structures for FastAPI applications.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Keywords: fastapi,project-structure,boilerplate,scaffold,cli,template,folder-structure,architecture,repository-pattern,rest-api
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Framework :: FastAPI
|
|
9
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://pypi.org/project/fastapi-struct/"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" width="320" alt="fastapi-struct"></a>
|
|
16
|
+
</p>
|
|
17
|
+
<p align="center">
|
|
18
|
+
<em>CLI tool to generate standard, enterprise-ready, layered folder structures for FastAPI applications in seconds.</em>
|
|
19
|
+
</p>
|
|
20
|
+
<p align="center">
|
|
21
|
+
<a href="https://pypi.org/project/fastapi-struct" target="_blank">
|
|
22
|
+
<img src="https://img.shields.io/pypi/v/fastapi-struct.svg?color=%2334D058" alt="Package version">
|
|
23
|
+
</a>
|
|
24
|
+
<a href="https://pypi.org/project/fastapi-struct" target="_blank">
|
|
25
|
+
<img src="https://img.shields.io/pypi/pyversions/fastapi-struct.svg?color=%2334D058" alt="Supported Python versions">
|
|
26
|
+
</a>
|
|
27
|
+
<a href="https://github.com/fastapi/fastapi" target="_blank">
|
|
28
|
+
<img src="https://img.shields.io/badge/FastAPI-0.115+-009688.svg?logo=fastapi&logoColor=white" alt="FastAPI">
|
|
29
|
+
</a>
|
|
30
|
+
<a href="https://github.com/pydantic/pydantic" target="_blank">
|
|
31
|
+
<img src="https://img.shields.io/badge/Pydantic-v2-E92063.svg?logo=pydantic&logoColor=white" alt="Pydantic v2">
|
|
32
|
+
</a>
|
|
33
|
+
<a href="https://opensource.org/licenses/MIT" target="_blank">
|
|
34
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT">
|
|
35
|
+
</a>
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
**FastAPI Documentation:** [https://fastapi.tiangolo.com](https://fastapi.tiangolo.com)
|
|
41
|
+
**PyPI Package:** [https://pypi.org/project/fastapi-struct/](https://pypi.org/project/fastapi-struct/)
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## ⚡ What is `fastapi-struct`?
|
|
46
|
+
|
|
47
|
+
**`fastapi-struct`** generates a clean, scalable, layered enterprise architecture for FastAPI applications. It organizes code into distinct responsibilities: **API Routes**, **Services**, **Repositories**, **Schemas**, **Models**, and **Core Settings**, avoiding messy spaghetti code and giving you a production-ready codebase instantly.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
fastapi-struct my_fastapi_project
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Or scaffold directly inside your current directory:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
fastapi-struct .
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 🎯 Architecture Diagram & Data Flow
|
|
62
|
+
|
|
63
|
+
```text
|
|
64
|
+
┌────────────────┐
|
|
65
|
+
│ Client Request │
|
|
66
|
+
└───────┬────────┘
|
|
67
|
+
│
|
|
68
|
+
▼
|
|
69
|
+
┌────────────────────────┐
|
|
70
|
+
│ API Routes (v1) │ Handles HTTP requests & route decorators
|
|
71
|
+
└───────┬────────────────┘
|
|
72
|
+
│
|
|
73
|
+
▼
|
|
74
|
+
┌────────────────────────┐
|
|
75
|
+
│ Services Layer │ Encapsulates core business logic
|
|
76
|
+
└───────┬────────────────┘
|
|
77
|
+
│
|
|
78
|
+
▼
|
|
79
|
+
┌────────────────────────┐
|
|
80
|
+
│ Repositories Layer │ Database interactions & CRUD operations
|
|
81
|
+
└───────┬────────────────┘
|
|
82
|
+
│
|
|
83
|
+
▼
|
|
84
|
+
┌────────────────────────┐
|
|
85
|
+
│ Database / ORM Models │ SQLAlchemy / SQLModel / Database tables
|
|
86
|
+
└────────────────────────┘
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 📂 Generated Project Structure
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
my_fastapi_project/
|
|
95
|
+
│
|
|
96
|
+
├── app/ # Main application package
|
|
97
|
+
│ ├── __init__.py
|
|
98
|
+
│ ├── main.py # FastAPI app initialization & entry point
|
|
99
|
+
│ │
|
|
100
|
+
│ ├── api/ # API endpoints & route definitions
|
|
101
|
+
│ │ ├── __init__.py
|
|
102
|
+
│ │ └── v1/ # API Versioning
|
|
103
|
+
│ │ ├── __init__.py
|
|
104
|
+
│ │ ├── api.py # Central router aggregating endpoints
|
|
105
|
+
│ │ └── routes/ # Route handlers
|
|
106
|
+
│ │ ├── __init__.py
|
|
107
|
+
│ │ ├── items.py # Endpoint logic for items
|
|
108
|
+
│ │ └── users.py # Endpoint logic for users
|
|
109
|
+
│ │
|
|
110
|
+
│ ├── core/ # Application configurations & settings
|
|
111
|
+
│ │ ├── __init__.py
|
|
112
|
+
│ │ ├── config.py # Environment variables (Pydantic BaseSettings)
|
|
113
|
+
│ │ ├── database.py # DB connection & session creation
|
|
114
|
+
│ │ └── security.py # Password hashing & security helpers
|
|
115
|
+
│ │
|
|
116
|
+
│ ├── models/ # Database ORM models (SQLAlchemy / SQLModel)
|
|
117
|
+
│ │ ├── __init__.py
|
|
118
|
+
│ │ ├── item.py
|
|
119
|
+
│ │ └── user.py
|
|
120
|
+
│ │
|
|
121
|
+
│ ├── schemas/ # Pydantic models for request validation & responses
|
|
122
|
+
│ │ ├── __init__.py
|
|
123
|
+
│ │ ├── item.py
|
|
124
|
+
│ │ └── user.py
|
|
125
|
+
│ │
|
|
126
|
+
│ ├── services/ # Core business logic layer
|
|
127
|
+
│ │ ├── __init__.py
|
|
128
|
+
│ │ ├── item_service.py
|
|
129
|
+
│ │ └── user_service.py
|
|
130
|
+
│ │
|
|
131
|
+
│ ├── repositories/ # Database interactions & CRUD queries layer
|
|
132
|
+
│ │ ├── __init__.py
|
|
133
|
+
│ │ ├── item_repository.py
|
|
134
|
+
│ │ └── user_repository.py
|
|
135
|
+
│ │
|
|
136
|
+
│ └── utils/ # Utility functions & helpers
|
|
137
|
+
│ ├── __init__.py
|
|
138
|
+
│ └── email.py
|
|
139
|
+
│
|
|
140
|
+
├── tests/ # Unit and integration tests
|
|
141
|
+
│ ├── __init__.py
|
|
142
|
+
│ ├── conftest.py # Pytest fixtures
|
|
143
|
+
│ ├── test_items.py # Item API test cases
|
|
144
|
+
│ └── test_users.py # User API test cases
|
|
145
|
+
│
|
|
146
|
+
├── .gitignore
|
|
147
|
+
├── .env # Environment variables (local)
|
|
148
|
+
├── .env.example # Sample environment variables template
|
|
149
|
+
├── README.md # Project documentation
|
|
150
|
+
├── requirements.txt # Project dependencies
|
|
151
|
+
└── pyproject.toml # Build & test configurations
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 📦 Installation & Quick Start
|
|
157
|
+
|
|
158
|
+
### Option 1: Instant with `uvx` *(No installation needed)*
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
uvx fastapi-struct my_fastapi_project
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Or inside your existing folder:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
uvx fastapi-struct .
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### Option 2: Standard install with `pip`
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
pip install fastapi-struct
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Run:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
fastapi-struct my_fastapi_project
|
|
182
|
+
```
|
|
183
|
+
*(Or inside the current folder: `fastapi-struct .`)*
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## 🚀 Running Your Generated Project
|
|
188
|
+
|
|
189
|
+
### 1. Step into the project folder
|
|
190
|
+
```bash
|
|
191
|
+
cd my_fastapi_project
|
|
192
|
+
```
|
|
193
|
+
*(Skip if generated with `fastapi-struct .`)*
|
|
194
|
+
|
|
195
|
+
### 2. Create and activate a virtual environment
|
|
196
|
+
|
|
197
|
+
**Windows PowerShell:**
|
|
198
|
+
```powershell
|
|
199
|
+
python -m venv .venv
|
|
200
|
+
.\.venv\Scripts\Activate.ps1
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**Windows CMD:**
|
|
204
|
+
```cmd
|
|
205
|
+
python -m venv .venv
|
|
206
|
+
call .venv\Scripts\activate.bat
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
**macOS & Linux:**
|
|
210
|
+
```bash
|
|
211
|
+
python3 -m venv .venv
|
|
212
|
+
source .venv/bin/activate
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### 3. Install dependencies
|
|
216
|
+
```bash
|
|
217
|
+
pip install -r requirements.txt
|
|
218
|
+
```
|
|
219
|
+
*(Or `pip install -e ".[dev]"`)*
|
|
220
|
+
|
|
221
|
+
### 4. Start the development server
|
|
222
|
+
```bash
|
|
223
|
+
python -m uvicorn app.main:app --reload
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 🔍 Interactive API Documentation
|
|
229
|
+
|
|
230
|
+
Once running, visit:
|
|
231
|
+
|
|
232
|
+
- **Swagger UI**: [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
|
|
233
|
+
- **ReDoc**: [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc)
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## 🧪 Running Automated Tests
|
|
238
|
+
|
|
239
|
+
Run the included Pytest suite:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
python -m pytest
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Output:
|
|
246
|
+
```text
|
|
247
|
+
tests\test_items.py .. [ 50%]
|
|
248
|
+
tests\test_users.py .. [100%]
|
|
249
|
+
============================== 4 passed in 0.25s ==============================
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## 📜 License
|
|
255
|
+
|
|
256
|
+
This project is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://pypi.org/project/fastapi-struct/"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" width="320" alt="fastapi-struct"></a>
|
|
3
|
+
</p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
<em>CLI tool to generate standard, enterprise-ready, layered folder structures for FastAPI applications in seconds.</em>
|
|
6
|
+
</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://pypi.org/project/fastapi-struct" target="_blank">
|
|
9
|
+
<img src="https://img.shields.io/pypi/v/fastapi-struct.svg?color=%2334D058" alt="Package version">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://pypi.org/project/fastapi-struct" target="_blank">
|
|
12
|
+
<img src="https://img.shields.io/pypi/pyversions/fastapi-struct.svg?color=%2334D058" alt="Supported Python versions">
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/fastapi/fastapi" target="_blank">
|
|
15
|
+
<img src="https://img.shields.io/badge/FastAPI-0.115+-009688.svg?logo=fastapi&logoColor=white" alt="FastAPI">
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://github.com/pydantic/pydantic" target="_blank">
|
|
18
|
+
<img src="https://img.shields.io/badge/Pydantic-v2-E92063.svg?logo=pydantic&logoColor=white" alt="Pydantic v2">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://opensource.org/licenses/MIT" target="_blank">
|
|
21
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT">
|
|
22
|
+
</a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
**FastAPI Documentation:** [https://fastapi.tiangolo.com](https://fastapi.tiangolo.com)
|
|
28
|
+
**PyPI Package:** [https://pypi.org/project/fastapi-struct/](https://pypi.org/project/fastapi-struct/)
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## ⚡ What is `fastapi-struct`?
|
|
33
|
+
|
|
34
|
+
**`fastapi-struct`** generates a clean, scalable, layered enterprise architecture for FastAPI applications. It organizes code into distinct responsibilities: **API Routes**, **Services**, **Repositories**, **Schemas**, **Models**, and **Core Settings**, avoiding messy spaghetti code and giving you a production-ready codebase instantly.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
fastapi-struct my_fastapi_project
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Or scaffold directly inside your current directory:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
fastapi-struct .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 🎯 Architecture Diagram & Data Flow
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
┌────────────────┐
|
|
52
|
+
│ Client Request │
|
|
53
|
+
└───────┬────────┘
|
|
54
|
+
│
|
|
55
|
+
▼
|
|
56
|
+
┌────────────────────────┐
|
|
57
|
+
│ API Routes (v1) │ Handles HTTP requests & route decorators
|
|
58
|
+
└───────┬────────────────┘
|
|
59
|
+
│
|
|
60
|
+
▼
|
|
61
|
+
┌────────────────────────┐
|
|
62
|
+
│ Services Layer │ Encapsulates core business logic
|
|
63
|
+
└───────┬────────────────┘
|
|
64
|
+
│
|
|
65
|
+
▼
|
|
66
|
+
┌────────────────────────┐
|
|
67
|
+
│ Repositories Layer │ Database interactions & CRUD operations
|
|
68
|
+
└───────┬────────────────┘
|
|
69
|
+
│
|
|
70
|
+
▼
|
|
71
|
+
┌────────────────────────┐
|
|
72
|
+
│ Database / ORM Models │ SQLAlchemy / SQLModel / Database tables
|
|
73
|
+
└────────────────────────┘
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 📂 Generated Project Structure
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
my_fastapi_project/
|
|
82
|
+
│
|
|
83
|
+
├── app/ # Main application package
|
|
84
|
+
│ ├── __init__.py
|
|
85
|
+
│ ├── main.py # FastAPI app initialization & entry point
|
|
86
|
+
│ │
|
|
87
|
+
│ ├── api/ # API endpoints & route definitions
|
|
88
|
+
│ │ ├── __init__.py
|
|
89
|
+
│ │ └── v1/ # API Versioning
|
|
90
|
+
│ │ ├── __init__.py
|
|
91
|
+
│ │ ├── api.py # Central router aggregating endpoints
|
|
92
|
+
│ │ └── routes/ # Route handlers
|
|
93
|
+
│ │ ├── __init__.py
|
|
94
|
+
│ │ ├── items.py # Endpoint logic for items
|
|
95
|
+
│ │ └── users.py # Endpoint logic for users
|
|
96
|
+
│ │
|
|
97
|
+
│ ├── core/ # Application configurations & settings
|
|
98
|
+
│ │ ├── __init__.py
|
|
99
|
+
│ │ ├── config.py # Environment variables (Pydantic BaseSettings)
|
|
100
|
+
│ │ ├── database.py # DB connection & session creation
|
|
101
|
+
│ │ └── security.py # Password hashing & security helpers
|
|
102
|
+
│ │
|
|
103
|
+
│ ├── models/ # Database ORM models (SQLAlchemy / SQLModel)
|
|
104
|
+
│ │ ├── __init__.py
|
|
105
|
+
│ │ ├── item.py
|
|
106
|
+
│ │ └── user.py
|
|
107
|
+
│ │
|
|
108
|
+
│ ├── schemas/ # Pydantic models for request validation & responses
|
|
109
|
+
│ │ ├── __init__.py
|
|
110
|
+
│ │ ├── item.py
|
|
111
|
+
│ │ └── user.py
|
|
112
|
+
│ │
|
|
113
|
+
│ ├── services/ # Core business logic layer
|
|
114
|
+
│ │ ├── __init__.py
|
|
115
|
+
│ │ ├── item_service.py
|
|
116
|
+
│ │ └── user_service.py
|
|
117
|
+
│ │
|
|
118
|
+
│ ├── repositories/ # Database interactions & CRUD queries layer
|
|
119
|
+
│ │ ├── __init__.py
|
|
120
|
+
│ │ ├── item_repository.py
|
|
121
|
+
│ │ └── user_repository.py
|
|
122
|
+
│ │
|
|
123
|
+
│ └── utils/ # Utility functions & helpers
|
|
124
|
+
│ ├── __init__.py
|
|
125
|
+
│ └── email.py
|
|
126
|
+
│
|
|
127
|
+
├── tests/ # Unit and integration tests
|
|
128
|
+
│ ├── __init__.py
|
|
129
|
+
│ ├── conftest.py # Pytest fixtures
|
|
130
|
+
│ ├── test_items.py # Item API test cases
|
|
131
|
+
│ └── test_users.py # User API test cases
|
|
132
|
+
│
|
|
133
|
+
├── .gitignore
|
|
134
|
+
├── .env # Environment variables (local)
|
|
135
|
+
├── .env.example # Sample environment variables template
|
|
136
|
+
├── README.md # Project documentation
|
|
137
|
+
├── requirements.txt # Project dependencies
|
|
138
|
+
└── pyproject.toml # Build & test configurations
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## 📦 Installation & Quick Start
|
|
144
|
+
|
|
145
|
+
### Option 1: Instant with `uvx` *(No installation needed)*
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
uvx fastapi-struct my_fastapi_project
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Or inside your existing folder:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
uvx fastapi-struct .
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
### Option 2: Standard install with `pip`
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
pip install fastapi-struct
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Run:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
fastapi-struct my_fastapi_project
|
|
169
|
+
```
|
|
170
|
+
*(Or inside the current folder: `fastapi-struct .`)*
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## 🚀 Running Your Generated Project
|
|
175
|
+
|
|
176
|
+
### 1. Step into the project folder
|
|
177
|
+
```bash
|
|
178
|
+
cd my_fastapi_project
|
|
179
|
+
```
|
|
180
|
+
*(Skip if generated with `fastapi-struct .`)*
|
|
181
|
+
|
|
182
|
+
### 2. Create and activate a virtual environment
|
|
183
|
+
|
|
184
|
+
**Windows PowerShell:**
|
|
185
|
+
```powershell
|
|
186
|
+
python -m venv .venv
|
|
187
|
+
.\.venv\Scripts\Activate.ps1
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**Windows CMD:**
|
|
191
|
+
```cmd
|
|
192
|
+
python -m venv .venv
|
|
193
|
+
call .venv\Scripts\activate.bat
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
**macOS & Linux:**
|
|
197
|
+
```bash
|
|
198
|
+
python3 -m venv .venv
|
|
199
|
+
source .venv/bin/activate
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### 3. Install dependencies
|
|
203
|
+
```bash
|
|
204
|
+
pip install -r requirements.txt
|
|
205
|
+
```
|
|
206
|
+
*(Or `pip install -e ".[dev]"`)*
|
|
207
|
+
|
|
208
|
+
### 4. Start the development server
|
|
209
|
+
```bash
|
|
210
|
+
python -m uvicorn app.main:app --reload
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## 🔍 Interactive API Documentation
|
|
216
|
+
|
|
217
|
+
Once running, visit:
|
|
218
|
+
|
|
219
|
+
- **Swagger UI**: [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
|
|
220
|
+
- **ReDoc**: [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc)
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## 🧪 Running Automated Tests
|
|
225
|
+
|
|
226
|
+
Run the included Pytest suite:
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
python -m pytest
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Output:
|
|
233
|
+
```text
|
|
234
|
+
tests\test_items.py .. [ 50%]
|
|
235
|
+
tests\test_users.py .. [100%]
|
|
236
|
+
============================== 4 passed in 0.25s ==============================
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## 📜 License
|
|
242
|
+
|
|
243
|
+
This project is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "fastapi-struct"
|
|
7
|
-
version = "0.
|
|
8
|
-
description = "CLI tool to generate standard folder
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "CLI tool to generate standard, layered enterprise folder structures for FastAPI applications."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
license = "MIT"
|
|
@@ -17,6 +17,9 @@ keywords = [
|
|
|
17
17
|
"cli",
|
|
18
18
|
"template",
|
|
19
19
|
"folder-structure",
|
|
20
|
+
"architecture",
|
|
21
|
+
"repository-pattern",
|
|
22
|
+
"rest-api",
|
|
20
23
|
]
|
|
21
24
|
classifiers = [
|
|
22
25
|
"Programming Language :: Python :: 3",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.0"
|
|
@@ -1,33 +1,44 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
import re
|
|
3
|
-
import shutil
|
|
4
|
-
|
|
5
|
-
PACKAGE_DIR = Path(__file__).parent
|
|
6
|
-
TEMPLATE_DIR = PACKAGE_DIR / "templates" / "basic"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def create_project(name: str) -> Path:
|
|
10
|
-
if name == ".":
|
|
11
|
-
project_path = Path.cwd()
|
|
12
|
-
project_name = project_path.name
|
|
13
|
-
else:
|
|
14
|
-
if not re.fullmatch(r"[A-Za-z][A-Za-z0-9_-]*", name):
|
|
15
|
-
raise ValueError(
|
|
16
|
-
"Project name must start with a letter and contain "
|
|
17
|
-
"only letters, numbers, underscores, or hyphens."
|
|
18
|
-
)
|
|
19
|
-
project_path = Path.cwd() / name
|
|
20
|
-
project_name = name
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import re
|
|
3
|
+
import shutil
|
|
4
|
+
|
|
5
|
+
PACKAGE_DIR = Path(__file__).parent
|
|
6
|
+
TEMPLATE_DIR = PACKAGE_DIR / "templates" / "basic"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def create_project(name: str) -> Path:
|
|
10
|
+
if name == ".":
|
|
11
|
+
project_path = Path.cwd()
|
|
12
|
+
project_name = project_path.name
|
|
13
|
+
else:
|
|
14
|
+
if not re.fullmatch(r"[A-Za-z][A-Za-z0-9_-]*", name):
|
|
15
|
+
raise ValueError(
|
|
16
|
+
"Project name must start with a letter and contain "
|
|
17
|
+
"only letters, numbers, underscores, or hyphens."
|
|
18
|
+
)
|
|
19
|
+
project_path = Path.cwd() / name
|
|
20
|
+
project_name = name
|
|
21
|
+
|
|
22
|
+
if project_path.exists():
|
|
23
|
+
raise FileExistsError(
|
|
24
|
+
f"Destination directory already exists: {project_path}"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
if not TEMPLATE_DIR.is_dir():
|
|
28
|
+
raise FileNotFoundError(
|
|
29
|
+
f"Template directory not found: {TEMPLATE_DIR}"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# Copy files allowing existing directory (useful when name is '.')
|
|
33
|
+
shutil.copytree(TEMPLATE_DIR, project_path, dirs_exist_ok=True)
|
|
34
|
+
|
|
35
|
+
config_path = project_path / "pyproject.toml"
|
|
36
|
+
if config_path.exists():
|
|
37
|
+
config = config_path.read_text(encoding="utf-8")
|
|
38
|
+
config = config.replace(
|
|
39
|
+
'name = "my-api"',
|
|
40
|
+
f'name = "{project_name.lower().replace("_", "-")}"',
|
|
41
|
+
)
|
|
42
|
+
config_path.write_text(config, encoding="utf-8")
|
|
43
|
+
|
|
44
|
+
return project_path
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# FastAPI Application
|
|
2
|
+
|
|
3
|
+
Enterprise-grade modular FastAPI application generated with `fastapi-struct`.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
### 1. Create Virtual Environment
|
|
8
|
+
```bash
|
|
9
|
+
python -m venv .venv
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Activate:
|
|
13
|
+
- Windows PowerShell: `.\.venv\Scripts\Activate.ps1`
|
|
14
|
+
- Windows CMD: `call .venv\Scripts\activate.bat`
|
|
15
|
+
- Linux/macOS: `source .venv/bin/activate`
|
|
16
|
+
|
|
17
|
+
### 2. Install Dependencies
|
|
18
|
+
```bash
|
|
19
|
+
pip install -r requirements.txt
|
|
20
|
+
```
|
|
21
|
+
*(or `pip install -e ".[dev]"`)*
|
|
22
|
+
|
|
23
|
+
### 3. Run Development Server
|
|
24
|
+
```bash
|
|
25
|
+
python -m uvicorn app.main:app --reload
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Interactive API docs available at:
|
|
29
|
+
- Swagger UI: http://127.0.0.1:8000/docs
|
|
30
|
+
- ReDoc: http://127.0.0.1:8000/redoc
|
|
31
|
+
|
|
32
|
+
### 4. Run Tests
|
|
33
|
+
```bash
|
|
34
|
+
python -m pytest
|
|
35
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from fastapi import APIRouter, HTTPException, status
|
|
2
|
+
from app.schemas.item import ItemCreate, ItemResponse
|
|
3
|
+
from app.services.item_service import item_service
|
|
4
|
+
|
|
5
|
+
router = APIRouter(prefix="/items", tags=["Items"])
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@router.get("/", response_model=list[ItemResponse])
|
|
9
|
+
async def read_items():
|
|
10
|
+
return item_service.list_items()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@router.post("/", response_model=ItemResponse, status_code=status.HTTP_201_CREATED)
|
|
14
|
+
async def create_item(item_in: ItemCreate):
|
|
15
|
+
return item_service.create_item(item_in)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@router.get("/{item_id}", response_model=ItemResponse)
|
|
19
|
+
async def read_item(item_id: int):
|
|
20
|
+
item = item_service.get_item(item_id)
|
|
21
|
+
if not item:
|
|
22
|
+
raise HTTPException(status_code=404, detail="Item not found")
|
|
23
|
+
return item
|