Skip to main content

Snipster

A code snippet management application built with FastAPI backend and Reflex frontend.

Development Setup

Prerequisites

  • Python 3.8+
  • uv package manager

For the fastest setup, use the provided Makefile commands:

# Install dependencies and start backend server
make dev

# In another terminal, start the frontend
make ui

This will automatically:

  • Install all dependencies
  • Initialize the database
  • Start the FastAPI backend at http://localhost:8000
  • Start the Reflex frontend at http://localhost:3000

Manual Setup

If you prefer to run commands manually, follow the steps below.

Backend (FastAPI)

The FastAPI backend provides the REST API for managing code snippets.

  1. Navigate to the project root:

    cd snipster
    
  2. Install dependencies:

    uv sync
    
  3. Initialize the database (REQUIRED):

    uv run alembic upgrade head
    

    Important: This step is required before starting the server. It creates the database tables and schema.

  4. Start the FastAPI development server:

    uv run fastapi dev src/snipster/api.py
    

    The API will be available at http://localhost:8000

  5. Optional: Run tests:

    uv run pytest
    

Frontend (Reflex)

The Reflex frontend provides a modern web interface for managing snippets.

  1. Navigate to the frontend directory:

    cd ui
    
  2. Install dependencies:

    uv sync
    
  3. Start the Reflex development server:

    uv run reflex run
    

    The frontend will be available at http://localhost:3000

  4. Optional: Build for production:

    uv run reflex export
    

Database Management

Alembic Migrations

Alembic handles database schema migrations for the project.

  1. Create a new migration:

    uv run alembic revision --autogenerate -m "Description of changes"
    
  2. Apply pending migrations:

    uv run alembic upgrade head
    
  3. Rollback to previous migration:

    uv run alembic downgrade -1
    ``****`
    
  4. View migration history:

    uv run alembic history
    
  5. Check current migration status:

    uv run alembic current
    

Note: Always review auto-generated migrations before applying them to production.

Project Structure

Backend (src/snipster/)

  • api.py: FastAPI application with REST endpoints
  • models.py: Pydantic models for request/response validation
  • repo.py: Data access layer for snippets
  • db.py: Database connection and session management
  • cli.py: Command-line interface for snippet management

Frontend (ui/)

  • ui/ui.py: Main Reflex application with UI components
  • rxconfig.py: Reflex configuration (ports, app name)
  • pyproject.toml: Frontend dependencies and configuration

Database

  • alembic/: Database schema migrations
  • snipster.sqlite: SQLite database file

Development Tools

  • pyproject.toml: Project configuration and dependencies
  • Makefile: Common development commands
  • .pre-commit-config.yaml: Code quality hooks
  • tests/: Comprehensive test suite

API Endpoints

  • GET /health - Health check

    GET /health
    Response: {"status": "ok"}
    
  • POST /create - Create new snippet

    POST /create
    {
      "title": "Hello World",
      "code": "print('Hello World')",
      "language": "python",
      "tags": ["example", "hello"]
    }
    
  • GET /snippets - List all snippets

    GET /snippets
    Response: [
      {
        "id": 1,
        "title": "Hello World",
        "code": "print('Hello World')",
        "language": "python",
        "tags": ["example", "hello"]
      }
    ]
    
  • GET /snippets/{id} - Get snippet by ID

    GET /snippets/1
    Response: {
      "id": 1,
      "title": "Hello World",
      "code": "print('Hello World')",
      "language": "python",
      "tags": ["example", "hello"]
    }
    
  • DELETE /snippets/{id} - Delete snippet

    DELETE /snippets/1
    Response: {"message": "Snippet deleted"}
    
  • POST /snippets/{id}/toggle-favorite - Toggle favorite status

    POST /snippets/1/toggle-favorite
    Response: {"id": 1, "is_favorite": true}
    
  • POST /snippets/{id}/add-tags - Add tags to snippet

    POST /snippets/1/add-tags
    {
      "tags": ["new", "tags"]
    }
    Response: {
      "id": 1,
      "tags": ["example", "hello", "new", "tags"]
    }
    
  • GET /search - Search snippets by query string

    GET /search?q=hello
    Response: [
      {
        "id": 1,
        "title": "Hello World",
        "code": "print('Hello World')",
        "language": "python",
        "tags": ["example", "hello"]
      }
    ]
    

Development Workflow

  1. Start the FastAPI backend first
  2. Start the Reflex frontend
  3. Make changes to either backend or frontend
  4. Both servers support hot reloading for development

Metadata

Release files for pdc-snipster-cli 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdc-snipster-cli 0.1.0
File Size Uploaded
pdc_snipster_cli-0.1.0.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pdc-snipster-cli 0.1.0
File Interpreter ABI Platform
pdc_snipster_cli-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.6 kB

Release files / pdc_snipster_cli-0.1.0.tar.gz

Download URL pdc_snipster_cli-0.1.0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
09a294e6d86d116360e7f3649f1e9fb2e6f6f490d260b6bc79761b507453e4b6
BLAKE2b-256 checksum
How to use checksums
acf91be04c632e640e3c934e6f642c03c3b17076ab03ea259903657b3425b59e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.4

Release files / pdc_snipster_cli-0.1.0-py3-none-any.whl

Download URL pdc_snipster_cli-0.1.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
71de50909c17f228d1c294026460c39ad7a481c7fc47c74ef78af4f0e929371d
BLAKE2b-256 checksum
How to use checksums
4b9cb07fed62ea410bb8596b20bb6a493f0a1a356af114b24d875ddb3991f371
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page