How reza-ns/blog-api-drf works
The Blog API project is a backend service built with Django and Django Rest Framework (DRF) that provides a blog platform inspired by Medium.com. It handles both free and paid articles, user authentication (via phone/OTP or email/password), user profiles, subscriptions (with various plans and expiration logic using Celery), and payment processing (integrated with the Zarinpal gateway).
Main Components
• Authentication & Accounts Module:
• Contains user management logic, custom authentication (JWT, OTP), and user profile management.
• Key files: Blog-API-drf/accounts/ (views, serializers, models, utils for JWT, OTP, and Redis integrations).
• Blog Module:
• Handles article creation (both free and paid), comments, and other blog-related features.
• Key files: Blog-API-drf/blog/ (APIs, models, views, serializers, and tests).
• Payment Module:
• Manages subscription payments using the Zarinpal gateway.
• Key files: Blog-API-drf/payment/ (APIs, models, signals, and utility integration with zarinpal).
• Subscription Module:
• Manages subscription plans, creation (leveraging Django signals), and expiration logic (using Celery tasks).
• Key files: Blog-API-drf/subscription/ (models, signals/receivers, tasks, views, serializers).
• Configuration & Application Bootstrapping:
• Bootstrapping code for Django (wsgi/asgi), settings, URL routing, and Celery integration.
• Key files: Blog-API-drf/config/ (asgi.py, wsgi.py, settings.py, urls.py) and manage.py.
• Infrastructure & Deployment:
• Docker configuration for containerized deployment.
• Key file: docker/docker-compose.yml.
• External Services and Database:
• Postgres is used for the database, while Celery and Redis are used for asynchronous tasks and caching respectively.
Out Relationships and Interactions
• That the API endpoints (in accounts/api, blog/api, payment/api, and subscription/api) interact with their respective models and serializers to handle client requests.
• From client/API gateway → Django controllers (views), then to business logic & data layer (models).
• Between modules: for example, the accounts module interconnects with blog (to link authors to articles) and with subscription/payment (to validate user subscriptions for accessing paid content).
• Decoupled components with Django signals (e.g., creating subscriptions when certain events occur) and Celery tasks handling background processes (subscription expiration).
Architectural Patterns and Design Principles
• MVC/MVT Framework: Emphasize the Django Model-View-Template (or DRF’s serializer-viewset approach) that structures the project.
• Modularization: Each functionality (accounts, blog, payment, subscription) exists as separate Django apps, promoting modular design.
• Asynchronous Processing: Use of Celery for background tasks (subscription management).
• Dependency Management: Integration with external payment provider (Zarinpal) and caching mechanisms (via Redis).
Details on Technologies and Frameworks
• Python, Django, and DRF drive the backend logic.
• Celery (with Django integration via Blog-API-drf/config/celery.py) handles asynchronous execution.
• Postgres serves as the relational database.
• Docker ensures containerized deployment.
• External integrations such as Zarinpal (for payments) and potential use of Redis in authentication.
Elements
• Labels:
• Tag each component (e.g., “Accounts Service”, “Blog Service”, “Payment Service”, “Subscription Service”, “Configuration”, “External Services”).
• Interactions between modules (e.g., Accounts → Blog for user content association, Payment → Subscription for plan activation).
• Visual Distinction:
• Notes/Annotations:
• Briefly label communication protocols (such as HTTP/HTTPS for API calls, or asynchronous messaging for Celery tasks).