Skip to content

Development Setup

This guide will help you set up the UBU Digital Finance Solution backend for development.

Prerequisites

Before you begin, ensure you have the following installed:

  • Python 3.9 or higher
  • PostgreSQL 12 or higher
  • Redis
  • Git

Installation Steps

1. Clone the Repository

git clone <repository-url>
cd UBU_Finance_backend

2. Create a Virtual Environment

# Windows
python -m venv venv
venv\Scripts\activate

# Linux/macOS
python -m venv venv
source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Configure Environment Variables

Create a .env file in the root directory with the following variables:

# Database Configuration
DATABASE_URL=postgresql+asyncpg://username:password@localhost/ubu_finance

# JWT Configuration
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7

# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
REDIS_PASSWORD=

# Email Configuration
MAIL_USERNAME=your_email@example.com
MAIL_PASSWORD=your_email_password
MAIL_FROM=your_email@example.com
MAIL_PORT=587
MAIL_SERVER=smtp.example.com
MAIL_FROM_NAME=UBU Digital Finance
MAIL_TLS=True
MAIL_SSL=False

Replace the placeholder values with your actual configuration.

5. Create the Database

Create a PostgreSQL database for the application:

# Connect to PostgreSQL
psql -U postgres

# Create the database
CREATE DATABASE ubu_finance;

# Exit PostgreSQL
\q

6. Run Database Migrations

alembic upgrade head

7. Start the Development Server

uvicorn main:app --reload

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

Project Structure

UBU_Finance_backend/
├── alembic/                  # Database migration scripts
├── app/                      # Application code
│   ├── api/                  # API endpoints
│   │   └── routers/          # API route definitions
│   │       └── users/        # User-related endpoints
│   ├── auth/                 # Authentication logic
│   ├── models/               # Database models
│   │   └── user_management/  # User management models
│   ├── schemas/              # Pydantic schemas
│   │   └── user_managment/   # User management schemas
│   └── utils/                # Utility functions
│       └── mail/             # Email utilities
├── docs/                     # Documentation
├── main.py                   # Application entry point
└── requirements.txt          # Project dependencies

API Documentation

Once the server is running, you can access the API documentation at:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Running Tests

To run the tests:

pytest

Database Migrations

Creating a New Migration

When you make changes to the database models, create a new migration:

alembic revision --autogenerate -m "Description of changes"

Applying Migrations

To apply all pending migrations:

alembic upgrade head

To apply a specific migration:

alembic upgrade <revision>

Reverting Migrations

To revert to a previous migration:

alembic downgrade <revision>

Troubleshooting

Database Connection Issues

If you encounter database connection issues:

  1. Verify that PostgreSQL is running
  2. Check that the database exists
  3. Ensure the connection string in the .env file is correct
  4. Verify that the user has appropriate permissions

Redis Connection Issues

If you encounter Redis connection issues:

  1. Verify that Redis is running
  2. Check the Redis configuration in the .env file
  3. Ensure Redis is accessible from your application

Email Configuration Issues

If emails are not being sent:

  1. Verify the email configuration in the .env file
  2. Check that the email server allows SMTP connections
  3. If using Gmail, ensure "Less secure app access" is enabled or use an app password