-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
245 lines (212 loc) · 7.39 KB
/
demo.py
File metadata and controls
245 lines (212 loc) · 7.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/usr/bin/env python3
"""
Demo script showing the FastAPI Scaffold CLI structure
This demonstrates what the tool does without needing to install dependencies
"""
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from fastapi_scaffold.config import ProjectConfig, PresetType, DatabaseType, ORMType, AuthType, get_preset_config
from fastapi_scaffold.generator import ProjectGenerator
def demo_config():
"""Show different configuration options"""
print("=" * 80)
print("FastAPI Scaffold - Configuration Demo")
print("=" * 80)
# Show minimal preset
print("\n1️⃣ MINIMAL PRESET")
print("-" * 40)
minimal = get_preset_config(PresetType.MINIMAL, "my-minimal-api")
print(f"Project: {minimal.project_name}")
print(f"Database: {minimal.database.value}")
print(f"Auth: {minimal.auth.value}")
print(f"Docker: {minimal.include_docker}")
# Show SaaS preset
print("\n2️⃣ SAAS PRESET (Full-Featured)")
print("-" * 40)
saas = get_preset_config(PresetType.SAAS, "my-saas-app")
print(f"Project: {saas.project_name}")
print(f"Database: {saas.database.value}")
print(f"ORM: {saas.orm.value}")
print(f"Auth: {saas.auth.value}")
print(f"Cache: {saas.cache.value}")
print(f"Task Queue: {saas.task_queue.value}")
print(f"Docker: {saas.include_docker}")
print(f"CI/CD: {saas.ci_type.value}")
print(f"Monitoring: {saas.include_monitoring}")
print(f"User Management: {saas.include_user_management}")
# Show custom config
print("\n3️⃣ CUSTOM CONFIGURATION")
print("-" * 40)
custom = ProjectConfig(
project_name="My Custom API",
project_slug="my-custom-api",
description="A custom FastAPI project",
database=DatabaseType.POSTGRES,
orm=ORMType.SQLALCHEMY_ASYNC,
auth=AuthType.JWT,
include_docker=True,
include_tests=True,
include_ci=True,
)
print(f"Project: {custom.project_name}")
print(f"Slug: {custom.project_slug}")
print(f"Python Package: {custom.python_package_name}")
print(f"Database: {custom.database.value}")
print(f"ORM: {custom.orm.value}")
print(f"Auth: {custom.auth.value}")
def demo_structure():
"""Show what directory structure would be created"""
print("\n" + "=" * 80)
print("Generated Project Structure")
print("=" * 80)
structure = """
my-project/
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI application entry point
│ ├── api/
│ │ ├── __init__.py
│ │ └── v1/
│ │ ├── __init__.py
│ │ ├── api.py # Router aggregation
│ │ └── endpoints/
│ │ ├── __init__.py
│ │ ├── health.py # Health check endpoints
│ │ ├── auth.py # Authentication (if enabled)
│ │ └── users.py # User management (if enabled)
│ ├── core/
│ │ ├── __init__.py
│ │ ├── config.py # Pydantic settings
│ │ ├── security.py # JWT & password hashing (if auth)
│ │ └── deps.py # FastAPI dependencies
│ ├── models/
│ │ ├── __init__.py
│ │ ├── domain/ # Pydantic models
│ │ └── database/ # SQLAlchemy models (if DB)
│ ├── schemas/ # Request/Response schemas
│ │ └── __init__.py
│ ├── services/ # Business logic layer
│ │ └── __init__.py
│ └── repositories/ # Database access (if DB)
│ └── __init__.py
├── tests/
│ ├── __init__.py
│ ├── conftest.py # Pytest fixtures
│ ├── test_api.py # API tests
│ ├── api/ # API endpoint tests
│ └── services/ # Service tests
├── alembic/ # Database migrations (if DB)
│ ├── env.py
│ ├── script.py.mako
│ └── versions/
├── scripts/ # Utility scripts
├── docker/
│ └── (optional based on config)
├── .github/ # CI/CD (if enabled)
│ └── workflows/
│ └── ci.yml
├── .env.example # Environment variables template
├── .gitignore
├── Dockerfile # Docker (if enabled)
├── docker-compose.yml # Docker Compose (if enabled)
├── pyproject.toml # Project dependencies
└── README.md # Generated documentation
"""
print(structure)
def demo_files():
"""Show examples of generated files"""
print("\n" + "=" * 80)
print("Sample Generated Files")
print("=" * 80)
print("\n📄 app/main.py (FastAPI Application)")
print("-" * 40)
print('''"""
My Project - FastAPI Application
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.v1.api import api_router
app = FastAPI(
title="My Project",
description="A FastAPI project",
version="0.1.0",
)
# CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include API router
app.include_router(api_router, prefix="/api/v1")
@app.get("/health")
async def health_check():
return {"status": "healthy", "version": "0.1.0"}
''')
print("\n📄 app/core/config.py (Configuration)")
print("-" * 40)
print('''"""
Application configuration
"""
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
PROJECT_NAME: str = "My Project"
VERSION: str = "0.1.0"
DEBUG: bool = True
DATABASE_URL: str = "postgresql+asyncpg://user:pass@localhost/db"
SECRET_KEY: str = "your-secret-key"
class Config:
env_file = ".env"
settings = Settings()
''')
print("\n📄 pyproject.toml (Dependencies)")
print("-" * 40)
print('''[project]
name = "my-project"
version = "0.1.0"
dependencies = [
"fastapi>=0.109.0",
"uvicorn[standard]>=0.27.0",
"pydantic>=2.5.0",
"sqlalchemy>=2.0.0",
"asyncpg>=0.29.0",
"alembic>=1.13.0",
"python-jose[cryptography]>=3.3.0",
"passlib[bcrypt]>=1.7.4",
]
''')
print("\n📄 tests/test_api.py (Tests)")
print("-" * 40)
print('''"""
API endpoint tests
"""
def test_health_check(client):
response = client.get("/health")
assert response.status_code == 200
assert response.json()["status"] == "healthy"
''')
def main():
"""Run all demos"""
print("\n🚀 FastAPI Scaffold CLI - Demo\n")
demo_config()
demo_structure()
demo_files()
print("\n" + "=" * 80)
print("✅ This is what the FastAPI Scaffold CLI will generate!")
print("=" * 80)
print("\n📦 To use the actual CLI:")
print(" 1. uv sync # Install dependencies")
print(" 2. uv run fastapi-scaffold create my-project")
print(" 3. cd my-project")
print(" 4. uv sync")
print(" 5. uv run uvicorn app.main:app --reload")
print("\n🌟 Or use presets:")
print(" fastapi-scaffold create my-api --preset saas")
print(" fastapi-scaffold create my-api --preset minimal")
print("\n")
if __name__ == "__main__":
main()