Repo rules
- This provisioning code is designed to run on Manjaro Linux.
This outlines how we build **structured perfection** for [Project Name] with a Python-based API server, extensions, and more.
Sign in to like and favorite skills
- This provisioning code is designed to run on Manjaro Linux.
.llmrules
Code Style and Structure
This outlines how we build structured perfection for [Project Name] with a Python-based API server, extensions, and more.
is_valid_user, has_token_expired).Hereβs the shiny, revised structure focusing on Python APIs in
server/:
server/ βββ src/ β βββ api/ # RESTful API endpoints (FastAPI preferred) β βββ models/ # ORM models (e.g., SQLAlchemy, Pydantic) β βββ schemas/ # Input/output validation schemas (e.g., Pydantic) β βββ services/ # Business logic and service layer β βββ utils/ # Reusable helper functions β βββ middleware/ # Custom FastAPI middleware β βββ tests/ # Unit and integration tests β βββ __init__.py # Make folders Python modules extension/ βββ src/ β βββ background/ β βββ content/ β βββ popup/ β βββ options/ β βββ components/ β βββ hooks/ β βββ utils/ β βββ lib/ β βββ types/ β βββ storage/ shared/ βββ src/ β βββ types/ # Shared TypeScript types β βββ utils/ # Shared utilities (e.g., date formatting)
π Important: Add
.venv to .gitignore (we donβt want Hue accidentally version-controlling the virtual environment)! A sample .gitignore for Python:
# Ignore Python virtual environment .venv/ # Ignore common Python artifacts *.pyc __pycache__/
To keep things smooth and sandboxed:
python -m venv .venv to create a local virtual environment.source .venv/bin/activate.venv\Scripts\activatepip right away to avoid package chaos:
pip install --upgrade pip
Hereβs how your
server/src/api/ folder could be structured:
server/src/api/ βββ v1/ # Versioned API structure β βββ users.py # User endpoints β βββ auth.py # Auth endpoints β βββ health.py # Health checks β βββ __init__.py βββ dependencies.py # Dependency injection helpers βββ errors.py # Custom API exception handling βββ __init__.py
from fastapi import APIRouter, HTTPException from pydantic import BaseModel router = APIRouter() class User(BaseModel): username: str email: str @router.post("/users", summary="Create a new user") async def create_user(user: User): if not user.email.endswith("@example.com"): raise HTTPException(status_code=400, detail="Invalid email domain") # Simulate user saving return {"status": "success", "data": user.dict()}
Letβs keep day-to-day server tasks hassle-free with a
scripts/manage.sh script:
#!/bin/bash ACTION=${1:-help} case "$ACTION" in "start") echo "π Starting the Python server..." uvicorn src.api.main:app --reload ;; "stop") echo "π Stopping the Python server (assuming Docker or background process)..." ;; "test") echo "π§ͺ Running tests..." pytest --cov=src ;; "setup") echo "π§ Setting up the environment..." python -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt ;; "help"|"") echo "ποΈ Usage: scripts/manage.sh {start|stop|test|setup}" ;; *) echo "β Unknown action: $ACTION" exit 1 ;; esac
Run this script for setup, testing, and more! Hue, enjoy the added flair in your terminal ("spicy life," as Trisha would say πΆοΈ).
pip install pytest pytest-cov).from fastapi.testclient import TestClient from src.api.main import app client = TestClient(app) def test_health_check(): response = client.get("/health") assert response.status_code == 200 assert response.json() == {"status": "ok"}
Hue, remember: Security is paramount. Here's your checklist: