🤖 AI Prompt Library API
A REST API for sharing, browsing, and upvoting AI prompts.
Built with Flask, PostgreSQL, and psycopg2 — clean, modular, and perfect for dev portfolios.
🚀 Features
- CRUD endpoints for AI prompts
- Category management
- Upvote system
- Random prompt endpoint
- Swagger docs for easy testing
- PostgreSQL database connection (psycopg2)
- Ready for hosting (Render, Railway, etc.)
🧩 Tech Stack
| Layer | Tech |
|---|---|
| Backend | Flask |
| Database | PostgreSQL |
| ORM/Driver | psycopg2 |
| Docs | flasgger (Swagger UI) |
| Testing | pytest |
⚙️ Setup
- Clone the repo
git clone https://github.com/<yourusername>/ai-prompt-api.git
cd ai-prompt-api- Set up a virtual environment
python -m venv venv
source venv/bin/activate # Mac/Linux
venv\Scripts\activate # Windows- Install dependencies
pip install -r requirements.txt- Set up PostgreSQL Create a new database called promptdb (or any name you want):
CREATE DATABASE promptdb;Then run the schema:
psql -U postgres -d promptdb -f app/models.sql🔐 Environment Variables
Create a .env file in the project root:
DB_NAME=promptdb
DB_USER=postgres
DB_PASSWORD=yourpassword
DB_HOST=localhost
🧠 Run the Server
flask runThe API should now be live at:
http://localhost:5000
Swagger Docs available at:
http://localhost:5000/apidocs
🧠 Example JSON POST /prompts
{
"title": "Creative character generation",
"prompt_text": "Generate a unique character for a fantasy novel with personality traits.",
"category_id": 1,
"model_type": "GPT-4"
}🧪 Testing Run all tests:
pytest📘 API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /prompts | Get all prompts |
| POST | /prompts | Create a new prompt |
| GET | /prompts/ | Get one prompt |
| POST | /prompts//upvote | Upvote a prompt |
| GET | /categories | List all categories |
| POST | /categories | Add a new category |
| GET | /random | Get a random prompt |
🌈 Future Ideas
- Add JWT user auth
- Add prompt tags (many-to-many)
- Add favorites/bookmarks
- Add AI-generated “prompt of the day”
- Frontend dashboard with React
💫 License MIT License © Elisa