-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
186 lines (163 loc) · 6.23 KB
/
app.py
File metadata and controls
186 lines (163 loc) · 6.23 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
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
# Enhanced Knowledge base of Stacks with Pros/Cons and Budget info
STACKS = {
"MERN": {
"name": "MERN Stack (MongoDB, Express, React, Node)",
"pros": [
"Single language (JavaScript) everywhere",
"Huge community and ecosystem",
"Great for JSON data and APIs",
"Fast development with reusable components",
"Excellent for real-time applications"
],
"cons": [
"Can be complex for beginners",
"Heavy for simple applications",
"SEO challenges (though Next.js helps)",
"Rapid ecosystem changes"
],
"budget": "medium",
"hosting_cost": "$10-50/month",
"learning_curve": "medium",
"best_for": ["realtime", "spa", "api"]
},
"Django": {
"name": "Django Stack (Python, SQL, Django)",
"pros": [
"Batteries included framework",
"Secure by default",
"Excellent ORM and admin panel",
"Great for rapid prototyping",
"Strong community and documentation"
],
"cons": [
"Monolithic structure",
"Can be overkill for simple projects",
"Steeper learning curve",
"Less flexible than microframeworks"
],
"budget": "low",
"hosting_cost": "$5-30/month",
"learning_curve": "high",
"best_for": ["cms", "enterprise", "data-heavy"]
},
"LAMP": {
"name": "LAMP Stack (Linux, Apache, MySQL, PHP)",
"pros": [
"Extremely cheap hosting options",
"Easy deployment and setup",
"Mature and stable ecosystem",
"Great for traditional web apps",
"Huge talent pool"
],
"cons": [
"Inconsistent language syntax",
"Performance issues at scale",
"Considered outdated by some",
"Security requires more attention"
],
"budget": "low",
"hosting_cost": "$3-15/month",
"learning_curve": "low",
"best_for": ["simple", "cms", "traditional"]
},
"Next.js": {
"name": "Next.js Stack (React, Node, Vercel)",
"pros": [
"Excellent SEO with SSR/SSG",
"Great developer experience",
"Built-in optimization",
"Easy deployment",
"Modern React patterns"
],
"cons": [
"Vendor lock-in with Vercel",
"Can be complex for simple sites",
"Rapid updates and changes",
"Learning curve for beginners"
],
"budget": "medium",
"hosting_cost": "$0-100/month",
"learning_curve": "medium",
"best_for": ["spa", "seo-critical", "modern"]
}
}
def calculate_stack_score(stack_data, project_type, team_skill, budget):
"""Calculate a score for how well a stack matches the requirements"""
score = 0
# Project type matching
if project_type in stack_data["best_for"]:
score += 3
# Budget matching
budget_scores = {"low": 3, "medium": 2, "high": 1}
if budget == "low" and stack_data["budget"] == "low":
score += 3
elif budget == "medium" and stack_data["budget"] in ["low", "medium"]:
score += 2
elif budget == "high":
score += 1
# Team skill matching
skill_stack_match = {
"js": ["MERN", "Next.js"],
"python": ["Django"],
"php": ["LAMP"],
"mixed": ["LAMP", "Django"]
}
stack_name = stack_data["name"].split()[0]
if stack_name in skill_stack_match.get(team_skill, []):
score += 2
return score
@app.route('/')
def home():
return render_template('index.html')
@app.route('/compare', methods=['POST'])
def compare():
data = request.json
project_type = data.get('projectType')
team_skill = data.get('teamSkill')
budget = data.get('budget', 'medium')
# Calculate scores for all stacks
stack_scores = []
for stack_key, stack_data in STACKS.items():
score = calculate_stack_score(stack_data, project_type, team_skill, budget)
stack_scores.append((stack_key, stack_data, score))
# Sort by score (highest first)
stack_scores.sort(key=lambda x: x[2], reverse=True)
# Get top 2 recommendations
primary = stack_scores[0]
secondary = stack_scores[1]
# Generate intelligent verdict
verdict = generate_verdict(primary, secondary, project_type, budget)
response = {
"optionA": {
**primary[1],
"score": primary[2],
"match_reason": get_match_reason(primary[1], project_type, team_skill, budget)
},
"optionB": {
**secondary[1],
"score": secondary[2],
"match_reason": get_match_reason(secondary[1], project_type, team_skill, budget)
},
"verdict": verdict
}
return jsonify(response)
def get_match_reason(stack_data, project_type, team_skill, budget):
"""Generate a reason why this stack matches the requirements"""
reasons = []
if project_type in stack_data["best_for"]:
reasons.append(f"Perfect for {project_type} projects")
if budget == "low" and stack_data["budget"] == "low":
reasons.append("Budget-friendly option")
return " • ".join(reasons) if reasons else "Good general-purpose choice"
def generate_verdict(primary, secondary, project_type, budget):
"""Generate an intelligent verdict based on the comparison"""
primary_name = primary[1]["name"].split()[0]
secondary_name = secondary[1]["name"].split()[0]
if primary[2] > secondary[2] + 1:
return f"{primary_name} is clearly the better choice for your {project_type} project with {budget} budget constraints."
else:
return f"Both {primary_name} and {secondary_name} are solid choices. {primary_name} edges out slightly, but consider your team's expertise and long-term goals."
if __name__ == '__main__':
app.run(debug=True)