PromptBase
Upgrade
Close icon
General
Home
Marketplace
Create
Hire
Login
Chat
Sell
Explore

Prompt Details

Model
(claude-4-7-opus)
Token size
527
Example input
[LEGACY_TECH_STACK]: Python 2.7 procedural script with legacy MySQLdb connectors [TARGET_TECH_STACK]: Python 3.11 with FastAPI async framework and Pydantic validation [LEGACY_CODE_CONTEXT]: import MySQLdb import urllib2 def process_user_data(user_id): db = MySQLdb.connect("localhost","admin","pass","db") cursor = db.cursor() cursor.execute("SELECT email FROM users WHERE id = %s" % user_id) row = cursor.fetchone() if row: email = row.__getitem__(0) response = urllib2.urlopen("https://api.external.com/verify?email=" + email) data = response.read() print "Processed user: ", user_id return data return None [MIGRATION_CONSTRAINTS]: Must be fully asynchronous and eliminate the raw SQL string interpolation security flaw.
Example output
# Legacy Migration & Modernization Blueprint ## PHASE 1: DEPENDENCY & OBSOLESCENCE MAPPING **Legacy Stack Audit:** - Use of deprecated Python 2.7 print statements and procedural execution block. - Use of outdated, synchronous, and insecure database connector drivers. - Complete lack of type hinting, making the script prone to runtime errors during scaling. **Dependency Translation Table:** - Legacy: `urllib2` -> Modern: `httpx` (Asynchronous HTTP client) - Legacy: `MySQLdb` -> Modern: `SQLAlchemy` (Async session engine) with `asyncpg` or `aiomysql` ## PHASE 2: TARGET ARCHITECTURE DESIGN **Structural Blueprint:** The legacy procedural script executes database writes and API calls in a single monolithic thread block. The target architecture will decouple this logic using the Router-Service-Repository pattern inside FastAPI. This separates the HTTP endpoint transport layer from the internal business rules and data access layer, allowing for asynchronous concurrency. **Data Flow Transformation:** Requests will be ingested via Pydantic schemas (validating types at entry), processed by an async service handler, and persisted using asynchronous SQLAlchemy sessions, preventing thread-blocking bottlenecks. ## PHASE 3: SYNTAX MIGRATION & TRANSLATION ### Legacy Implementation (Python 2.7) ```python import MySQLdb import urllib2 def process_user_data(user_id): db = MySQLdb.connect("localhost","admin","pass","db") cursor = db.cursor() cursor.execute("SELECT email FROM users WHERE id = %s" % user_id) row = cursor.fetchone() if row: email = row[0] response = urllib2.urlopen("[https://api.external.com/verify?email=](https://api.external.com/verify?email=)" + email) data = response.read() print "Processed user: ", user_id return data return None ``` ### Modern Implementation (Python 3.11 + FastAPI Async) ```python from fastapi import FastAPI, HTTPException, Depends from pydantic import BaseModel, EmailStr from sqlalchemy.ext.asyncio import AsyncSession import httpx class UserResponse(BaseModel): user_id: int verification_data: str async def get_user_email(session: AsyncSession, user_id: int) -> str: query = "SELECT email FROM users WHERE id = :id" result = await session.execute(query, {"id": user_id}) row = result.fetchone() if not row: raise HTTPException(status_code=404, detail="User not found") return row[0] async def fetch_verification(email: EmailStr) -> str: async with httpx.AsyncClient() as client: response = await client.get(f"[https://api.external.com/verify](https://api.external.com/verify)", params={"email": email}) if response.status_code != 200: raise HTTPException(status_code=502, detail="External API error") return response.text ``` ## PHASE 4: REGRESSION GUARDRAILS & RISK MITIGATION 1. *SQL Injection Vulnerability during Porting:* The old script used raw string interpolation (`%s`) for database queries. *Mitigation:* The modern code strictly enforces parameterized execution bindings through SQLAlchemy core objects to mitigate injection attacks completely. 2. *Asynchronous Connection Depletion:* Shifting to async endpoints without connection pooling can exhaust the database connection limits rapidly. *Mitigation:* Enforce an explicit connection pool limit size inside the FastAPI database dependency setup block.
🌀 Claude

Enterprise Legacy Code Modernizer

Add to Cart
Instant accessInstant access
Usage rightsCommercial use
Money-back guaranteeMoney‑back
By purchasing this prompt, you agree to our terms of service
CLAUDE-4-7-OPUS
Tested icon
Guide icon
4 examples icon
Free credits icon
Stop drowning in technical debt and outdated dependencies. This prompt acts as a Principal Software Architect specializing in legacy modernization, transforming archaic code or monolithic logic into clean, modern architectures. It maps anti-patterns, designs strict dependency deprecation paths, and provides side-by-side migration code syntax. Designed for engineering teams looking to port legacy systems safely without regression risks. No overpromises, just rock-solid code porting strategy.
...more
Added 3 weeks ago
Report
Browse Marketplace