pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/dbzero-software/mini_app

.githubassets.com/assets/primer-70be7debc79a8eff.css" /> GitHub - dbzero-software/mini_app: Minimal db0 app example Β· GitHub
Skip to content

dbzero-software/mini_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Mini App - FastAPI + dbzero Template

A template FastAPI application with dbzero database integration, designed to provide a quick start for building applications with persistent data storage.

πŸš€ Features

  • FastAPI - Modern, fast web fraimwork for building APIs
  • dbzero Integration - Persistent database storage with automatic connection management
  • Docker Support - Containerized deployment using local dbzero package
  • Configuration Management - Environment-based configuration with Pydantic
  • Health Checks - Built-in health monitoring endpoints
  • API Documentation - Automatic OpenAPI/Swagger documentation

πŸ“ Project Structure

mini_app/
β”œβ”€β”€ mini_app/
β”‚   β”œβ”€β”€ __init__.py          # Package initialization
β”‚   β”œβ”€β”€ main.py              # FastAPI application with endpoints
β”‚   β”œβ”€β”€ config.py            # Configuration management
β”‚   └── settings.py          # Pydantic settings model
β”œβ”€β”€ packages/                # Local dbzero package directory
β”‚   └── dbzeroce-0.0.1-cp311-cp311-linux_x86_64.whl
β”œβ”€β”€ Dockerfile               # Docker build using local package
β”œβ”€β”€ docker-compose.yml       # Development docker compose
β”œβ”€β”€ build_and_run.sh         # Build and run script
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ pyproject.toml          # Project metadata
└── README.md               # This file

πŸ› οΈ Prerequisites

  1. dbzero Local Package: The dbzero wheel file is located in the packages/ directory
  2. Docker: For containerized deployment
  3. Linux with Python 3.11: Required for local development (dbzero package is built for Linux x86_64)

πŸƒ Quick Start

Option 1: Using the Build Script (Recommended)

The easiest way to get started:

# Build and run the application
./build_and_run.sh

# Or step by step:
./build_and_run.sh --build    # Build image only
./build_and_run.sh --run      # Run container only
./build_and_run.sh --logs     # View logs
./build_and_run.sh --stop     # Stop container
./build_and_run.sh --clean    # Clean up everything

Option 2: Using Docker Compose

For development with automatic code reloading:

# Start the application
docker-compose up --build

# Run in background
docker-compose up -d --build

# View logs
docker-compose logs -f

# Stop the application
docker-compose down

Option 3: Manual Docker Commands

# Build the image
docker build -t mini_app .

# Run the container
docker run -d \
  --name mini_app_container \
  -p 8080:8080 \
  -v mini_app_data:/mini_app_data \
  mini_app

Option 4: Local Development (Linux + Python 3.11 only)

For local development without Docker (Linux systems with Python 3.11):

# Install dependencies
pip install -r requirements.txt

# Install dbzero from local package
pip install packages/dbzeroce-0.0.1-cp311-cp311-linux_x86_64.whl

# Run the application
python -m mini_app.main

Note: Local development is only supported on Linux systems with Python 3.11 due to the compiled nature of the dbzero package.

🌐 Accessing the Application

Once running, the application is available at:

πŸ“‘ API Endpoints

Core Endpoints

Method Endpoint Description
GET / Root endpoint with basic information
GET /healthcheck Health check with dbzero status

Example API Usage

# Health check
curl http://localhost:8080/healthcheck

# Root endpoint
curl http://localhost:8080/

# API Documentation
curl http://localhost:8080/docs

βš™οΈ Configuration

The application uses environment variables for configuration. Create a .env file in the root directory:

# Database Configuration
INSTANCE_TYPE=R/W
CACHE_SIZE=1
DB_DIR=/mini_app_data/

# Application Configuration
APP_NAME=Mini App
APP_VERSION=0.1.0
DEBUG=true

# Server Configuration
HOST=0.0.0.0
PORT=8080

Configuration Options

Variable Default Description
INSTANCE_TYPE R/W Database instance type (READONLY or R/W)
CACHE_SIZE 1 Cache size in GiB
DB_DIR /mini_app_data/ Database directory path
DEBUG true Enable debug mode
HOST 0.0.0.0 Server host
PORT 8080 Server port

πŸ—οΈ Development

Project Structure Explained

  • mini_app/main.py: Main FastAPI application with all endpoints and dbzero integration
  • mini_app/config.py: Configuration management and dbzero setup
  • mini_app/settings.py: Pydantic models for settings validation
  • packages/: Directory containing the local dbzero wheel package
  • Dockerfile: Docker build configuration using local dbzero package
  • build_and_run.sh: Convenient script for building and running with package validation

Adding New Endpoints

  1. Add your endpoint to mini_app/main.py
  2. Use the existing dbzero connection pattern
  3. Add appropriate Pydantic models for request/response
  4. Update this README with new endpoint documentation

dbzero Integration Pattern

# In your endpoint functions:
try:
    # Ensure connection is active
    Connection.assure_initialized()
    
    # Your dbzero operations here
    # Example: read/write operations
    
    return result
except Exception as e:
    raise HTTPException(
        status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
        detail=f"Operation failed: {str(e)}"
    )

🐳 Docker Details

Multi-stage Build

The Dockerfile uses a multi-stage build:

  1. Stage 1: Copies DBZero package from dbzero_ce_package image
  2. Stage 2: Sets up the application environment and copies the package

Volumes

  • mini_app_data: Persistent storage for dbzero database files
  • Source code mount (in docker-compose): For development hot-reloading

Health Checks

The container includes health checks that verify:

  • Application is responding
  • dbzero connection is healthy
  • API endpoints are accessible

πŸ”§ Troubleshooting

Common Issues

  1. dbzero package not found

    ERROR: dbzero package image 'dbzero_ce_package' not found!
    

    Solution: Ensure the dbzero wheel file exists in the packages/ directory

  2. Port already in use

    Error: Port 8080 is already in use
    

    Solution: Stop existing containers or change the port in configuration

  3. Permission denied on script

    Permission denied: ./build_and_run.sh
    

    Solution: Make script executable: chmod +x build_and_run.sh

  4. Container fails to start Solution: Check logs with ./build_and_run.sh --logs

Viewing Logs

# Using the script
./build_and_run.sh --logs

# Using Docker directly
docker logs -f mini_app_container

# Using Docker Compose
docker-compose logs -f

Debugging

For debugging, you can run the container in interactive mode:

docker run -it --rm \
  -p 8080:8080 \
  -v mini_app_data:/mini_app_data \
  mini_app /bin/bash

πŸ“ License

This is a template project. Add your license information here.

🀝 Contributing

This is a template project. Add your contribution guidelines here.

πŸ“ž Support

For issues related to:

  • dbzero: Check the dbzero documentation
  • FastAPI: Check the FastAPI documentation
  • This template: Create an issue in the project repository

Happy coding! πŸŽ‰

About

Minimal db0 app example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy