2.3 KiB
2.3 KiB
Project Migration Task: Python/FastAPI to Bun/Hono
1. Role & Objective
Act as a Senior Backend Engineer expert in both Python (FastAPI) and the modern JavaScript/TypeScript ecosystem (Bun runtime).
Your Goal: Rewrite the existing API service located in the python-ref/ directory using Bun, Hono, and SQLite.
2. Source Code Context
The source code is located in the python-ref/ folder. It currently runs on:
- Python 3.x
- FastAPI
- SQLite3 (standard library)
3. Target Technology Stack
You must use the following stack for the rewrite:
- Runtime: Bun (latest version)
- Framework: Hono (latest version)
- Database: Native
bun:sqlite(do not use generic node-sqlite3 unless necessary, prefer Bun's native high-performance driver). - Language: TypeScript
4. Strict Requirements
The new service must be a "drop-in" replacement. Adhere to the following rules strictly:
A. Database Integrity
- Analyze the SQL schemas or ORM models in
python-ref. - Recreate the exact same database table structures (table names, column names, data types, constraints).
- If the Python code uses an ORM (like SQLAlchemy or Tortoise), translate the logic to raw SQL or a lightweight query builder suitable for
bun:sqlite.
B. API Consistency
- Keep all API URL paths exactly the same (e.g., if Python has
/api/v1/users, Hono must have/api/v1/users). - Keep HTTP Methods exactly the same (GET, POST, PUT, DELETE).
- Keep Request/Response JSON formats exactly the same. Field names must not change (e.g., do not change
user_idtouserIdin the JSON response, keep it consistent with the old API).
C. Code Structure
- Organize the code logically (e.g., separate
db.tsfor database connections,index.tsfor routes). - Use TypeScript interfaces to define the shape of Request/Response bodies.
5. Deliverables
Please read the files in python-ref/ recursively. Then, generate the following:
- Project Setup: The
package.jsoncommand or content needed to install dependencies. - Database Setup: A script or function to initialize the SQLite database matching the old schema.
- Application Code: The full source code for the Hono application.
Start by analyzing the key files in python-ref/ and summarizing the endpoints and schema you found, then proceed to write the code.