Skip to content

sharma-sugurthi/Django_CRM

Repository files navigation

πŸš€ Django CRM API

Tests Coverage Python Django License

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.

🌟 Features

  • βœ… 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

πŸ“ Architecture

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
Loading

Model Relationships

  • 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

πŸš€ Quick Start

Prerequisites

  • Python 3.10+
  • pip
  • Virtual environment (recommended)

Installation

# 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 runserver

Server runs at: http://127.0.0.1:8000/


πŸ“– API Documentation

Interactive API documentation available at:


πŸ’» API Examples

1. Authentication

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..."
}

2. Create a Lead with Tags

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]
  }'

3. List All Tags

curl -X GET http://localhost:8000/api/tags/ \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

4. Create a Contact

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]
  }'

5. Create a Deal

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]
  }'

6. Filter Leads by Tags

# Get all hot enterprise leads
curl -X GET "http://localhost:8000/api/leads/?tags=1,4" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

7. Update Deal Stage

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
  }'

πŸ“‚ Project Structure

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

πŸ§ͺ Testing

Run Tests

# 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 -v

Coverage

Current 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

πŸ”§ Code Quality

Pre-commit Hooks

# Install pre-commit hooks
pre-commit install

# Run manually
pre-commit run --all-files

Linting & Formatting

# Format code
black .

# Sort imports
isort .

# Lint code
flake8 .

# Security scan
bandit -r .

πŸ“Š Available Tags (Pre-populated)

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

πŸš€ Deployment

Render Deployment

This project is configured for Render deployment.

See DEPLOYMENT.md for detailed deployment instructions.

Environment Variables

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.app

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.

Development Workflow

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Make changes with tests
  4. Run tests and linters
  5. Commit changes (git commit -m 'Add amazing feature')
  6. Push to branch (git push origin feature/amazing-feature)
  7. Open Pull Request

πŸ“ License

This project is licensed under the MIT License - see LICENSE file for details.


πŸ™ Acknowledgments

  • Django REST Framework - Powerful REST API toolkit
  • SimpleJWT - JWT authentication for Django
  • drf-spectacular - OpenAPI 3 schema generation
  • factory-boy - Test fixtures replacement

πŸ“§ Support

For issues and questions:

  • Open an issue on GitHub
  • Check existing documentation
  • Review API docs at /api/docs/

Built with ❀️ using Django REST Framework

About

This is a basic version of CRM app built using Django.

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors