File size: 1,879 Bytes
bd91486
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import Dict, Optional

class CodeTemplates:
    """Code templates for various programming patterns and frameworks."""
    
    def __init__(self):
        self.templates: Dict[str, Dict[str, str]] = {
            "api": {
                "python-fastapi": self._python_fastapi_template(),
                "python-flask": self._python_flask_template(),
                "node-express": self._node_express_template(),
                "go-gin": self._go_gin_template(),
                "rust-actix": self._rust_actix_template()
            },
            "cli": {
                "python-click": self._python_click_template(),
                "rust-clap": self._rust_clap_template(),
                "go-cobra": self._go_cobra_template()
            },
            "gui": {
                "python-tkinter": self._python_tkinter_template(),
                "typescript-react": self._typescript_react_template(),
                "kotlin-compose": self._kotlin_compose_template()
            }
        }
    
    def get_template(self, category: str, tech_stack: str) -> Optional[str]:
        """Get a specific template by category and technology stack."""
        return self.templates.get(category, {}).get(tech_stack)
    
    def _python_fastapi_template(self) -> str:
        return '''
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}

@app.get("/items/{item_id}")
async def read_item(item_id: int):
    return {"item_id": item_id}
'''

    def _python_flask_template(self) -> str:
        return '''
from flask import Flask, jsonify

app = Flask(__name__)

@app.route("/")
def hello_world():
    return jsonify({"message": "Hello World"})

if __name__ == "__main__":
    app.run(debug=True)
'''

    # Add more template methods for other frameworks...