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
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
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
7. Start the Development Server
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:
Database Migrations
Creating a New Migration
When you make changes to the database models, create a new migration:
Applying Migrations
To apply all pending migrations:
To apply a specific migration:
Reverting Migrations
To revert to a previous migration:
Troubleshooting
Database Connection Issues
If you encounter database connection issues:
- Verify that PostgreSQL is running
- Check that the database exists
- Ensure the connection string in the
.envfile is correct - Verify that the user has appropriate permissions
Redis Connection Issues
If you encounter Redis connection issues:
- Verify that Redis is running
- Check the Redis configuration in the
.envfile - Ensure Redis is accessible from your application
Email Configuration Issues
If emails are not being sent:
- Verify the email configuration in the
.envfile - Check that the email server allows SMTP connections
- If using Gmail, ensure "Less secure app access" is enabled or use an app password