Nexus is a robust fintech backend demonstration built with FastAPI. It features secure Google authentication (OAuth2), idempotent payment processing with Paystack, and real-time transaction updates via cryptographic webhooks.
- Authentication: Google OAuth2 (Authorization Code Flow) with HTTP-only Cookies.
- Payments: Paystack integration with idempotent transaction initiation.
- Webhooks: Secure signature verification (HMAC SHA512) for payment status updates.
- Database: PostgreSQL with SQLAlchemy ORM and Alembic migrations.
- Testing: Full integration testing suite using
pytestand SQLite. - Frontend: Minimalist dashboard for user interaction.
- Python 3.10+
- PostgreSQL (Local installation OR Docker)
- Paystack Account (Test Keys)
- Google Cloud Console Project (OAuth Credentials)
Create a .env file in the root directory:
# Database
DATABASE_URL=postgresql://nexus_user:nexus_password@localhost:5432/nexus_db
# Google Auth
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REDIRECT_URI=http://localhost:8000/auth/google/callback
# Paystack
PAYSTACK_SECRET_KEY=sk_test_your_paystack_secret
# Security
SECRET_KEY=your_random_secret_string
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
ENVIRONMENT=developmentIf you prefer to run directly on your machine, follow these steps.
You must have PostgreSQL running locally.
# (Linux/WSL) Install Postgres
sudo apt update && sudo apt install postgresql postgresql-contrib
# Switch to postgres user
sudo -i -u postgres
# Create User and DB
psql -c "CREATE USER nexus_user WITH PASSWORD 'nexus_password';"
psql -c "CREATE DATABASE nexus_db OWNER nexus_user;"
exit# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install libraries
pip install -r requirements.txtInitialize the database tables.
alembic upgrade headuvicorn app.main:app --reloadAccess the app at: http://localhost:8000/auth/google
This method handles the database and application environment automatically.
Ensure Docker Desktop is running.
Build and run:
docker compose up --buildAccess the app at: http://localhost:8000/auth/google
Tests use an in-memory SQLite database, so they work without a running Postgres instance.
Local (with venv active):
pytest -vVia Docker:
docker compose exec web pytest -v| Method | Endpoint | Description |
|---|---|---|
| GET | /auth/google |
Initiates Google OAuth2 login flow. |
| GET | /users/me |
Returns current user details (Requires Cookie). |
| POST | /payments/paystack/initiate |
Starts a transaction. Body: {"amount": 5000} (Kobo). |
| GET | /payments/{ref}/status |
Checks transaction status. |
| POST | /payments/paystack/webhook |
Receives Paystack updates (Verifies Signature). |