Web site for The TechNous club
This is a Backend for the main website of our TechNous club .
To set up the project locally, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/TheTechNous.git cd TheTechNous
-
Set up a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r Backend/requirements.txt
-
Set up environment variables: Create a
.env
file in theBackend
directory and add the following environment variables:DJANGO_SECRET_KEY=your_secret_key DJANGO_DEBUG=True DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1
-
Apply database migrations:
python Backend/api/manage.py migrate
-
Start the development server:
python Backend/api/manage.py runserver
To register a new user, send a POST request to the /auth/register
endpoint with the following JSON payload:
{
"username": "john_doe",
"email": "[email protected]",
"password": "password123"
}
To log in, send a POST request to the /auth/login
endpoint with the following JSON payload:
{
"username": "john_doe",
"password": "password123",
"otp": "123456" # If MFA is enabled
}
To create a new blog post, send a POST request to the /blog/post
endpoint with the following JSON payload:
{
"title": "New Blog Post",
"content": "This is the content of the new blog post."
}
Include the JWT token in the Authorization header:
Authorization: Bearer your_jwt_token
We welcome contributions to TheTechNous! To contribute, follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix:
git checkout -b my-feature-branch
- Make your changes and commit them with a descriptive commit message.
- Push your changes to your forked repository:
git push origin my-feature-branch
- Create a pull request to the main repository.
For detailed API documentation, including endpoints, request/response formats, and examples, please refer to the API Documentation.
For detailed deployment instructions, including environment setup, configuration, and deployment steps, please refer to the Deployment Instructions.
For a troubleshooting guide to help resolve common issues, please refer to the Troubleshooting Guide.
For detailed steps on how to integrate the back-end with the front-end of the LMS website, please refer to the Frontend Integration Documentation.
The backend uses a custom pagination class to standardize the pagination of API responses. This ensures that all paginated responses follow a consistent structure, making it easier for frontend developers to handle paginated data.
The CustomPagination
class is defined in Backend/api/api/views.py
and extends the PageNumberPagination
class from Django REST framework. It overrides the get_paginated_response
method to return a standardized response format.
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
class CustomPagination(PageNumberPagination):
page_size = 10
page_size_query_param = 'page_size'
max_page_size = 100
def get_paginated_response(self, data):
return Response({
'status': 'success',
'data': data,
'metadata': {
'page': self.page.number,
'page_size': self.page_size,
'total_pages': self.page.paginator.num_pages,
'total_items': self.page.paginator.count
}
})
To use the CustomPagination
class in your API views, set it as the pagination_class
in your viewsets or API views.
from rest_framework import viewsets
from .models import YourModel
from .serializers import YourModelSerializer
from .pagination import CustomPagination
class YourModelViewSet(viewsets.ModelViewSet):
queryset = YourModel.objects.all()
serializer_class = YourModelSerializer
pagination_class = CustomPagination
By using the CustomPagination
class, you ensure that all paginated API responses follow a consistent structure, making it easier for frontend developers to handle paginated data.
To prevent abuse and DDoS attacks, rate limiting has been implemented for all API endpoints using the flask_limiter
package. This helps to ensure that the API remains responsive and available to legitimate users.
Comprehensive input validation and sanitization have been added to all schemas using the marshmallow
library. This helps to prevent SQL injection and other attacks by ensuring that all input data is properly validated and sanitized before being processed.
Password security has been enhanced by using the Argon2 hashing algorithm in the User
model. Argon2 is a more secure hashing algorithm that provides better protection against brute-force attacks.
Two-factor authentication (2FA) has been implemented for user accounts using the pyotp
library. This adds an extra layer of security by requiring users to provide a one-time password (OTP) in addition to their regular password when logging in.
Caching has been implemented for frequently accessed data using the flask_caching
package. This helps to reduce database load and improve response times by storing frequently accessed data in memory.
Database queries have been optimized by using indexing and query optimization techniques. This helps to improve the performance of database operations and reduce the time it takes to retrieve data.
Asynchronous processing has been implemented for time-consuming tasks, such as sending emails or processing large datasets, using Celery. This helps to improve the responsiveness of the API by offloading time-consuming tasks to background workers.
Connection pooling has been implemented for the database to improve performance and resource utilization. This helps to reduce the overhead of establishing new database connections and ensures that database connections are reused efficiently.
A comprehensive CI/CD pipeline has been set up to automate testing, linting, and deployment. This helps to ensure that code changes are thoroughly tested and validated before being deployed to production.
Detailed API documentation has been provided using tools like Swagger or ReDoc. This helps developers understand the available API endpoints, request/response formats, and usage examples.
A standardized response format has been implemented for all API endpoints. This ensures consistency and improves error handling by providing a uniform structure for all API responses.
Detailed contribution guidelines have been provided to help developers contribute to the project. This includes instructions for forking the repository, creating branches, making changes, and submitting pull requests.