How thatdipen/django-sample works
Project Type and Purpose
• Full-stack web application built with Django, following Domain-Driven Design (DDD) principles.
• Provides user signup/login flows, email verification (SendGrid), asynchronous tasks (Celery), custom logging, and exception handling.
File Structure
• Layered (“hexagonal”) architecture under the core/ package:
• core/domain → Entities, value objects, domain services, migrations
• core/application → Use-case–level services
• core/infrastructure → Implementations of external services (mail, logging)
• core/interface → HTTP adapters: Django views, URLs, background tasks
• core/driver → Entry points: ASGI/WSGI bootstrappers, Celery app
• Top-level: templates/ & core/static/ for UI, manage.py and settings.py for configuration, requirements.txt for dependencies, utils/ for shared utilities.
README for Insights
• Key components: Django web server, PostgreSQL (or another RDBMS), Celery worker, message broker (Redis/RabbitMQ), SendGrid API, custom logging service.
• Architectural principles: loosely coupled modules, data classes, reusability.
Main Components and Their Interactions
a. User’s Browser (Frontend)
• Requests HTML pages & static JS → Served by Django’s static handlers and template engine.
b. Web Layer (Django Server)
• Entry via core/driver ASGI/WSGI → URL routing in core/interface/urls.py → views in core/interface/users/views.py
c. Application Layer
• Views delegate to application services (core/application/users/services.py) which orchestrate domain logic.
d. Domain Layer
• Business rules in core/domain/users/models.py and domain services (core/domain/users/services.py).
e. Infrastructure Layer
• Email service: core/infrastructure/mailing_services/services.py (SendGrid)
• Logging service: core/infrastructure/log_services/services.py
f. Async Task Layer
• Celery configured in core/celery.py → tasks in core/interface/users/tasks.py → execute application/domain logic asynchronously.
g. Database
• Django ORM mapping to the RDBMS via models and migrations.
h. External Services
• Message broker (Redis/RabbitMQ) for Celery
• SendGrid API for mail delivery
• Optional: third-party auth, monitoring, etc.
Architectural Patterns and Principles
• Layered/hexagonal (ports & adapters) architecture: each layer only depends on inner layers via interfaces.
• DDD: Separation of domain entities, services, and application use cases.
• Asynchronous processing with Celery for long-running tasks (e.g., sending emails, password resets).
• Utility modules (utils/) provide shared functionality (type conversion, custom exceptions).