Skip to content

Handit-AI/hackaton-self-improving-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Self-Improving Engine API

A FastAPI application with PostgreSQL database support, following best practices.

Features

  • FastAPI with async/await support
  • PostgreSQL database connection with SQLAlchemy
  • Alembic for database migrations
  • Environment-based configuration
  • Health check endpoint
  • Docker containerization
  • Google Cloud Run deployment ready
  • Proper logging and error handling
  • Type hints throughout

Prerequisites

  • Python 3.9+
  • PostgreSQL 12+
  • pip

Installation

  1. Clone the repository:
git clone <repository-url>
cd hackaton-self-improving-engine
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables:
cp env.example .env
# Edit .env with your database credentials

Important: Make sure to create a .env file with your database URL before running the application.

Configuration

Edit the .env file with your database configuration:

DATABASE_URL=postgresql://user:password@localhost:5432/dbname
DEBUG=True
LOG_LEVEL=INFO
HOST=0.0.0.0
PORT=8000

Database Setup

  1. Create a PostgreSQL database:
createdb dbname
  1. Run migrations:
alembic upgrade head

Running the Application

Development Mode

python main.py

Or using uvicorn directly:

uvicorn main:app --reload

Production Mode

uvicorn main:app --host 0.0.0.0 --port 8000

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

Docker

Build the Docker image:

docker build -t self-improving-engine-api .

Run the container:

docker run -p 8080:8080 --env-file .env self-improving-engine-api

Google Cloud Deployment

Cloud Build (Recommended)

For automatic deployments using Cloud Build triggers, see CLOUDBUILD.md.

Manual deployment:

gcloud builds submit --config=cloudbuild.yaml

Alternative Deployment

For simple deployment without Cloud Build, see DEPLOYMENT.md.

Quick deployment:

chmod +x deploy.sh
./deploy.sh

API Endpoints

Root

  • GET / - Welcome message

Health Check

  • GET /health - Health check endpoint with database connectivity status

API Documentation

Once the application is running, you can access:

  • Interactive API docs: http://localhost:8000/docs
  • Alternative API docs: http://localhost:8000/redoc

Database Migrations

Create a new migration

alembic revision --autogenerate -m "description"

Apply migrations

alembic upgrade head

Rollback last migration

alembic downgrade -1

Project Structure

.
├── alembic/           # Alembic migration files
│   ├── versions/      # Migration versions
│   ├── env.py         # Alembic environment config
│   └── script.py.mako # Migration template
├── main.py            # FastAPI application entry point
├── config.py          # Application configuration
├── database.py        # Database connection and session management
├── requirements.txt   # Python dependencies
├── alembic.ini        # Alembic configuration
├── env.example        # Environment variables template
├── Dockerfile         # Docker configuration
├── cloudbuild.yaml    # Google Cloud Build configuration
├── app.yaml           # App Engine configuration (optional)
├── deploy.sh          # Deployment script
├── startup.sh         # Container startup script
├── DEPLOYMENT.md      # Deployment documentation
├── CLOUDBUILD.md      # Cloud Build configuration guide
└── README.md          # This file

Development

Adding Models

  1. Create your model in database.py or a separate models.py file:
from sqlalchemy import Column, Integer, String
from database import Base

class YourModel(Base):
    __tablename__ = "your_table"
    
    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)
  1. Create a migration:
alembic revision --autogenerate -m "add your_model table"
  1. Apply the migration:
alembic upgrade head

Adding Endpoints

Add your endpoints in main.py or create separate router files for better organization.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages