A Django-based microservice for a simple social media platform called Chirp.
- 📝 Post and view statuses (posts) with 280 character limit
- 👥 Create and manage groups with admin/member roles
- 📧 Send group invitations and manage memberships
- 💬 Post messages in groups with permission controls
- 📩 Send direct messages with privacy protection
- 🔐 JWT-based authentication and authorization
- 🏥 Health check endpoint for server monitoring.
chirp/- Main Django project settings, URLs, and JWT utilitiesposts/- Status (post) related logic and API endpointsgroups/- Group management logic with permission systemdmessages/- Direct messaging logic with privacy controls*/tests/- Comprehensive tests
- Backend: Django 5.2.3, Django REST Framework
- Database: PostgreSQL (recommended) / SQLite (development)
- Authentication: JWT tokens with HS256 algorithm
- Testing: Django TestCase, APIClient
- Python 3.8+
- PostgreSQL 12+ (for production)
- Git
git clone git@github.com:opencrafts-io/chirp_backend.git
cd chirp# Create virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate # On Linux/Mac
# or
venv\Scripts\activate # On Windowspip install -r requirements.txt1. Install PostgreSQL
2. Start PostgreSQL service
3. Create database and userIn PostgreSQL shell:
CREATE DATABASE chirp_db;
CREATE USER chirp_user WITH PASSWORD 'your_secure_password';
GRANT ALL PRIVILEGES ON DATABASE chirp_db TO chirp_user;
ALTER USER chirp_user CREATEDB;
\qSQLite is configured by default and requires no additional setup.
Create a .env file in the project root
python manage.py makemigrations
python manage.py migratepython manage.py runserver 0.0.0.0:8000Test the health check endpoint:
curl http://localhost:8000/ping/
# Expected response: {"message": "Bang."}All endpoints except /ping/ require JWT authentication:
Authorization: Bearer <jwt_token>GET /ping/- Health check (no auth required)GET|POST /statuses/- View/create postsGET|POST /groups/- View/create groupsGET /groups/discover/- Discover all available groups with membership statusPOST /groups/{group_name}/join/- Join a groupPOST /groups/{group_name}/leave/- Leave a groupPOST /groups/{group_name}/add_member/- Add member to group (admin only)POST /groups/{group_name}/invite/- Invite user to group (admin only)POST /groups/accept_invite/{invite_id}/- Accept group invitationGET|POST /groups/{group_name}/posts/- View/create group postsGET|POST /messages/- View/send direct messages
# Health check
curl http://localhost:8000/ping/
# Create post (requires JWT)
curl -X POST -H "Authorization: Bearer <jwt_token>" \
-H "Content-Type: application/json" \
-d '{"content": "Hello, Chirp!"}' \
http://localhost:8000/statuses/
# Discover all groups
curl -H "Authorization: Bearer <jwt_token>" \
http://localhost:8000/groups/discover/
# Join a group
curl -X POST -H "Authorization: Bearer <jwt_token>" \
http://localhost:8000/groups/my-group/join/
# Leave a group
curl -X POST -H "Authorization: Bearer <jwt_token>" \
http://localhost:8000/groups/my-group/leave/The project includes tests:
- Model Tests
- Serializer Tests
- View Tests
- Endpoint Tests
- Middleware Tests
- Integration Tests
# Run all tests
python manage.py test
# Run specific app tests
python manage.py test posts.tests
python manage.py test groups.tests
python manage.py test dmessages.tests
# Run with verbose output
python manage.py test --verbosity=2
# Run specific test categories
python manage.py test posts.tests.test_models
python manage.py test groups.tests.test_endpoints
python manage.py test chirp.tests.test_middlewaregit checkout -b feature/new-feature# Add tests to appropriate test file
python manage.py test path.to.new.tests# Write code to make tests pass
python manage.py testpython manage.py test --verbosity=2git add .
git commit -m "Add new feature with tests"- Database Connection: Ensure PostgreSQL is running and credentials are correct
- JWT Errors: Check JWT_TEST_SECRET in settings
- Test Failures: Run tests individually to isolate issues
- Migration Errors: Reset database with
python manage.py migrate --run-syncdb
- OpenAPI spec available in
chirp_openapi.json - Import into Postman or Swagger UI for interactive testing
- Fork the repository
- Create feature branch
- Write tests for new functionality
- Ensure all tests pass
- Submit pull request
This project is licensed under the MIT License.
For more details, see the code in each app's directory and test suites.