django-sveltekit-starter Svelte Themes

Django Sveltekit Starter

A production-ready monorepo template for building full-stack applications with Django (backend) and SvelteKit (frontend).

Django-SvelteKit Starter

A production-ready monorepo template for building full-stack applications with Django (backend) and SvelteKit (frontend).

๐Ÿš€ Features

  • Django Backend: REST API with Django REST Framework, JWT auth, Celery task queue
  • SvelteKit Frontend: Type-safe, fast, and modern UI with TypeScript
  • Type Safety: Auto-generated TypeScript types from Django OpenAPI schema
  • Docker Compose: One-command local development environment
  • Monorepo Benefits: Atomic commits, shared tooling, simplified workflow
  • Production Ready: Includes deployment configurations and infrastructure

๐Ÿ“ Project Structure

django-sveltekit-starter/
โ”œโ”€โ”€ backend/                # Django REST API
โ”‚   โ”œโ”€โ”€ project/            # Django project
โ”‚   โ”œโ”€โ”€ docker/             # Docker configuration
โ”‚   โ”œโ”€โ”€ ansible/            # Deployment automation
โ”‚   โ””โ”€โ”€ terraform/          # Infrastructure as code
โ”œโ”€โ”€ frontend/               # SvelteKit application
โ”‚   โ”œโ”€โ”€ src/                # Source code
โ”‚   โ””โ”€โ”€ static/             # Static assets
โ”œโ”€โ”€ docker-compose.yml      # Development environment
โ”œโ”€โ”€ Makefile                # Common development commands
โ”œโ”€โ”€ docs/                   # Project documentation
โ”‚   โ””โ”€โ”€ engineering-handbook/ # Engineering practices and standards
โ””โ”€โ”€ .github/                # CI/CD workflows

๐Ÿ“‹ Prerequisites

  • Python 3.11+
  • Node.js 20+
  • Docker & Docker Compose
  • Poetry (Python package manager)

๐Ÿš€ Quick Start

  1. Clone the repository

    git clone https://github.com/auros-one/django-sveltekit-starter.git
    cd django-sveltekit-starter
    
  2. Install dependencies

    make install
    
  3. Start development environment

    make run
    
  4. Access the applications

  5. Set up development data (optional)

    make fresh-start
    

    This creates a clean database with default admin credentials:

โšก Development Commands

Global Commands (from root directory)

make help               # Show all available commands
make install            # Install all dependencies + pre-commit hooks
make setup-pre-commit   # Install pre-commit hooks only
make sync-types         # Sync API types from backend to frontend
make run                # Start Docker Compose stack
make test               # Run all tests
make format             # Format code
make lint               # Lint code
make clean              # Clean generated files

Backend Commands

cd backend/
poetry run python manage.py runserver   # Dev server
poetry run python manage.py migrate     # Run migrations
poetry run pytest                       # Run tests
poetry run python manage.py shell       # Django shell

Frontend Commands

cd frontend/
npm run dev                 # Dev server (port 5173)
npm run sync-types         # Sync API types from backend (CRITICAL)
npm run build              # Production build
npm run check              # Type checking
npm run lint               # Lint code
npm run format             # Format code

โš™๏ธ Configuration

Database Setup

The project uses PostgreSQL. For development, the database runs in Docker via docker-compose.yml.

๐Ÿ”’ Type Safety

This monorepo emphasizes type safety between frontend and backend:

  1. Django generates OpenAPI schema with drf-spectacular
  2. TypeScript types are automatically generated from the schema using openapi-typescript
  3. Single command synchronizes everything: make sync-types

Always run after backend API changes:

make sync-types

๐Ÿ”’ Code Quality & Pre-commit

This monorepo uses intelligent pre-commit hooks that only run when relevant files change:

  • Backend tools (backend/**/*.py): black, isort, ruff, pyupgrade, django-upgrade, Django system checks
  • Frontend tools (frontend/**/*.{js,ts,svelte}): prettier, eslint, svelte-check
  • Smart type sync: Auto-generates TypeScript types when backend API files change

Pre-commit hooks are automatically installed with make install, or manually with make setup-pre-commit.

๐Ÿš€ CI/CD & GitHub Actions

Path-based GitHub Actions workflows for efficient CI/CD:

  • Backend CI: Triggers on backend/** changes - runs Django tests, migrations, linting
  • Frontend CI: Triggers on frontend/** OR any backend/** changes - syncs types, runs tests/linting
  • Integration Tests: Full Docker stack testing on main branch and PRs

โœ… Backend changes โ†’ backend tests + frontend type sync (safe & reliable) โœ… Frontend changes โ†’ frontend tests only โœ… Integration tests catch full-stack issues

๐Ÿ” Authentication

  • JWT tokens and a refresh token which is stored in HTTP-only cookies
  • Automatic token injection via API client middleware
  • Route protection in SvelteKit using server-side auth checks
  • Multi-tenant User model uses Django Sites framework for tenancy
  • Email-based authentication - users login with email, internal username is site_id-email
  • Admin authentication - Django admin accepts email instead of internal username
  • Site-aware - all authentication respects site boundaries for true multi-tenancy

Multi-Tenancy Architecture

This starter template implements multi-tenancy using Django's built-in Sites framework:

  • Each tenant = Django Site (no custom Tenant model needed)
  • Internal username format: {site_id}-{email} (e.g., "[email protected]")
  • Public interface: Users only see and use email addresses
  • Site middleware: Automatically identifies tenant from subdomain/domain
  • Isolated data: Users can only access data within their site
  • Admin support: Django admin works with email authentication across sites

๐Ÿงช Testing

Backend Tests

cd backend/
poetry run pytest                    # Run all tests
poetry run pytest --cov             # With coverage
poetry run pytest tests/test_api.py  # Specific test file

Frontend Tests

cd frontend/
npm run check    # Type checking
npm run lint     # Linting
npm test         # Unit tests (if configured)

๐Ÿš€ Deployment

Development

Use the root docker-compose.yml for simple development:

make run  # Starts all services

Production

The backend includes comprehensive deployment configurations:

  • Docker: Production-ready Dockerfile with multi-stage builds
  • Ansible: Automated deployment to servers
  • Terraform: Infrastructure provisioning
  • Celery: Background task processing with Redis

See backend/deploy.md for detailed deployment instructions.

๐Ÿค Contributing

  1. Create a feature branch from main
  2. Make your changes
  3. Run tests: make test
  4. Format code: make format
  5. Create a pull request

๐Ÿ“š Documentation

  • docs/: Comprehensive project documentation
    • engineering-handbook/: Engineering practices, standards, and workflows
  • backend/README.md: Backend-specific documentation
  • frontend/README.md: Frontend-specific documentation

Built with ๐Ÿ’š using Django 4.2+, SvelteKit 2+, and modern development practices.

Top categories

Loading Svelte Themes