Skip to content

Setting Up Development Environment

Max Azatian edited this page Oct 5, 2024 · 2 revisions

This guide will walk you through setting up the development environment for the Flet-Chat project. We'll be using Docker to containerize our services, making it easy to manage and deploy.

Prerequisites

Before you begin, ensure you have the following installed on your system:

  • Docker
  • Docker Compose
  • Python 3.11 or higher
  • Git (for version control)

Step 1: Clone the Repository

First, clone the project repository to your local machine:

git clone https://github.com/HardMax71/Flet-Chat.git
cd Flet-Chat

Step 2: Environment Configuration

Create a .env file in the root directory of the project and add the following environment variables:

# Example
## Database Configuration
DB_NAME=chatdb
DB_USER=chatuser
DB_PORT=5432
POSTGRES_VERSION=14
POSTGRES_PASSWORD=password

## Application Configuration
APP_PORT=8000
SECRET_KEY=secretkey
REFRESH_SECRET_KEY=refreshsecretkey
PYTHON_VERSION=3.11

## Redis Configuration
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_VERSION=6.2-alpine

Make sure to replace secretkey and refreshsecretkey with secure, randomly generated strings.

Step 3: Docker Setup

Our docker-compose.yml file defines three main services: the database (PostgreSQL), the chat service (our FastAPI backend), and Redis for real-time messaging.

To start all services, run:

docker-compose up -d

This command will:

  • Start a PostgreSQL database
  • Launch a Redis instance
  • Build and start the chat service

You can check if all services are running correctly with:

docker-compose ps

Step 4: Database Initialization

The database will be automatically initialized with the schema defined in chat_service/init.sql. This happens when the container starts for the first time.

Step 5: Running the Frontend

To run the Flet frontend application:

  1. Create a virtual environment:
python -m venv venv
  1. Activate the virtual environment:
    • On Windows:
venv\Scripts\activate
  • On macOS and Linux:
source venv/bin/activate
  1. Install the required packages:
pip install -r requirements.txt
  1. Run the Flet application:
python main.py --web

Step 6: Accessing the Application

  • The Flet frontend will be running as a desktop application.
  • The FastAPI backend will be accessible at http://localhost:8000.
  • You can access the API documentation at:
    • Swagger UI: http://localhost:8000/docs
    • ReDoc: http://localhost:8000/redoc

Troubleshooting

  • If you encounter any issues with database connections, ensure that the PostgreSQL container is running and healthy:

docker-compose logs db

  • For issues with the chat service, check its logs:
docker-compose logs flet-chat-chat_service
  • If Redis is not connecting, verify its status:
docker-compose logs redis

Clone this wiki locally