Sample Project Overview
The Django-CFG Sample Project is a comprehensive demonstration of all Django-CFG features and capabilities. This guide walks you through every aspect of the project, from setup to advanced features.
Architecture Overview
What Youβll Learn
- π Project Creation - Using
django-cfg create-project - βοΈ Configuration Management - Type-safe settings with Pydantic v2
- ποΈ Multi-Database Setup - Automatic routing and migrations
- π¨ Admin Customization - Modern Unfold interface with dashboards
- π API Documentation - Auto-generated OpenAPI/Swagger
- π Authentication System - OTP-based user management
- β‘ Background Tasks - ReArq integration
- π± Service Integrations - Twilio, SendGrid, Telegram
- π³ Docker Deployment - Production-ready containerization
Quick Start
1. Create the Sample Project
# Create new project
django-cfg create-project "My Django-CFG Demo"
# Navigate to project
cd my_django_cfg_demo
# The project is ready to run!
poetry run python manage.py runserver2. Explore the Admin Interface
Visit http://127.0.0.1:8000/admin/ and login with:
- Email:
[email protected] - Password:
admin123
3. Check API Documentation
Visit http://127.0.0.1:8000/api/schema/swagger-ui/ for interactive API docs.
4. Monitor System Health
Visit http://127.0.0.1:8000/cfg/status/ for system health checks.
Whatβs Included
The sample project includes:
Multi-Database Architecture
Demonstrates sophisticated database routing with separate databases for different apps:
- Main Database - Users, sessions, admin
- Blog Database - Posts, comments, categories
- Shop Database - Products, orders, inventory
See Multi-Database Setup for details.
Modern Admin Interface
Built on the Unfold theme with:
- Custom dashboard with real-time metrics
- Organized navigation structure
- Beautiful UI with Material Design icons
- Responsive design for mobile access
See Admin Interface for customization options.
Comprehensive API
Auto-generated REST API with:
- OpenAPI/Swagger documentation
- JWT authentication
- Endpoint versioning
- Interactive testing interface
See API Documentation for endpoint details.
Service Integrations
Production-ready integrations with:
- Twilio - SMS and WhatsApp messaging
- SendGrid - Professional email delivery
- Telegram - Real-time notifications and bot commands
See Service Integrations for configuration.
Background Task Processing
ReArq integration for:
- Asynchronous email sending
- Order processing
- Scheduled cleanup tasks
- Scalable worker management
See Background Tasks for task examples.
Project Structure Overview
my_django_cfg_demo/
βββ π api/ # Configuration & Settings
β βββ π§ config.py # Main Django-CFG configuration
β βββ βοΈ settings.py # Auto-generated Django settings
β βββ π urls.py # Root URL configuration
β βββ π environment/ # Environment-specific configs
βββ π apps/ # Django Applications
β βββ π blog/ # Blog with posts & comments
β βββ π shop/ # E-commerce with products & orders
β βββ π₯ profiles/ # User profiles & preferences
βββ π core/ # Core utilities
βββ π db/ # Database files (SQLite)
βββ π docker/ # Docker configuration
βββ π static/ # Static files
βββ π templates/ # Django templates
βββ ποΈ manage.py # Django management script
βββ π pyproject.toml # Poetry dependenciesFor a detailed explanation of each directory, see Project Structure.
Configuration Architecture
The sample project showcases Django-CFGβs type-safe configuration system:
Configuration Code Example
from django_cfg import DjangoConfig
class SampleProjectConfig(DjangoConfig):
"""Complete Django-CFG sample configuration."""
# Project metadata
project_name: str = "Django CFG Sample"
debug: bool = env.debug
secret_key: str = env.secret_key
# Multi-database configuration
databases: Dict[str, DatabaseConfig] = {...}
# Service integrations
email: EmailConfig = EmailConfig(...)
twilio: TwilioConfig = TwilioConfig(...)
telegram: TelegramConfig = TelegramConfig(...)
# Admin interface
unfold: UnfoldConfig = UnfoldConfig(...)
# API configuration
drf: DRFConfig = DRFConfig(...)
# Create global config instance
config = SampleProjectConfig()For complete configuration details, see Configuration Setup.
Best Practices Demonstrated
1. Type-Safe Configuration
# β
Good: Type-safe configuration
class MyProjectConfig(DjangoConfig):
email: EmailConfig = EmailConfig(...)
# β Bad: Raw Django settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'2. Automatic Database Routing
# β
Good: Automatic routing
post = Post.objects.create(title="My Post") # Goes to blog_db automatically
# β Bad: Manual database selection
post = Post.objects.using('blog_db').create(title="My Post")3. Module-Based Services
# β
Good: Module-based services
email = DjangoEmailService() # Auto-configured
email.send_simple("Test", "Hello!", ["[email protected]"])
# β Bad: Manual configuration
from django.core.mail import send_mail
send_mail("Test", "Hello!", "[email protected]", ["[email protected]"])Next Steps
Now that you have an overview, explore these topics:
- Project Structure - Understand the folder organization
- Configuration Setup - Learn about configuration management
- Multi-Database Setup - Master database routing
- Admin Interface - Customize the admin dashboard
- API Documentation - Explore the REST API
- Authentication - Implement OTP authentication
- Background Tasks - Process tasks asynchronously
- Service Integrations - Connect external services
- Deployment - Deploy to production with Docker
Related Documentation
- CLI Tools - Manage your project via CLI
- Configuration Guide - Advanced configuration
- Modules System - Available modules
- Built-in Apps - Authentication and more
- Integrations - External services
The sample project demonstrates the full power of Django-CFG - from simple setup to production deployment! π