|
| 1 | +# Django SaaS example app |
| 2 | + |
| 3 | +A Django 3.0+ SaaS application for testing PostHog wizard integration. This app provides subscription billing, user authentication, and project management features. |
| 4 | + |
| 5 | +## Running the app |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | + |
| 9 | +- Python 3.10+ |
| 10 | +- SQLite (included with Python, used by default) |
| 11 | +- Stripe account (optional, app runs in demo mode without it) |
| 12 | + |
| 13 | +### Installation |
| 14 | + |
| 15 | +1. Create and activate a virtual environment: |
| 16 | + |
| 17 | +```bash |
| 18 | +python -m venv venv |
| 19 | +source venv/bin/activate # On Windows: venv\Scripts\activate |
| 20 | +``` |
| 21 | + |
| 22 | +1. Install dependencies: |
| 23 | + |
| 24 | +```bash |
| 25 | +pip install -r requirements.txt |
| 26 | +``` |
| 27 | + |
| 28 | +1. Set up environment variables (create a `.env` file): |
| 29 | + |
| 30 | +```bash |
| 31 | +SECRET_KEY=your-secret-key |
| 32 | +# DATABASE_URL=postgresql://... # Optional, defaults to SQLite |
| 33 | +STRIPE_PUBLIC_KEY=pk_test_... # Optional, enables Stripe |
| 34 | +STRIPE_SECRET_KEY=sk_test_... # Optional, enables Stripe |
| 35 | +STRIPE_WEBHOOK_SECRET=whsec_... # Optional, for webhooks |
| 36 | +``` |
| 37 | + |
| 38 | +> **Note:** By default, the app uses SQLite (`db.sqlite3`) and runs in demo mode without Stripe. No additional setup is required for local development. |
| 39 | +
|
| 40 | +1. Initialize the database: |
| 41 | + |
| 42 | +```bash |
| 43 | +python manage.py migrate |
| 44 | +python manage.py seed_plans # Optional: seed pricing plans |
| 45 | +``` |
| 46 | + |
| 47 | +1. Run the development server: |
| 48 | + |
| 49 | +```bash |
| 50 | +python manage.py runserver |
| 51 | +``` |
| 52 | + |
| 53 | +The app will be available at `http://127.0.0.1:8000`. |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## Application structure |
| 58 | + |
| 59 | +``` |
| 60 | +├── manage.py # Django management script |
| 61 | +├── requirements.txt # Python dependencies |
| 62 | +├── accounts/ # User authentication & profiles |
| 63 | +│ ├── models.py # Custom User model |
| 64 | +│ ├── views.py # Login, register, password reset |
| 65 | +│ └── forms.py # Auth forms |
| 66 | +├── billing/ # Subscription & payment handling |
| 67 | +│ ├── models.py # Plan, Subscription models |
| 68 | +│ ├── views.py # Stripe checkout, webhooks, billing portal |
| 69 | +│ ├── admin.py # Django admin customization |
| 70 | +│ └── management/ # seed_plans command |
| 71 | +├── config/ # Django settings |
| 72 | +│ ├── settings.py |
| 73 | +│ ├── urls.py |
| 74 | +│ └── wsgi.py |
| 75 | +├── dashboard/ # Main app functionality |
| 76 | +│ ├── models.py # Project, ActivityLog models |
| 77 | +│ ├── views.py # Dashboard, project CRUD |
| 78 | +│ └── forms.py |
| 79 | +├── marketing/ # Public pages |
| 80 | +│ └── views.py # Home, features pages |
| 81 | +├── static/ # CSS, JS, images |
| 82 | +└── templates/ # HTML templates |
| 83 | +``` |
| 84 | + |
| 85 | +## Features |
| 86 | + |
| 87 | +### Authentication |
| 88 | + |
| 89 | +- User registration with email |
| 90 | +- Login/logout with session management |
| 91 | +- Password reset via email |
| 92 | +- User profiles and settings |
| 93 | + |
| 94 | +### Billing & subscriptions |
| 95 | + |
| 96 | +- Pricing page with plan tiers |
| 97 | +- Stripe Checkout integration |
| 98 | +- Subscription management (upgrade/downgrade/cancel) |
| 99 | +- Stripe webhook handling |
| 100 | +- Demo mode when Stripe is not configured |
| 101 | + |
| 102 | +### Dashboard |
| 103 | + |
| 104 | +- Project CRUD (create, read, update, delete) |
| 105 | +- Activity logging |
| 106 | +- Usage metrics display |
| 107 | +- Subscription status |
| 108 | + |
| 109 | +### Admin panel |
| 110 | + |
| 111 | +- Django admin at `/admin/` |
| 112 | +- Plan management with subscriber counts |
| 113 | +- Subscription management with status badges |
| 114 | + |
| 115 | +## Database models |
| 116 | + |
| 117 | +| Model | Description | |
| 118 | +|-------|-------------| |
| 119 | +| `User` | Custom user model with authentication and Stripe customer ID | |
| 120 | +| `Plan` | Subscription plans with pricing and Stripe price IDs | |
| 121 | +| `Subscription` | User subscriptions with status tracking | |
| 122 | +| `Project` | User projects with activity logging | |
| 123 | +| `ActivityLog` | Audit trail for user actions | |
| 124 | + |
| 125 | +## Key dependencies |
| 126 | + |
| 127 | +- **Django** - Web framework |
| 128 | +- **Stripe** - Payment processing |
| 129 | +- **Whitenoise** - Static file serving |
| 130 | +- **dj-database-url** - Database configuration from URL |
| 131 | +- **python-dotenv** - Environment variable management |
0 commit comments