
- Set up FastAPI project structure with modular architecture - Create comprehensive database models for users, properties, messages, notifications, and payments - Implement JWT-based authentication with role-based access control (Seeker, Agent, Landlord, Admin) - Build property listings CRUD with advanced search and filtering capabilities - Add dedicated affordable housing endpoints for Nigerian market focus - Create real-time messaging system between users - Implement admin dashboard with property approval workflow and analytics - Add notification system for user alerts - Integrate Paystack payment gateway for transactions - Set up SQLite database with Alembic migrations - Include comprehensive health check and API documentation - Add proper error handling and validation throughout - Follow FastAPI best practices with Pydantic schemas and dependency injection
Urban Real Estate API
A comprehensive backend API for the Urban Real Estate App - a Nigerian housing marketplace that connects property seekers with agents, landlords, and affordable housing options.
Features
- User Authentication & Authorization: JWT-based authentication with role-based access control
- Property Listings Management: Full CRUD operations for property listings
- Affordable Housing: Dedicated endpoints for affordable housing listings
- Messaging System: Real-time messaging between users
- Admin Dashboard: Administrative controls for managing users and properties
- Notifications: User notification system
- Payment Integration: Paystack payment gateway integration
- Search & Filtering: Advanced property search with multiple filters
Technology Stack
- Framework: FastAPI (Python)
- Database: SQLite with SQLAlchemy ORM
- Authentication: JWT tokens with bcrypt password hashing
- API Documentation: Automatic OpenAPI/Swagger documentation
- Migrations: Alembic for database migrations
Project Structure
urbanrealestateapi/
├── app/
│ ├── auth/ # Authentication utilities
│ ├── core/ # Core security functions
│ ├── db/ # Database configuration
│ ├── models/ # SQLAlchemy models
│ ├── routers/ # API route handlers
│ └── schemas/ # Pydantic schemas
├── alembic/ # Database migrations
├── main.py # FastAPI application entry point
├── requirements.txt # Python dependencies
└── README.md # This file
Installation & Setup
-
Install Dependencies:
pip install -r requirements.txt
-
Set Environment Variables:
export SECRET_KEY="your-secret-key-here" export PAYSTACK_SECRET_KEY="your-paystack-secret-key" export PAYSTACK_PUBLIC_KEY="your-paystack-public-key" export ENVIRONMENT="development"
-
Run Database Migrations:
alembic upgrade head
-
Start the Application:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
Environment Variables
The following environment variables should be set for production:
SECRET_KEY
: JWT secret key for token generationPAYSTACK_SECRET_KEY
: Paystack secret key for payment processingPAYSTACK_PUBLIC_KEY
: Paystack public key for payment processingENVIRONMENT
: Application environment (development/production)
API Endpoints
Authentication
POST /api/auth/register
- Register a new userPOST /api/auth/login
- Login user
Properties
GET /api/properties/
- List properties with filteringPOST /api/properties/
- Create new property listingGET /api/properties/{id}
- Get property detailsPUT /api/properties/{id}
- Update property listingDELETE /api/properties/{id}
- Delete property listing
Affordable Housing
GET /api/affordable/
- List affordable housing properties
Messages
POST /api/messages/
- Send a messageGET /api/messages/
- Get user messagesGET /api/messages/conversations/{user_id}
- Get conversation with specific userPUT /api/messages/{id}/read
- Mark message as read
Notifications
GET /api/notifications/
- Get user notificationsPUT /api/notifications/{id}/read
- Mark notification as readPUT /api/notifications/mark-all-read
- Mark all notifications as read
Admin (Admin role required)
GET /api/admin/properties/pending
- Get pending property approvalsPUT /api/admin/properties/{id}/approve
- Approve property listingPUT /api/admin/properties/{id}/reject
- Reject property listingGET /api/admin/users
- List usersPUT /api/admin/users/{id}/deactivate
- Deactivate userGET /api/admin/analytics
- Get system analytics
Payments
POST /api/payments/initiate
- Initiate paymentPOST /api/payments/verify/{ref}
- Verify paymentGET /api/payments/
- Get user paymentsGET /api/payments/{id}
- Get payment details
System
GET /
- API informationGET /health
- Health check endpointGET /docs
- Swagger documentationGET /redoc
- ReDoc documentation
User Roles
- Seeker: Can search and view properties, send messages
- Agent: Can list properties, manage listings, communicate with seekers
- Landlord: Can list properties, manage listings, communicate with seekers
- Admin: Full access to all endpoints, can approve/reject listings, manage users
Database Schema
Users
- User authentication and profile information
- Role-based access control
- Profile with bio, image, and verification status
Properties
- Property listings with comprehensive details
- Location, pricing, and amenity information
- Approval workflow for listings
- Support for affordable housing categorization
Messages
- Real-time messaging between users
- Message read status tracking
Notifications
- User notification system
- Read/unread status tracking
Payments
- Payment transaction logging
- Paystack integration support
Development
Running Tests
# Add your test commands here when tests are implemented
pytest
Code Formatting
ruff check .
ruff format .
Database Operations
# Create new migration
alembic revision --autogenerate -m "Description"
# Apply migrations
alembic upgrade head
# Rollback migration
alembic downgrade -1
Production Deployment
- Set all required environment variables
- Use a production WSGI server like Gunicorn
- Configure proper database (PostgreSQL recommended for production)
- Set up proper logging and monitoring
- Configure HTTPS/SSL
- Set up database backups
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
License
This project is licensed under the MIT License.
Support
For support and questions, please create an issue in the repository.
Description
Languages
Python
98.9%
Mako
1.1%