fastapi-struct 0.2.0__tar.gz → 0.2.1__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.
Files changed (81) hide show
  1. fastapi_struct-0.2.1/PKG-INFO +231 -0
  2. fastapi_struct-0.2.1/README.md +218 -0
  3. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/pyproject.toml +1 -1
  4. fastapi_struct-0.2.1/src/create_fastapi_app/__init__.py +1 -0
  5. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/cli.py +15 -6
  6. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/generator.py +10 -5
  7. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/.env +4 -0
  8. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/.env.example +4 -0
  9. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/.gitignore +9 -0
  10. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/README.md +31 -0
  11. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/__init__.py +0 -0
  12. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/api/__init__.py +0 -0
  13. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/api/v1/__init__.py +0 -0
  14. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/api/v1/api.py +6 -0
  15. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/api/v1/routes/__init__.py +0 -0
  16. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/api/v1/routes/health.py +15 -0
  17. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/api/v1/routes/predict.py +16 -0
  18. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/core/__init__.py +0 -0
  19. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/core/config.py +20 -0
  20. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/main.py +37 -0
  21. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/ml/__init__.py +0 -0
  22. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/ml/model.py +34 -0
  23. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/ml/pipeline.py +17 -0
  24. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/schemas/__init__.py +0 -0
  25. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/schemas/predict.py +20 -0
  26. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/services/__init__.py +0 -0
  27. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/app/services/inference.py +30 -0
  28. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/pyproject.toml +21 -0
  29. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/requirements.txt +6 -0
  30. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/tests/__init__.py +0 -0
  31. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/tests/conftest.py +9 -0
  32. fastapi_struct-0.2.1/src/create_fastapi_app/templates/ml/tests/test_predict.py +17 -0
  33. fastapi_struct-0.2.1/src/fastapi_struct.egg-info/PKG-INFO +231 -0
  34. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/fastapi_struct.egg-info/SOURCES.txt +26 -0
  35. fastapi_struct-0.2.1/tests/test_generator.py +37 -0
  36. fastapi_struct-0.2.0/PKG-INFO +0 -256
  37. fastapi_struct-0.2.0/README.md +0 -243
  38. fastapi_struct-0.2.0/src/create_fastapi_app/__init__.py +0 -1
  39. fastapi_struct-0.2.0/src/fastapi_struct.egg-info/PKG-INFO +0 -256
  40. fastapi_struct-0.2.0/tests/test_generator.py +0 -29
  41. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/MANIFEST.in +0 -0
  42. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/setup.cfg +0 -0
  43. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/.env +0 -0
  44. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/.env.example +0 -0
  45. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/.gitignore +0 -0
  46. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/README.md +0 -0
  47. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/__init__.py +0 -0
  48. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/api/__init__.py +0 -0
  49. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/api/v1/__init__.py +0 -0
  50. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/api/v1/api.py +0 -0
  51. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/api/v1/routes/__init__.py +0 -0
  52. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/api/v1/routes/items.py +0 -0
  53. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/api/v1/routes/users.py +0 -0
  54. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/core/__init__.py +0 -0
  55. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/core/config.py +0 -0
  56. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/core/database.py +0 -0
  57. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/core/security.py +0 -0
  58. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/main.py +0 -0
  59. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/models/__init__.py +0 -0
  60. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/models/item.py +0 -0
  61. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/models/user.py +0 -0
  62. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/repositories/__init__.py +0 -0
  63. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/repositories/item_repository.py +0 -0
  64. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/repositories/user_repository.py +0 -0
  65. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/schemas/__init__.py +0 -0
  66. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/schemas/item.py +0 -0
  67. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/schemas/user.py +0 -0
  68. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/services/__init__.py +0 -0
  69. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/services/item_service.py +0 -0
  70. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/services/user_service.py +0 -0
  71. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/utils/__init__.py +0 -0
  72. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/app/utils/email.py +0 -0
  73. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/pyproject.toml +0 -0
  74. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/requirements.txt +0 -0
  75. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/tests/__init__.py +0 -0
  76. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/tests/conftest.py +0 -0
  77. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/tests/test_items.py +0 -0
  78. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/create_fastapi_app/templates/basic/tests/test_users.py +0 -0
  79. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/fastapi_struct.egg-info/dependency_links.txt +0 -0
  80. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/fastapi_struct.egg-info/entry_points.txt +0 -0
  81. {fastapi_struct-0.2.0 → fastapi_struct-0.2.1}/src/fastapi_struct.egg-info/top_level.txt +0 -0
@@ -0,0 +1,231 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastapi-struct
3
+ Version: 0.2.1
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, production-ready FastAPI folder structures in seconds — with dedicated templates for Enterprise Web APIs and AI/ML Inference Services.</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 clean, modular, and production-tested architectures for FastAPI applications. Rather than spending hours writing repetitive boilerplate, you get an instantly runnable codebase tailored to your exact project type:
48
+
49
+ 1. **`basic` (Default)**: Layered enterprise web API architecture (Routes &rarr; Services &rarr; Repositories &rarr; Database & Models).
50
+ 2. **`ml`**: Lean, specialized AI/ML inference microservice (Lifespan Model Loader &rarr; Inference Pipeline &rarr; Predictions & Latency Tracking).
51
+
52
+ ---
53
+
54
+ ## 📦 Quick Start & CLI Usage
55
+
56
+ ### 1. Enterprise Web API (Default)
57
+
58
+ ```bash
59
+ # With uvx (instant, no install needed)
60
+ uvx fastapi-struct my_api
61
+
62
+ # Or with pip:
63
+ pip install fastapi-struct
64
+ fastapi-struct my_api
65
+ ```
66
+
67
+ ### 2. AI / ML Inference Service (`--template ml`)
68
+
69
+ ```bash
70
+ # Generate a dedicated AI/ML service:
71
+ fastapi-struct my_ml_service --template ml
72
+
73
+ # Or shorthand:
74
+ fastapi-struct my_ml_service -t ml
75
+ ```
76
+
77
+ ### 3. Scaffold in the Current Directory (`.`)
78
+
79
+ ```bash
80
+ fastapi-struct . --template ml
81
+ ```
82
+
83
+ ---
84
+
85
+ ## 📂 Template 1: AI / ML Inference Architecture (`-t ml`)
86
+
87
+ Specially designed for AI/ML and GenAI engineers. Removes database CRUD overhead and optimizes for model loading, tensor preprocessing, inference, and latency benchmarking.
88
+
89
+ ```text
90
+ my_ml_service/
91
+ │
92
+ ├── app/
93
+ │ ├── __init__.py
94
+ │ ├── main.py # FastAPI app + lifespan model loader (loads weights once at startup)
95
+ │ │
96
+ │ ├── api/
97
+ │ │ ├── __init__.py
98
+ │ │ └── v1/ # API Versioning
99
+ │ │ ├── __init__.py
100
+ │ │ ├── api.py # Central router aggregating endpoints
101
+ │ │ └── routes/
102
+ │ │ ├── __init__.py
103
+ │ │ ├── health.py # /health probe (readiness check + GPU/device info)
104
+ │ │ └── predict.py # /predict endpoint (input validation, inference, latency)
105
+ │ │
106
+ │ ├── core/
107
+ │ │ ├── __init__.py
108
+ │ │ └── config.py # MODEL_NAME, MODEL_PATH, DEVICE ("cpu"/"cuda"), API_KEYS
109
+ │ │
110
+ │ ├── ml/ # Machine learning logic
111
+ │ │ ├── __init__.py
112
+ │ │ ├── model.py # Model wrapper (PyTorch / ONNX / HuggingFace)
113
+ │ │ └── pipeline.py # Tokenizer, preprocessing & postprocessing
114
+ │ │
115
+ │ ├── schemas/ # Request & Response Pydantic models
116
+ │ │ ├── __init__.py
117
+ │ │ └── predict.py # PredictionRequest, PredictionResponse, HealthResponse
118
+ │ │
119
+ │ └── services/ # Orchestration layer
120
+ │ ├── __init__.py
121
+ │ └── inference.py # Validates payload, executes pipeline, measures latency
122
+ │
123
+ ├── tests/ # Automated test suite
124
+ │ ├── __init__.py
125
+ │ ├── conftest.py # TestClient fixtures + mock model
126
+ │ └── test_predict.py # Pytest test cases for /health & /predict
127
+ │
128
+ ├── .gitignore
129
+ ├── .env # Local model configuration
130
+ ├── .env.example
131
+ ├── requirements.txt # Ready for pip install -r requirements.txt
132
+ ├── pyproject.toml # Build & pytest configuration
133
+ └── README.md
134
+ ```
135
+
136
+ ---
137
+
138
+ ## 📂 Template 2: Layered Enterprise Web Architecture (`-t basic`)
139
+
140
+ Designed for full-stack and backend services that require domain-driven separation of concerns.
141
+
142
+ ```text
143
+ my_fastapi_project/
144
+ │
145
+ ├── app/
146
+ │ ├── __init__.py
147
+ │ ├── main.py # Application factory & router registration
148
+ │ │
149
+ │ ├── api/v1/routes/ # HTTP route endpoints (items.py, users.py)
150
+ │ ├── core/ # config.py, database.py, security.py
151
+ │ ├── models/ # Database ORM models (item.py, user.py)
152
+ │ ├── schemas/ # Pydantic serialization schemas (item.py, user.py)
153
+ │ ├── services/ # Pure business logic layer
154
+ │ ├── repositories/ # Database CRUD queries layer
155
+ │ └── utils/ # Utility helpers (email.py)
156
+ │
157
+ ├── tests/ # conftest.py, test_items.py, test_users.py
158
+ ├── requirements.txt
159
+ ├── pyproject.toml
160
+ └── README.md
161
+ ```
162
+
163
+ ---
164
+
165
+ ## 🚀 Running Your Generated Project
166
+
167
+ ### 1. Step into your project directory
168
+ ```bash
169
+ cd my_ml_service
170
+ ```
171
+
172
+ ### 2. Create and activate a virtual environment
173
+
174
+ **Windows PowerShell:**
175
+ ```powershell
176
+ python -m venv .venv
177
+ .\.venv\Scripts\Activate.ps1
178
+ ```
179
+
180
+ **Windows CMD:**
181
+ ```cmd
182
+ python -m venv .venv
183
+ call .venv\Scripts\activate.bat
184
+ ```
185
+
186
+ **macOS / Linux:**
187
+ ```bash
188
+ python3 -m venv .venv
189
+ source .venv/bin/activate
190
+ ```
191
+
192
+ ### 3. Install dependencies
193
+ ```bash
194
+ pip install -r requirements.txt
195
+ ```
196
+
197
+ ### 4. Start the server
198
+ ```bash
199
+ python -m uvicorn app.main:app --reload
200
+ ```
201
+
202
+ ---
203
+
204
+ ## 🔍 Interactive API Documentation
205
+
206
+ Once running, visit:
207
+
208
+ - **Swagger UI**: [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
209
+ - **ReDoc**: [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc)
210
+
211
+ ---
212
+
213
+ ## 🧪 Running Automated Tests
214
+
215
+ Run the included Pytest suite:
216
+
217
+ ```bash
218
+ python -m pytest
219
+ ```
220
+
221
+ Output:
222
+ ```text
223
+ tests\test_predict.py .. [100%]
224
+ ============================== 2 passed in 0.15s ==============================
225
+ ```
226
+
227
+ ---
228
+
229
+ ## 📜 License
230
+
231
+ This project is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,218 @@
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, production-ready FastAPI folder structures in seconds — with dedicated templates for Enterprise Web APIs and AI/ML Inference Services.</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 clean, modular, and production-tested architectures for FastAPI applications. Rather than spending hours writing repetitive boilerplate, you get an instantly runnable codebase tailored to your exact project type:
35
+
36
+ 1. **`basic` (Default)**: Layered enterprise web API architecture (Routes &rarr; Services &rarr; Repositories &rarr; Database & Models).
37
+ 2. **`ml`**: Lean, specialized AI/ML inference microservice (Lifespan Model Loader &rarr; Inference Pipeline &rarr; Predictions & Latency Tracking).
38
+
39
+ ---
40
+
41
+ ## 📦 Quick Start & CLI Usage
42
+
43
+ ### 1. Enterprise Web API (Default)
44
+
45
+ ```bash
46
+ # With uvx (instant, no install needed)
47
+ uvx fastapi-struct my_api
48
+
49
+ # Or with pip:
50
+ pip install fastapi-struct
51
+ fastapi-struct my_api
52
+ ```
53
+
54
+ ### 2. AI / ML Inference Service (`--template ml`)
55
+
56
+ ```bash
57
+ # Generate a dedicated AI/ML service:
58
+ fastapi-struct my_ml_service --template ml
59
+
60
+ # Or shorthand:
61
+ fastapi-struct my_ml_service -t ml
62
+ ```
63
+
64
+ ### 3. Scaffold in the Current Directory (`.`)
65
+
66
+ ```bash
67
+ fastapi-struct . --template ml
68
+ ```
69
+
70
+ ---
71
+
72
+ ## 📂 Template 1: AI / ML Inference Architecture (`-t ml`)
73
+
74
+ Specially designed for AI/ML and GenAI engineers. Removes database CRUD overhead and optimizes for model loading, tensor preprocessing, inference, and latency benchmarking.
75
+
76
+ ```text
77
+ my_ml_service/
78
+ │
79
+ ├── app/
80
+ │ ├── __init__.py
81
+ │ ├── main.py # FastAPI app + lifespan model loader (loads weights once at startup)
82
+ │ │
83
+ │ ├── api/
84
+ │ │ ├── __init__.py
85
+ │ │ └── v1/ # API Versioning
86
+ │ │ ├── __init__.py
87
+ │ │ ├── api.py # Central router aggregating endpoints
88
+ │ │ └── routes/
89
+ │ │ ├── __init__.py
90
+ │ │ ├── health.py # /health probe (readiness check + GPU/device info)
91
+ │ │ └── predict.py # /predict endpoint (input validation, inference, latency)
92
+ │ │
93
+ │ ├── core/
94
+ │ │ ├── __init__.py
95
+ │ │ └── config.py # MODEL_NAME, MODEL_PATH, DEVICE ("cpu"/"cuda"), API_KEYS
96
+ │ │
97
+ │ ├── ml/ # Machine learning logic
98
+ │ │ ├── __init__.py
99
+ │ │ ├── model.py # Model wrapper (PyTorch / ONNX / HuggingFace)
100
+ │ │ └── pipeline.py # Tokenizer, preprocessing & postprocessing
101
+ │ │
102
+ │ ├── schemas/ # Request & Response Pydantic models
103
+ │ │ ├── __init__.py
104
+ │ │ └── predict.py # PredictionRequest, PredictionResponse, HealthResponse
105
+ │ │
106
+ │ └── services/ # Orchestration layer
107
+ │ ├── __init__.py
108
+ │ └── inference.py # Validates payload, executes pipeline, measures latency
109
+ │
110
+ ├── tests/ # Automated test suite
111
+ │ ├── __init__.py
112
+ │ ├── conftest.py # TestClient fixtures + mock model
113
+ │ └── test_predict.py # Pytest test cases for /health & /predict
114
+ │
115
+ ├── .gitignore
116
+ ├── .env # Local model configuration
117
+ ├── .env.example
118
+ ├── requirements.txt # Ready for pip install -r requirements.txt
119
+ ├── pyproject.toml # Build & pytest configuration
120
+ └── README.md
121
+ ```
122
+
123
+ ---
124
+
125
+ ## 📂 Template 2: Layered Enterprise Web Architecture (`-t basic`)
126
+
127
+ Designed for full-stack and backend services that require domain-driven separation of concerns.
128
+
129
+ ```text
130
+ my_fastapi_project/
131
+ │
132
+ ├── app/
133
+ │ ├── __init__.py
134
+ │ ├── main.py # Application factory & router registration
135
+ │ │
136
+ │ ├── api/v1/routes/ # HTTP route endpoints (items.py, users.py)
137
+ │ ├── core/ # config.py, database.py, security.py
138
+ │ ├── models/ # Database ORM models (item.py, user.py)
139
+ │ ├── schemas/ # Pydantic serialization schemas (item.py, user.py)
140
+ │ ├── services/ # Pure business logic layer
141
+ │ ├── repositories/ # Database CRUD queries layer
142
+ │ └── utils/ # Utility helpers (email.py)
143
+ │
144
+ ├── tests/ # conftest.py, test_items.py, test_users.py
145
+ ├── requirements.txt
146
+ ├── pyproject.toml
147
+ └── README.md
148
+ ```
149
+
150
+ ---
151
+
152
+ ## 🚀 Running Your Generated Project
153
+
154
+ ### 1. Step into your project directory
155
+ ```bash
156
+ cd my_ml_service
157
+ ```
158
+
159
+ ### 2. Create and activate a virtual environment
160
+
161
+ **Windows PowerShell:**
162
+ ```powershell
163
+ python -m venv .venv
164
+ .\.venv\Scripts\Activate.ps1
165
+ ```
166
+
167
+ **Windows CMD:**
168
+ ```cmd
169
+ python -m venv .venv
170
+ call .venv\Scripts\activate.bat
171
+ ```
172
+
173
+ **macOS / Linux:**
174
+ ```bash
175
+ python3 -m venv .venv
176
+ source .venv/bin/activate
177
+ ```
178
+
179
+ ### 3. Install dependencies
180
+ ```bash
181
+ pip install -r requirements.txt
182
+ ```
183
+
184
+ ### 4. Start the server
185
+ ```bash
186
+ python -m uvicorn app.main:app --reload
187
+ ```
188
+
189
+ ---
190
+
191
+ ## 🔍 Interactive API Documentation
192
+
193
+ Once running, visit:
194
+
195
+ - **Swagger UI**: [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
196
+ - **ReDoc**: [http://127.0.0.1:8000/redoc](http://127.0.0.1:8000/redoc)
197
+
198
+ ---
199
+
200
+ ## 🧪 Running Automated Tests
201
+
202
+ Run the included Pytest suite:
203
+
204
+ ```bash
205
+ python -m pytest
206
+ ```
207
+
208
+ Output:
209
+ ```text
210
+ tests\test_predict.py .. [100%]
211
+ ============================== 2 passed in 0.15s ==============================
212
+ ```
213
+
214
+ ---
215
+
216
+ ## 📜 License
217
+
218
+ This project is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fastapi-struct"
7
- version = "0.2.0"
7
+ version = "0.2.1"
8
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"
@@ -0,0 +1 @@
1
+ __version__ = "0.2.1"
@@ -7,14 +7,21 @@ from create_fastapi_app.generator import create_project
7
7
 
8
8
  def main():
9
9
  parser = argparse.ArgumentParser(
10
- prog="create-fastapi-app",
11
- description="Create a new FastAPI project.",
10
+ prog="fastapi-struct",
11
+ description="Create a production-ready FastAPI project.",
12
12
  )
13
13
  parser.add_argument(
14
14
  "name",
15
15
  nargs="?",
16
16
  help="Name of the project to generate (or . for current directory)",
17
17
  )
18
+ parser.add_argument(
19
+ "-t",
20
+ "--template",
21
+ choices=["basic", "ml"],
22
+ default="basic",
23
+ help="Architecture template to use: 'basic' (layered enterprise web API) or 'ml' (AI/ML inference service). Default: basic",
24
+ )
18
25
  parser.add_argument(
19
26
  "--version",
20
27
  action="version",
@@ -28,17 +35,19 @@ def main():
28
35
  sys.exit(2)
29
36
 
30
37
  try:
31
- path = create_project(args.name)
38
+ path = create_project(args.name, template=args.template)
32
39
  except (ValueError, FileExistsError, FileNotFoundError) as exc:
33
40
  parser.error(str(exc))
34
41
 
35
- print(f"\nSuccess! Created project at: {path}")
42
+ template_desc = "AI/ML Inference Service" if args.template == "ml" else "Enterprise Layered Web API"
43
+ print(f"\nSuccess! Created {template_desc} at: {path}")
36
44
  print("\nNext steps:")
37
45
  if args.name != ".":
38
46
  print(f" cd {args.name}")
39
47
  print(" python -m venv .venv")
40
- print(r" .\.venv\Scripts\Activate.ps1")
41
- print(' python -m pip install -e ".[dev]"')
48
+ print(r" .\.venv\Scripts\Activate.ps1 # Windows PowerShell")
49
+ print(" # or: source .venv/bin/activate # macOS / Linux")
50
+ print(" pip install -r requirements.txt")
42
51
  print(" python -m uvicorn app.main:app --reload")
43
52
 
44
53
 
@@ -3,10 +3,10 @@ import re
3
3
  import shutil
4
4
 
5
5
  PACKAGE_DIR = Path(__file__).parent
6
- TEMPLATE_DIR = PACKAGE_DIR / "templates" / "basic"
6
+ TEMPLATES_DIR = PACKAGE_DIR / "templates"
7
7
 
8
8
 
9
- def create_project(name: str) -> Path:
9
+ def create_project(name: str, template: str = "basic") -> Path:
10
10
  if name == ".":
11
11
  project_path = Path.cwd()
12
12
  project_name = project_path.name
@@ -24,13 +24,15 @@ def create_project(name: str) -> Path:
24
24
  f"Destination directory already exists: {project_path}"
25
25
  )
26
26
 
27
- if not TEMPLATE_DIR.is_dir():
27
+ selected_template_dir = TEMPLATES_DIR / template
28
+ if not selected_template_dir.is_dir():
29
+ available = [p.name for p in TEMPLATES_DIR.iterdir() if p.is_dir()]
28
30
  raise FileNotFoundError(
29
- f"Template directory not found: {TEMPLATE_DIR}"
31
+ f"Template '{template}' not found. Available templates: {', '.join(available)}"
30
32
  )
31
33
 
32
34
  # Copy files allowing existing directory (useful when name is '.')
33
- shutil.copytree(TEMPLATE_DIR, project_path, dirs_exist_ok=True)
35
+ shutil.copytree(selected_template_dir, project_path, dirs_exist_ok=True)
34
36
 
35
37
  config_path = project_path / "pyproject.toml"
36
38
  if config_path.exists():
@@ -38,6 +40,9 @@ def create_project(name: str) -> Path:
38
40
  config = config.replace(
39
41
  'name = "my-api"',
40
42
  f'name = "{project_name.lower().replace("_", "-")}"',
43
+ ).replace(
44
+ 'name = "my-ml-api"',
45
+ f'name = "{project_name.lower().replace("_", "-")}"',
41
46
  )
42
47
  config_path.write_text(config, encoding="utf-8")
43
48
 
@@ -0,0 +1,4 @@
1
+ PROJECT_NAME="FastAPI AI Inference Service"
2
+ MODEL_NAME="classifier-v1"
3
+ DEVICE="cpu"
4
+ DEBUG=true
@@ -0,0 +1,4 @@
1
+ PROJECT_NAME="FastAPI AI Inference Service"
2
+ MODEL_NAME="classifier-v1"
3
+ DEVICE="cpu"
4
+ DEBUG=true
@@ -0,0 +1,9 @@
1
+ .venv/
2
+ __pycache__/
3
+ .env
4
+ .pytest_cache/
5
+ *.py[cod]
6
+ *.pt
7
+ *.onnx
8
+ *.bin
9
+ weights/
@@ -0,0 +1,31 @@
1
+ # FastAPI AI/ML Inference Service
2
+
3
+ High-performance AI/ML inference microservice generated with `fastapi-struct --template ml`.
4
+
5
+ ## Quick Start
6
+
7
+ ### 1. Setup Virtual Environment
8
+ ```bash
9
+ python -m venv .venv
10
+ ```
11
+ - Windows: `.\.venv\Scripts\Activate.ps1`
12
+ - macOS/Linux: `source .venv/bin/activate`
13
+
14
+ ### 2. Install Dependencies
15
+ ```bash
16
+ pip install -r requirements.txt
17
+ ```
18
+
19
+ ### 3. Run Inference Server
20
+ ```bash
21
+ python -m uvicorn app.main:app --reload
22
+ ```
23
+
24
+ - Swagger UI: http://127.0.0.1:8000/docs
25
+ - Prediction endpoint: `POST /api/v1/predict/`
26
+ - Health/Readiness probe: `GET /api/v1/health`
27
+
28
+ ### 4. Run Tests
29
+ ```bash
30
+ python -m pytest
31
+ ```
@@ -0,0 +1,6 @@
1
+ from fastapi import APIRouter
2
+ from app.api.v1.routes import health, predict
3
+
4
+ api_router = APIRouter()
5
+ api_router.include_router(health.router)
6
+ api_router.include_router(predict.router)
@@ -0,0 +1,15 @@
1
+ from fastapi import APIRouter
2
+ from app.core.config import settings
3
+ from app.ml.model import ml_model
4
+ from app.schemas.predict import HealthResponse
5
+
6
+ router = APIRouter(tags=["Health"])
7
+
8
+
9
+ @router.get("/health", response_model=HealthResponse)
10
+ async def health_check():
11
+ return {
12
+ "status": "healthy" if ml_model.is_loaded else "degraded",
13
+ "model_loaded": ml_model.is_loaded,
14
+ "device": settings.DEVICE,
15
+ }
@@ -0,0 +1,16 @@
1
+ from fastapi import APIRouter, HTTPException, status
2
+ from app.schemas.predict import PredictionRequest, PredictionResponse
3
+ from app.services.inference import inference_service
4
+
5
+ router = APIRouter(prefix="/predict", tags=["Inference"])
6
+
7
+
8
+ @router.post("/", response_model=PredictionResponse, status_code=status.HTTP_200_OK)
9
+ async def predict(payload: PredictionRequest):
10
+ try:
11
+ return inference_service.run_prediction(payload)
12
+ except Exception as exc:
13
+ raise HTTPException(
14
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
15
+ detail=f"Inference error: {str(exc)}",
16
+ )
@@ -0,0 +1,20 @@
1
+ from pydantic_settings import BaseSettings, SettingsConfigDict
2
+
3
+
4
+ class Settings(BaseSettings):
5
+ PROJECT_NAME: str = "FastAPI AI Inference Service"
6
+ API_V1_STR: str = "/api/v1"
7
+ DEBUG: bool = True
8
+ MODEL_NAME: str = "classifier-v1"
9
+ MODEL_PATH: str = "models/weights.bin"
10
+ DEVICE: str = "cpu" # "cpu" or "cuda"
11
+ MAX_BATCH_SIZE: int = 32
12
+ API_KEY: str = "secret_ai_key"
13
+
14
+ model_config = SettingsConfigDict(
15
+ env_file=".env",
16
+ extra="ignore",
17
+ )
18
+
19
+
20
+ settings = Settings()