{"stack": "python-fastapi", "files": {"main.py": "\"\"\"\nExample FastAPI app for Niblit.ai.\nThis is a minimal API with SQLite persistence.\n\"\"\"\n\nimport os\nimport sqlite3\nfrom contextlib import contextmanager\nfrom typing import Optional\nfrom fastapi import FastAPI, HTTPException\nfrom fastapi.responses import HTMLResponse\nfrom pydantic import BaseModel\n\napp = FastAPI(\n    title=\"Notes API\",\n    description=\"A simple notes API powered by Niblit.ai\",\n    version=\"1.0.0\"\n)\n\n# Database path - MUST use /data/ for persistence\nDATABASE_PATH = os.environ.get('DATABASE_PATH', '/data/app.db')\n\n\n@contextmanager\ndef get_db():\n    \"\"\"Get database connection.\"\"\"\n    conn = sqlite3.connect(DATABASE_PATH)\n    conn.row_factory = sqlite3.Row\n    try:\n        yield conn\n    finally:\n        conn.close()\n\n\ndef init_db():\n    \"\"\"Initialize the database schema.\"\"\"\n    with get_db() as db:\n        db.execute('''\n            CREATE TABLE IF NOT EXISTS notes (\n                id INTEGER PRIMARY KEY AUTOINCREMENT,\n                title TEXT NOT NULL,\n                content TEXT,\n                created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n            )\n        ''')\n        db.commit()\n\n\n# Pydantic models\nclass NoteCreate(BaseModel):\n    title: str\n    content: Optional[str] = None\n\n\nclass Note(BaseModel):\n    id: int\n    title: str\n    content: Optional[str]\n    created_at: str\n\n\n# Initialize database on startup\n@app.on_event(\"startup\")\ndef startup():\n    init_db()\n\n\n@app.get(\"/\", response_class=HTMLResponse)\ndef home():\n    \"\"\"Home page with links to API docs.\"\"\"\n    return \"\"\"\n    <!DOCTYPE html>\n    <html>\n    <head>\n        <title>Notes API - Niblit.ai</title>\n        <style>\n            body { font-family: -apple-system, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }\n            h1 { color: #4F46E5; }\n            a { color: #4F46E5; }\n            code { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; }\n            .endpoint { margin: 10px 0; padding: 10px; background: #f9fafb; border-radius: 4px; }\n        </style>\n    </head>\n    <body>\n        <h1>Notes API</h1>\n        <p>A simple REST API for managing notes.</p>\n\n        <h2>Endpoints</h2>\n        <div class=\"endpoint\"><code>GET /notes</code> - List all notes</div>\n        <div class=\"endpoint\"><code>POST /notes</code> - Create a note</div>\n        <div class=\"endpoint\"><code>GET /notes/{id}</code> - Get a note</div>\n        <div class=\"endpoint\"><code>DELETE /notes/{id}</code> - Delete a note</div>\n\n        <p><a href=\"/docs\">Interactive API Documentation (Swagger UI)</a></p>\n        <p><a href=\"/redoc\">Alternative Documentation (ReDoc)</a></p>\n\n        <div style=\"margin-top: 40px; color: #999; font-size: 14px;\">\n            Powered by <a href=\"https://niblit.ai\">Niblit.ai</a>\n        </div>\n    </body>\n    </html>\n    \"\"\"\n\n\n@app.get(\"/notes\", response_model=list[Note])\ndef list_notes():\n    \"\"\"List all notes.\"\"\"\n    with get_db() as db:\n        notes = db.execute('SELECT * FROM notes ORDER BY created_at DESC').fetchall()\n        return [dict(note) for note in notes]\n\n\n@app.post(\"/notes\", response_model=Note)\ndef create_note(note: NoteCreate):\n    \"\"\"Create a new note.\"\"\"\n    with get_db() as db:\n        cursor = db.execute(\n            'INSERT INTO notes (title, content) VALUES (?, ?)',\n            (note.title, note.content)\n        )\n        db.commit()\n        new_note = db.execute('SELECT * FROM notes WHERE id = ?', (cursor.lastrowid,)).fetchone()\n        return dict(new_note)\n\n\n@app.get(\"/notes/{note_id}\", response_model=Note)\ndef get_note(note_id: int):\n    \"\"\"Get a specific note.\"\"\"\n    with get_db() as db:\n        note = db.execute('SELECT * FROM notes WHERE id = ?', (note_id,)).fetchone()\n        if not note:\n            raise HTTPException(status_code=404, detail=\"Note not found\")\n        return dict(note)\n\n\n@app.delete(\"/notes/{note_id}\")\ndef delete_note(note_id: int):\n    \"\"\"Delete a note.\"\"\"\n    with get_db() as db:\n        result = db.execute('DELETE FROM notes WHERE id = ?', (note_id,))\n        db.commit()\n        if result.rowcount == 0:\n            raise HTTPException(status_code=404, detail=\"Note not found\")\n        return {\"message\": \"Note deleted\"}\n\n\n@app.get(\"/health\")\ndef health():\n    \"\"\"Health check endpoint.\"\"\"\n    return {\"status\": \"ok\"}\n", "requirements.txt": "fastapi\nuvicorn[standard]\n", "Dockerfile": "FROM python:3.12-slim\n\nWORKDIR /app\n\n# Install dependencies first (better caching)\nCOPY requirements.txt .\nRUN pip install --no-cache-dir -r requirements.txt\n\n# Copy application code\nCOPY . .\n\n# Create data directory for persistent storage\nRUN mkdir -p /data\n\n# Environment variables\nENV PORT=8080\nENV DATABASE_PATH=/data/app.db\n\nEXPOSE 8080\n\n# Run with uvicorn for production\nCMD [\"uvicorn\", \"main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"8080\"]\n"}}