A production-ready Customer Relationship Management (CRM) API built with Django REST Framework. Features JWT authentication, comprehensive tagging system, automated testing (92% coverage), and enterprise-grade security.
- β Complete CRM Entities: Leads, Contacts, Deals, Activities, Tags
- π JWT Authentication: Secure token-based auth with SimpleJWT
- π·οΈ Advanced Tagging: Categorize and filter leads, contacts, and deals
- π Organization Management: Multi-tenant with API key support
- π Filtering & Search: Django-filter integration with pagination
- π Auto-generated API Docs: Swagger/OpenAPI via drf-spectacular
- π§ͺ High Test Coverage: 92% coverage with 60+ tests
- π Production Ready: Deployed on Render with PostgreSQL
graph TD
A[User/Organization] --> B[Leads]
A --> C[Contacts]
A --> D[Deals]
A --> E[Activities]
B --> F[Tags]
C --> F
D --> F
B -.Convert.-> C
C --> D
C --> E
D --> E
B --> E
style A fill:#e1f5ff
style B fill:#fff9c4
style C fill:#c8e6c9
style D fill:#ffccbc
style E fill:#f8bbd0
style F fill:#e1bee7
- User/Organization: Base authentication and multi-tenancy
- Leads: Potential customers β Can convert to Contacts
- Contacts: Qualified leads/customers β Linked to Deals and Activities
- Deals: Sales opportunities β Tied to Contacts
- Activities: Calls, emails, meetings β Track engagement with Leads/Contacts/Deals
- Tags: Flexible categorization across all entities
- Python 3.10+
- pip
- Virtual environment (recommended)
# Clone repository
git clone https://github.com/YOUR_USERNAME/YOUR_REPO.git
cd dcrm
# Create and activate virtual environment
python3 -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 with your values
# Run migrations
python3 manage.py migrate
# Create superuser
python3 manage.py createsuperuser
# Populate sample tags (optional)
python3 manage.py populate_tags
# Start development server
python3 manage.py runserverServer runs at: http://127.0.0.1:8000/
Interactive API documentation available at:
- Swagger UI: http://127.0.0.1:8000/api/docs/
- ReDoc: http://127.0.0.1:8000/api/redoc/
Get JWT Token:
curl -X POST http://localhost:8000/api/v1/token/ \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"password": "yourpassword"
}'Response:
{
"refresh": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"access": "eyJ0eXAiOiJKV1QiLCJhbGc..."
}curl -X POST http://localhost:8000/api/leads/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"first_name": "Sarah",
"last_name": "Johnson",
"email": "sarah@enterprise.com",
"phone": "+1234567890",
"status": "new",
"source": "website",
"tags": [1, 4, 5]
}'curl -X GET http://localhost:8000/api/tags/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"curl -X POST http://localhost:8000/api/contacts/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"first_name": "John",
"last_name": "Doe",
"email": "john@example.com",
"address": "123 Main St, Tech City",
"description": "VIP Client - Decision Maker",
"tags": [7, 16]
}'curl -X POST http://localhost:8000/api/deals/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Enterprise SaaS License",
"value": "50000.00",
"stage": "prospecting",
"probability": 50,
"contact": 1,
"tags": [11, 15]
}'# Get all hot enterprise leads
curl -X GET "http://localhost:8000/api/leads/?tags=1,4" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"curl -X PATCH http://localhost:8000/api/deals/1/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"stage": "negotiation",
"probability": 75
}'dcrm/
βββ accounts/ # User & Organization management
βββ leads/ # Lead tracking & conversion
βββ contacts/ # Contact management
βββ deals/ # Sales pipeline
βββ activities/ # Activity logging (calls, emails, meetings)
βββ tags/ # Tagging system
βββ api/ # API configuration & routing
βββ tests/ # Comprehensive test suite
β βββ factories.py # Factory-boy test data generators
β βββ test_models.py # Model tests (34 tests)
β βββ test_api.py # API tests (25 tests)
βββ dcrm/ # Project settings
βββ manage.py
βββ requirements.txt
# Run all tests
pytest
# Run with coverage report
pytest --cov=. --cov-report=html
# Run specific test file
pytest tests/test_models.py
# Run with verbose output
pytest -vCurrent test coverage: 92% (exceeds 70% industry standard)
- 60 comprehensive tests
- Model validation tests
- API endpoint tests
- Authentication & permission tests
- Factory-boy for test data generation
# Install pre-commit hooks
pre-commit install
# Run manually
pre-commit run --all-files# Format code
black .
# Sort imports
isort .
# Lint code
flake8 .
# Security scan
bandit -r .| Category | Tags |
|---|---|
| Leads | hot-lead, cold-lead, qualified, enterprise, smb, demo-scheduled |
| Contacts | decision-maker, technical, influencer, champion |
| Deals | high-priority, needs-approval, renewal, upsell, Q1-target |
| General | vip, urgent |
Use tags for:
- Lead categorization
- Contact segmentation
- Deal prioritization
- Filtering and reporting
This project is configured for Render deployment.
See DEPLOYMENT.md for detailed deployment instructions.
Required environment variables:
SECRET_KEY=your-secret-key-here
DEBUG=False
DATABASE_URL=postgresql://user:pass@host:5432/dbname
ALLOWED_HOSTS=.render.com,yourdomain.com
FRONTEND_URL=https://your-frontend.vercel.appContributions are welcome! Please read CONTRIBUTING.md for guidelines.
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Make changes with tests
- Run tests and linters
- Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
This project is licensed under the MIT License - see LICENSE file for details.
- Django REST Framework - Powerful REST API toolkit
- SimpleJWT - JWT authentication for Django
- drf-spectacular - OpenAPI 3 schema generation
- factory-boy - Test fixtures replacement
For issues and questions:
- Open an issue on GitHub
- Check existing documentation
- Review API docs at
/api/docs/
Built with β€οΈ using Django REST Framework