This is a simple Hacker News clone built with FastAPI and PostgreSQL. The purpose of this project is to educate users on how to deploy database-dependent applications on Leapcell.
- FastAPI backend
- PostgreSQL database integration
- Jinja2 templating for rendering views
.
├── LICENSE # License file
├── main.py # Main application entry point
├── models.py # Database models using SQLAlchemy
├── requirements.txt # Project dependencies
└── templates/ # HTML templates for rendering views
├── index.html # Homepage displaying the list of posts
├── missing-pg.html # PG missing
└── post_detail.html # Template for displaying post details
This guide will walk you through setting up and deploying the project on Leapcell.
Ensure you have the following:
- A Leapcell account
- PostgreSQL database instance
- Python installed (recommended: Python 3.8+)
This project requires a PostgreSQL connection string, which should be set using the following environment variable:
DATABASE_DSN=<your_postgresql_connection_string>- Clone the repository:
git clone https://github.com/leapcell/fastapi-hackernews-clone cd fastapi-hackernews-clone - Create a virtual environment and install dependencies:
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate pip install -r requirements.txt
To start the project locally, ensure your PostgreSQL instance is running and execute:
uvicorn main:app --reloadThe application will be accessible at http://localhost:8000.
- Push your code to a GitHub repository.
- Log in to Leapcell and connect your repository.
- Configure the
DATABASE_DSNenvironment variable in the Leapcell deployment settings. - Deploy your application.
Once deployed, your application will be accessible via the Leapcell-generated domain.
Feel free to submit issues or pull requests to improve this project.
For support, reach out via the Leapcell Discord community or email support@leapcell.io.