A role-aware marketplace backend for construction materials, buyer-seller messaging, payments, moderation, and community activity.
Buildmart is a Django REST Framework marketplace API designed for Kenyan and regional construction supply businesses. It combines email-first authentication, three user roles, product catalog management, seller verification, boost plans, Flutterwave payment initiation, direct messaging models, product questions and answers, notifications, reporting, disputes, and activity tracking.
This repository contains the backend. It is suitable for API-first clients, mobile applications, dashboards, and integrations.
- Email and JWT authentication with refresh-token rotation
- Google OAuth integration through django-allauth and dj-rest-auth
- User, seller, and administrator role boundaries
- Seller onboarding and verification workflows
- Hierarchical categories and marketplace products
- Product reviews, inventory quantities, boosted listings, and product images
- Automatic image resizing, thumbnails, and upload cleanup using Pillow
- Flutterwave checkout initiation and webhook handling for boosted listings
- Buyer-seller chats, message records, product Q&A, and helpful-answer votes
- User notifications, system notifications, and contact submissions
- User and seller activity feeds
- Reports, flags, disputes, and dispute messages
- Django admin support for operational management
- UUID identifiers for marketplace entities and tokens for API access
| Layer | Technology |
|---|---|
| Language | Python 3.8+ |
| Web framework | Django 4.2 |
| API framework | Django REST Framework 3.15 |
| Authentication | Simple JWT, dj-rest-auth, django-allauth |
| Database | SQLite for local development |
| Media processing | Pillow |
| CORS | django-cors-headers |
| Payments | Flutterwave HTTP API |
| Social login | Google OAuth 2.0 |
Clients (Web / Mobile / Admin)
|
v
Django REST API
|
+--------+----------------+
| | |
Accounts Products Payments
| | |
+---- Chats / Reports ----+
| | |
Notifications Activities SQLite / Filesystem
| App | Responsibility |
|---|---|
accounts |
Email user model, profiles, sellers, verification, registration, login, passwords, and Google OAuth |
products |
Categories, listings, inventory, images, reviews, and boost metadata |
payments |
Boost plans, listing boosts, Flutterwave payment initiation, and webhook processing |
chats |
Buyer-seller chats, messages, product questions, answers, and helpful votes |
notifications |
System notifications, per-user read state, and contact messages |
activities |
Recent seller/buyer activity and product-view tracking |
reports |
Content reports, flags, moderation records, disputes, and dispute messages |
The API uses /api/<application>/... prefixes. The development server defaults to http://127.0.0.1:8000.
| Area | Base path | Main capabilities |
|---|---|---|
| Accounts | /api/accounts/ |
Registration, login, logout, JWT refresh, email verification, passwords, profiles, sellers |
| Products | /api/products/ |
Categories, products, product images, reviews, and seller catalog operations |
| Payments | /api/payments/ |
Boost plans, boost purchases, payment status, Flutterwave webhook |
| Chats | /api/chats/ |
Chats, messages, questions, answers, and helpful votes |
| Notifications | /api/notifications/ |
Admin/user notifications and contact submissions |
| Activities | /api/activities/ |
Buyer activity and admin activity feeds |
| Reports | /api/reports/ |
Reports, flags, disputes, and dispute messages |
| Admin | /admin/ |
Django administration interface |
| OAuth routes | /accounts/ |
django-allauth provider and account routes |
| Media | /media/ |
Uploaded files served by Django in debug mode |
Buildmart uses JWT authentication:
- Access token lifetime: 60 minutes
- Refresh token lifetime: 7 days
- Refresh-token rotation is enabled
- Refresh tokens are invalidated after rotation
- Tokens use the
Bearerauthorization header
Authorization: Bearer <access-token>
Content-Type: application/jsonExample login:
curl -X POST http://127.0.0.1:8000/api/accounts/login/ \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"replace-with-a-real-password"}'Example authenticated request:
curl http://127.0.0.1:8000/api/accounts/profile/ \
-H "Authorization: Bearer <access-token>"By default, DRF is configured for JWT and session authentication. Open the route modules below to inspect permissions and action-level authorization for each resource:
accounts/urls.pyproducts/urls.pypayments/urls.pychats/urls.pynotifications/urls.pyactivities/urls.pyreports/urls.py
CustomUser: email-based account identity anduser,seller, oradminroleProfile: personal profile for regular users and administratorsSeller: business profile, address, verification status, and subscription stateCategory: hierarchical product categoryProduct: marketplace listing with price, quantity, seller, category, and boost stateProductImage: optimized listing image, thumbnail, dimensions, and display orderProductReview: one verified-purchase-aware review per user per productBoostPlan/Boost: promoted-listing packages and payment stateChat/Message: buyer-seller conversationsProductQuestion/ProductAnswer: listing Q&A and seller answersNotification/NotificationRead: notifications and per-user read stateRecentActivity: recent marketplace eventsReport/Flag/Dispute: moderation and resolution records
- Python 3.8 or newer
pipandvenv- A Google OAuth client for social-login testing, optional
- A Flutterwave account for payment testing, optional
git clone https://github.com/Kiprotich-Code/buildmart.git
cd buildmart
python -m venv .venvActivate the virtual environment:
Windows PowerShell
.venv\Scripts\Activate.ps1macOS / Linux
source .venv/bin/activateInstall dependencies and initialize the database:
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python manage.py migrate
python manage.py createsuperuser
python manage.py runserverThe API is available at http://127.0.0.1:8000/.
Copy .env.example to .env, then replace placeholders before using protected integrations.
# Email settings
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_HOST_USER=your-email@example.com
EMAIL_HOST_PASSWORD=your-app-password
DEFAULT_FROM_EMAIL=noreply@buildmart.com
# Google OAuth
GOOGLE_OAUTH_CLIENT_ID=your-google-client-id.apps.googleusercontent.com
GOOGLE_OAUTH_CLIENT_SECRET=your-google-client-secret
# Flutterwave
FLUTTERWAVE_PUBLIC_KEY=your-flutterwave-public-key
FLUTTERWAVE_SECRET_KEY=your-flutterwave-secret-keyThe settings module also contains local defaults for development. Review and replace secrets and host restrictions before deployment.
Important: the current settings module is development-oriented. It currently uses a fixed SQLite database and development secret values, permits all CORS origins, enables debug mode, and serves media locally. Configure environment-backed settings and HTTPS before production deployment.
python manage.py createsuperuserpython manage.py makemigrations
python manage.py migratepython manage.py create_chat_test_datapython manage.py create_sample_activitiespython manage.py shellRun the complete Django test suite:
python manage.py testRun a single app:
python manage.py test accounts
python manage.py test products
python manage.py test payments
python manage.py test reports
python manage.py test notificationsRun with fail-fast behavior while developing:
python manage.py test --failfastThe repository includes application-level tests across authentication, payments, reports, notifications, and other marketplace areas. Some standalone test scripts are also present at the project root; prefer the Django test runner for repeatable suite execution.
Boost purchases are created through the payments API. The payment flow uses a generated transaction reference and Flutterwave keys loaded from the environment.
After deployment:
- Configure the Flutterwave keys.
- Register the public webhook URL with Flutterwave.
- Verify that the deployed webhook receives HTTPS requests.
- Record and reconcile the returned transaction reference before activating boosts.
- Use provider signature verification or server-side transaction verification as part of hardening.
The webhook route is:
/api/payments/webhook/flutterwave/
Product image handling is implemented in the products app:
- Up to 5 MB upload size is configured
- Supported types include JPEG, PNG, and WebP
- Main images are resized and optimized
- Thumbnails are generated through Pillow
- Dimensions and file size are stored on
ProductImage - Image files are removed when image records are deleted
- Images and thumbnails are served from
MEDIA_ROOTduring development
For production, configure persistent object storage or a shared media volume; a local filesystem is not appropriate for stateless application instances.
The chats app defines WebSocket consumers and URL patterns for chat, dispute, and user events. Before enabling them in production, wire Django Channels into ASGI_APPLICATION, add channels and a channel-layer backend such as Redis, register the routing layer, configure authentication, and run a documented ASGI server.
buildmart/
├── accounts/ Authentication, users, profiles, sellers
├── activities/ Recent activity and view tracking
├── chats/ Chat, messages, product Q&A
├── notifications/ Notifications and contact submissions
├── payments/ Boost plans and Flutterwave payments
├── products/ Catalog, listings, images, reviews
├── reports/ Reports, flags, disputes
├── buildmart/ Project settings, root routes, WSGI/ASGI
├── media/ Local uploaded media
├── manage.py Django management entry point
├── requirements.txt Python dependencies
└── .env.example Example environment variables
Before exposing this API publicly:
- Replace the Django secret key and load it from environment variables
- Set
DEBUG=False - Restrict
ALLOWED_HOSTS - Replace permissive CORS settings with explicit origins
- Configure
DATABASE_URLor the intended production database and migrations - Configure HTTPS, secure cookies, HSTS, and proxy headers
- Use persistent media storage and a CDN or signed storage URLs when appropriate
- Configure SMTP credentials from secrets management
- Set a strict payment webhook verification strategy
- Add request throttling and centralized logging
- Configure backups, monitoring, health checks, and error reporting
- Review permissions, object-level authorization, and admin access
- Run migrations and tests in CI before deployment
There is no OpenAPI/Swagger dependency or generated schema currently declared in requirements.txt. For publication-ready documentation, add drf-spectacular, generate an OpenAPI schema, and serve versioned interactive documentation.
The URL module is the source of truth for current routes. For payment integration details, see payments/API_TESTING_GUIDE.md only if present in the deployed branch; general API behavior should be documented from the route and serializer implementations.
- Do not commit
.env, database files, private keys, payment secrets, or generated media - Do not expose the Django admin without network, authentication, and operational controls
- Use strong passwords and rotate OAuth/payment credentials regularly
- Validate provider callbacks against verified transaction/server-side data
- Review role checks and object-level permissions when adding endpoints
- Report suspected vulnerabilities privately to the repository maintainer
Contributions should preserve the existing Django app boundaries and API conventions.
- Create a focused branch from
main. - Add or update migrations for model changes.
- Add tests covering authorization, validation, and regressions.
- Run the smallest relevant Django test module first.
- Run the full suite before opening a pull request.
- Keep secrets, generated databases, media, and test fixtures out of commits.
git checkout -b feature/short-description
python manage.py test
git add .
git commit -m "feat: add short description"
git push origin feature/short-descriptionBuildmart is licensed under the GNU Affero General Public License v3.0. See LICENSE for the complete terms.
Copyright (C) 2026 Kiprotich-Code and contributors.