AgroShop is a comprehensive agricultural marketplace platform that enables buying and selling of farm items, agricultural products, planting materials, food stuffs, land/factory rentals, and equipment. This backend API provides all necessary functionality for the AgroShop mobile/web application.
- Email/username registration with full name
- JWT-based authentication
- User profiles with verification
- Account deletion with safety checks
- Favorites system
- Dual balance system (normal + pending)
- Escrow system for secure trades
- Recharge functionality with payment gateway integration
- Withdrawal system to bank accounts
- Transaction history
- Item posting with rich categories
- Variant and option selection (size, color, grade, etc.)
- Secure trade initiation with escrow
- One-to-one chat for buyer-seller communication
- Trade completion and fund release
- Dispute resolution system
- Document upload for user verification
- Different limits for verified/unverified users
- Admin verification approval panel
- Enhanced trust and security
- 10+ comprehensive agricultural categories
- Sale/rental/lease options
- Location-based listings
- Image upload support
- Advanced search and filtering
- System statistics and analytics
- User management
- Dispute resolution
- Verification approval
- Content moderation
Client (Frontend) โ REST API โ Django Backend
โโโ Database (PostgreSQL)
โโโ File Storage (S3)
โโโ Cache (Redis)
โโโ Async Tasks (Celery)
agroshop/
โโโ models.py # Database models
โโโ views.py # API endpoints
โโโ serializers.py # Request/response serializers
โโโ permissions.py # Custom permissions
โโโ utils.py # Utility functions
โโโ tasks.py # Celery async tasks
โโโ admin.py # Django admin configuration
โโโ urls.py # URL routing
โโโ signals.py # Django signals
โโโ apps.py # App configuration
- Python 3.8+
- PostgreSQL 12+
- Redis 6+
- Virtualenv
- Clone the repository
git clone repo
cd repo- Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Set up environment variables
cp .env.example .env
# Edit .env with your configuration- Run database migrations
python manage.py migrate- Create superuser
python manage.py createsuperuser- Run development server
python manage.py runserver# Database
DB_ENGINE=django.db.backends.postgresql
DB_NAME=agroshop
DB_USER=postgres
DB_PASSWORD=yourpassword
DB_HOST=localhost
DB_PORT=5432
# Security
SECRET_KEY=your-secret-key-here
DEBUG=True
# CORS
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
# Email
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-app-password
# AWS S3 (optional)
USE_S3=False
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_STORAGE_BUCKET_NAME=your-bucket
# Celery
CELERY_BROKER_URL=redis://localhost:6379/0
CELERY_RESULT_BACKEND=redis://localhost:6379/0| Endpoint | Method | Description |
|---|---|---|
/api/auth/register/ |
POST | Register new user |
/api/auth/login/ |
POST | User login |
/api/auth/token/refresh/ |
POST | Refresh JWT token |
| Endpoint | Method | Description |
|---|---|---|
/api/user/profile/ |
GET, PATCH | Get/update user profile |
/api/user/balance/ |
GET | Get user balance |
/api/user/recharge/ |
POST | Recharge balance |
/api/user/withdraw/ |
POST | Withdraw funds |
/api/user/verify/ |
POST | Submit verification documents |
/api/user/dashboard/ |
GET | User dashboard |
/api/user/account/delete/ |
DELETE | Delete user account |
| Endpoint | Method | Description |
|---|---|---|
/api/categories/ |
GET | List all categories |
/api/items/ |
GET, POST | List/create items |
/api/items/{id}/ |
GET, PUT, PATCH, DELETE | Item CRUD |
/api/items/{id}/toggle_favorite/ |
POST | Add/remove from favorites |
| Endpoint | Method | Description |
|---|---|---|
/api/trades/ |
GET, POST | List/create trades |
/api/trades/{id}/ |
GET | Get trade details |
/api/trades/{id}/mark_complete/ |
POST | Mark trade as complete |
/api/trades/{id}/open_dispute/ |
POST | Open dispute |
/api/trades/{id}/messages/ |
GET | Get trade messages |
/api/trades/{id}/send_message/ |
POST | Send message |
/api/trades/my_trades/ |
GET | Get user's trades |
| Endpoint | Method | Description |
|---|---|---|
/api/admin/dashboard/ |
GET | Admin dashboard stats |
/api/admin/users/manage/ |
POST | Manage users |
- Maximum 5 active ads
- Maximum 3 ads per day
- Maximum 3 active trades
- Maximum โฆ500,000 per trade
- Maximum โฆ1,000,000 daily trade volume
- Unlimited ads
- Unlimited trades
- No trade amount limits
- 60-day ad expiry (vs 30 days for unverified)
- Recharge Balance (
views.py:132-158)
# Mocked payment gateway - Replace with actual implementation
# Currently simulates successful payment
transaction.status = 'completed'
transaction.save()
# Real implementation would:
# 1. Initialize payment with gateway
# 2. Redirect user to payment page
# 3. Handle webhook callback
# 4. Update transaction status- Withdrawal Processing (
views.py:160-216)
# Process withdrawal asynchronously
process_withdrawal.delay(transaction.id)
# Real implementation would:
# 1. Call bank transfer API
# 2. Handle callbacks
# 3. Update transaction status/api/webhooks/payment-success//api/webhooks/payment-failure//api/webhooks/withdrawal-callback/
- Bank Transfer
- Card Payments
- Mobile Money (to be integrated)
- USSD (to be integrated)
- User - Extended Django User with full name
- UserProfile - Extended user information
- UserBalance - Balance tracking
- Category/Subcategory - Product categorization
- Item - Products for sale/rent
- Trade - Buy-sell transactions
- PaymentTransaction - Payment history
- Dispute - Trade dispute management
- UserVerification - KYC documents
python manage.py test# Install pre-commit
pre-commit install
# Run checks
flake8 .
black .
isort .# Create migration
python manage.py makemigrations
# Apply migration
python manage.py migrate
# Check migration status
python manage.py showmigrations# Start Celery worker
celery -A agroshop worker -l info
# Start Celery beat (for scheduled tasks)
celery -A agroshop beat -l info- Set
DEBUG=False - Update
ALLOWED_HOSTS - Configure production database
- Set up SSL certificates
- Configure S3 for media storage
- Set up Celery with Redis
- Configure email service
- Set up monitoring (Sentry, etc.)
- Configure backup strategy
- Enable security headers
# Dockerfile
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
RUN python manage.py collectstatic --noinput
CMD ["gunicorn", "agroshop.wsgi:application", "--bind", "0.0.0.0:8000"]- AWS: Elastic Beanstalk, ECS, EC2
- Heroku: Simple deployment
- DigitalOcean: Droplets or App Platform
- Railway: Easy deployment
- Database indexing on frequently queried fields
- Query optimization with
select_relatedandprefetch_related - API pagination (20 items per page)
- Redis caching for frequently accessed data
- Celery for async tasks
- CDN for static and media files
- Database connection pooling
- API response compression
- Load balancing for high traffic
- JWT authentication with refresh tokens
- Password validation and hashing
- CORS configuration
- CSRF protection
- SQL injection prevention (Django ORM)
- XSS protection
- Rate limiting (100/day anonymous, 1000/day users)
- File upload validation
- Web Application Firewall (WAF)
- DDoS protection
- Regular security audits
- Penetration testing
- Security headers (HSTS, CSP)
// Example Axios configuration
import axios from 'axios';
const api = axios.create({
baseURL: process.env.REACT_APP_API_URL,
});
// Add JWT token to requests
api.interceptors.request.use(config => {
const token = localStorage.getItem('access_token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
// Handle token refresh
api.interceptors.response.use(
response => response,
async error => {
if (error.response.status === 401) {
// Refresh token logic
}
return Promise.reject(error);
}
);- Authentication flow (register/login/logout)
- Balance management (recharge/withdraw)
- Item listing (create/edit/delete)
- Search and filtering
- Trade management (initiate/complete/dispute)
- Real-time chat (WebSocket integration recommended)
- User profile (edit/verify)
- Notifications system
-
Database connection errors
- Check PostgreSQL service is running
- Verify database credentials in
.env - Ensure database exists
-
Migration errors
python manage.py migrate --fake-initial python manage.py migrate --run-syncdb
-
Static files not loading
python manage.py collectstatic
-
Celery not processing tasks
- Check Redis is running
- Verify Celery worker is started
- Check task queue configuration
- Application logs:
agroshop.log - Server logs: Check web server logs
- Database logs: PostgreSQL logs
- Celery logs: Worker output
[Specify your license here]
- Fork the repository
- Create a feature branch
- Commit changes
- Push to the branch
- Create a Pull Request
For support, please contact:
- Email: support@agroshop.com
- Issues: GitHub Issues page
- Documentation: [Add documentation link]
- Real-time notifications
- Advanced analytics dashboard
- Bulk upload for items
- Auction system
- Subscription plans
- Multi-language support
- Mobile money integration
- USSD payment integration
- Delivery tracking integration
- Advanced reporting system
AgroShop - Powering Agricultural Commerce ๐
This project was bootstrapped using tap_drf - A production-ready Django REST Framework boilerplate with JWT auth, Swagger docs, Docker support, and more.
Conscience Ekhomwandolor (AVT Conscience)
- Passionate fullstack developer & cyber security researcher (red team enthusiast)
- Creator of tap_drf, tap_react, tap_fullstack
- Personal Blog: https://medium.com/@avtconscience
- GitHub: https://github.com/razielapps
- Email: avtxconscience@gmail.com
For questions, support, or collaboration, feel free to reach out.