A REST API for a mobile app that helps users identify spam numbers and search for contacts in a global database.
- User Authentication
- Contact Management
- Global Search (by name and phone number)
- Spam Reporting & Management
- Django + Django REST Framework
- PostgreSQL
- JWT Authentication
- Python 3.8+
- PostgreSQL (via Neon DB or Docker)
- pip
You can either use Neon.tech for database hosting or set up a local PostgreSQL instance using Docker.
-
Get your database URL from Neon.tech
-
Create and activate virtual environment:
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows- Install dependencies:
pip install -r requirements.txt- Set up environment variables in
.env:
DJANGO_SECRET_KEY='anysecretkey'
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
DATABASE_URL='your-neon-database-url'
- Start PostgreSQL using Docker:
docker-compose up -d- Create and activate virtual environment:
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows- Install dependencies:
pip install -r requirements.txt- Set up environment variables in
.env:
DJANGO_SECRET_KEY='django-insecure-4@w=9rk^&uzh187+1&=sr#dr#)4+c*ct0qnk=^s_n$_qp2Z3ix'
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
DATABASE_URL='postgresql://postgres:postgres@localhost:5432/spamdb'
- Run migrations:
python manage.py migrate- Populate test data (optional):
python populate_db.py- Run the server:
python manage.py runserverPOST /api/auth/register/- Register new userPOST /api/auth/login/- User loginPOST /api/auth/refresh/- Refresh tokenPOST /api/auth/logout/- Logout user
GET /api/users/profile/- Get profilePUT /api/users/profile/- Update profilePOST /api/users/change-password/- Change passwordDELETE /api/users/deactivate/- Deactivate account
GET /api/contacts/- List all contactsPOST /api/contacts/- Create contactGET /api/contacts/{id}/- Get single contactPUT /api/contacts/{id}/- Update contactPATCH /api/contacts/{id}/- Partially update contactDELETE /api/contacts/{id}/- Delete contactPOST /api/contacts/bulk-create/- Bulk create contactsGET /api/contacts/phone/{number}/- Get contact by phone number
GET /api/search/name/?q={query}- Search by nameGET /api/search/phone/?q={number}- Search by phone number
POST /api/spam/report/- Report a number as spamDELETE /api/spam/{number}/retract/- Retract spam reportGET /api/spam/status/{number}/- Get spam status for numberGET /api/spam/statistics/- Get spam statistics
The project includes a data population script for testing:
python populate_db.pyThis will create:
- Sample users with random phone numbers
- Contacts for each user
- Sample spam reports
- All phone numbers should be in E.164 format (e.g.,
+1234567890) - Email is optional for users
- Authentication is required for all endpoints except register/login
- If using Docker, make sure Docker and Docker Compose are installed on your system.
- The Docker setup creates a local PostgreSQL instance with the following credentials:
- Database:
spamdb - User:
postgres - Password:
postgres - Port:
5432
- Database:
You can switch between Neon DB and Docker by updating the DATABASE_URL in your .env file.