- 🖥️ Description
- 🚀 Features
- 🛠️ Technologies Used
- 📚 Installation
- 🔐 Authentication
- 📦 Usage
- 🎓 Key Learnings
- 🔮 Future Enhancements
The Form Builder API is a robust backend application built with Django and Django REST Framework (DRF). It allows administrators to create customizable forms with various question types (e.g., dropdowns, text fields, checkboxes), collect user responses, and analyze the data through insightful analytics endpoints.
This project serves as the foundation for a comprehensive form management system, enabling seamless form creation, distribution, and data analysis.
-
Form Management:
- Create, retrieve, update, and delete forms.
- Add multiple questions to each form with different types.
- Define options for questions like dropdowns and checkboxes.
-
Response Handling:
- Allow users to submit responses to forms.
- Support various answer types based on question types.
-
Analytics:
- Generate insightful analytics for each form.
- Analyze response data, including option selection counts and text response insights.
-
Authentication & Permissions:
- Implement Token Authentication for secure access.
- Restrict administrative actions to authorized users.
-
API Documentation:
- Interactive documentation using Swagger/OpenAPI.
- Organized Postman Collections for easy API testing and collaboration.
-
Backend:
- Django - High-level Python Web framework.
- Django REST Framework (DRF) - Toolkit for building Web APIs.
- drf-yasg - Automatic Swagger/OpenAPI 2.0 schema generation.
- django-cors-headers - Django app for handling the server headers required for Cross-Origin Resource Sharing (CORS).
- djangorestframework-simplejwt - JSON Web Token authentication for DRF.
-
Testing:
- pytest & pytest-django - Testing frameworks.
- DRF's built-in
APIClientfor API testing.
-
Version Control:
Follow these steps to set up the Form Builder API on your local machine.
Ensure you have the following installed:
- Python 3.8 or higher
- pip (Python package installer)
- Git (for version control)
- Virtual Environment Tool (
venvorvirtualenv)
-
Clone the Repository
git clone https://github.com/Nani2139/morpheus.git cd morpheus
-
Create a Virtual Environment
python -m venv venv
-
Activate the Virtual Environment
Windows: venv\Scripts\activate macOS/Linux:source venv/bin/activate
-
Install Dependencies
pip install django djangorestframework drf-yasg django-cors-headers djangorestframework-simplejwt
-
Apply Migrations python manage.py migrate
-
Create a Superuser python manage.py createsuperuser
-
Run the Development Server python manage.py runserver
-
Access the Application Admin Panel: http://127.0.0.1:8000/admin/ API Endpoints: http://127.0.0.1:8000/api/ Swagger Documentation: http://127.0.0.1:8000/swagger/ ReDoc Documentation: http://127.0.0.1:8000/redoc/
This project utilizes Token Authentication to secure its API endpoints. Here's a brief overview:
- Purpose: Ensure that only authenticated users can access protected endpoints.
- Implementation:
- Users obtain a token by providing their credentials.
- This token must be included in the
Authorizationheader of subsequent API requests.
- Endpoints:
- Obtain Token:
/api/token/(POST)- Payload:
{ "username": "yourusername", "password": "yourpassword" } - Response:
{ "refresh": "your_refresh_token", "access": "your_access_token" }
- Payload:
- Refresh Token:
/api/token/refresh/(POST)- Payload:
{ "refresh": "your_refresh_token" } - Response:
{ "access": "new_access_token" }
- Payload:
- Obtain Token:
- Admin Endpoints: Restricted to admin users only.
- Response Submission: Open to any authenticated user.
Note: Ensure that you include the obtained access token in the Authorization header as follows:
Here's how to interact with the Form Builder API:
- Access Admin Panel:
Navigate to http://127.0.0.1:8000/admin/ and log in with your superuser credentials.
-
Manage Forms, Questions, and Options:
-
Forms: Create, edit, or delete forms.
-
Questions: Add various types of questions to each form.
-
Options: Define selectable options for questions like dropdowns and checkboxes.
-
Endpoint:
POST /api/responses/ -
Payload Example:
{
"form": 3,
"answers": [
{
"question": 1,
"selected_option": 2
}
]
}-
Token-Based Authentication with Django REST Framework:
- Implemented secure token authentication to protect API endpoints, ensuring that only authorized users can access sensitive functionalities.
- Managed token generation, refreshing, and validation using
djangorestframework-simplejwt, enhancing the security and scalability of the authentication system.
-
Comprehensive API Documentation:
- Utilized
drf-yasgto generate interactive Swagger/OpenAPI documentation, providing clear and accessible information for developers to understand and test API endpoints. - Created organized Postman Collections to facilitate efficient API testing.
- Utilized
-
Backend Development and Data Analytics:
- Designed and developed a robust backend system with Django models, serializers, and viewsets to handle dynamic form creation, user responses, and data storage.
- Developed custom analytics endpoints to process and visualize response data, offering valuable insights and enhancing the decision-making capabilities for administrators.
While the current scope covers the backend functionalities, there are several avenues for future development:
-
Frontend Interface:
- User Interface for End-Users: Enable users to interact with forms seamlessly through a web or mobile application.
- Admin Dashboard: Provide administrators with a user-friendly dashboard to manage forms and view analytics.
-
Advanced Authentication:
- Implement OAuth2: For more secure and scalable authentication mechanisms.
- Role-Based Access Control: Define user roles with specific permissions.
-
Extended Analytics:
- Sentiment Analysis: Analyze text responses for sentiment insights.
- Data Visualization: Integrate charts and graphs to represent analytics data visually.
-
Email Notifications:
- Response Alerts: Notify administrators when new responses are submitted.
-
Deployment:
- Production Setup: Deploy the application to cloud platforms like Heroku, AWS, or DigitalOcean.
- CI/CD Integration: Automate testing and deployment processes.