Skip to content

TrippleA-Ashaba/shirobase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Shirobase

A production-ready Django skeleton project that serves as a solid starting point for building modern web applications.

๐ŸŽฏ Overview

Shirobase is a production-ready Django skeleton project designed to jumpstart your development process. Instead of spending hours setting up the same boilerplate configurations for every new project, use Shirobase as your foundation.

What's Included:

  • Complete authentication system with JWT tokens and REST APIs
  • Two pre-built Django apps (users and accounts)
  • API documentation with Swagger/ReDoc
  • Docker containerization
  • Testing framework with pytest
  • Code quality tools (Ruff linter)
  • Comprehensive middleware and security configurations
  • Development tools (debug toolbar, auto-reload)
  • Production-ready settings (WhiteNoise, logging, PostgreSQL support)

This skeleton comes with 20+ essential packages and best practices already integrated, allowing you to focus on building your application's unique features from day one.

๐Ÿš€ Tech Stack

  • Python 3.14 - Latest Python version
  • Django 5.2 - Modern Django framework
  • uv - Fast Python package manager
  • Django REST Framework - RESTful API toolkit
  • PostgreSQL/SQLite - Database support
  • Docker - Containerization support

โœจ Features

This skeleton project includes:

Core Setup

  • โœ… Pre-configured Django 5.2 setup
  • โœ… Modern Python 3.14 support
  • โœ… UV package management for lightning-fast dependency resolution
  • โœ… Docker configuration for containerized deployment
  • โœ… Clean project structure with organized apps

Authentication & Authorization

  • โœ… Custom User model with Profile support
  • โœ… Django Allauth integration for complete authentication flows
  • โœ… DJ-REST-Auth for RESTful API authentication endpoints
  • โœ… JWT authentication with SimpleJWT (access & refresh tokens)
  • โœ… Token blacklisting support
  • โœ… Custom permissions system (Smartmin)
  • โœ… Django Author for automatic created_by/modified_by tracking

API Development

  • โœ… Django REST Framework fully configured
  • โœ… drf-spectacular for automatic OpenAPI/Swagger documentation
  • โœ… Django Filter for advanced filtering
  • โœ… Custom CSRF middleware with API exemptions
  • โœ… Pagination enabled by default

Database & Models

  • โœ… PostgreSQL support (with psycopg)
  • โœ… SQLite support for development
  • โœ… Django Extensions with TimeStampedModel
  • โœ… Phone number field support
  • โœ… Audit logging with django-auditlog

Testing & Code Quality

  • โœ… Pytest configuration with Django integration
  • โœ… pytest-sugar for enhanced test output
  • โœ… pytest-xdist for parallel test execution
  • โœ… Ruff for fast Python linting and formatting
  • โœ… Comprehensive test structure

Development Tools

  • โœ… Django Debug Toolbar (in DEBUG mode)
  • โœ… Django Browser Reload for auto-refresh
  • โœ… Django Extensions with management commands
  • โœ… Loguru for advanced logging
  • โœ… Environment variable management (django-environ, python-dotenv)

Production Ready

  • โœ… WhiteNoise for static file serving
  • โœ… Security middleware configured
  • โœ… CSRF protection with trusted origins
  • โœ… Login required middleware
  • โœ… Ready for production deployment

๐Ÿ“‹ Prerequisites

  • Python 3.14 or higher
  • uv package manager

โšก Quick Start

For those who want to get running immediately:

# Clone and setup
git clone <repository-url> myproject && cd myproject

# Install dependencies
uv sync

# Setup database
uv run python manage.py migrate

# Create admin user
uv run python manage.py createsuperuser

# Run server
uv run python manage.py runserver

Visit http://localhost:8000 - you're ready to build! ๐Ÿš€

๐Ÿ”ง Detailed Setup

1. Clone or Use as Template

# Clone the repository
git clone <repository-url> your-project-name
cd your-project-name

2. Install Dependencies

# Using uv (recommended)
uv sync

3. Set Up Environment Variables

Create a .env file in the project root with your configuration:

# Security
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1

# Database (SQLite - default for development)
USE_SQLITE=True

# Database (PostgreSQL - for production)
# USE_SQLITE=False
# DB_NAME=your_database_name
# DB_USER=your_database_user
# DB_PASSWORD=your_database_password
# DB_HOST=localhost
# DB_PORT=5432

4. Run Migrations

uv run python manage.py migrate

5. Create Superuser

uv run python manage.py createsuperuser

6. Start Development Server

uv run python manage.py runserver

Visit http://localhost:8000 to see your application running.

7. Access API Documentation

Once the server is running, visit:

  • Docs: http://localhost:8000/api/docs/
  • Swagger UI: http://localhost:8000/api/schema/swagger-ui/
  • ReDoc: http://localhost:8000/api/schema/redoc/
  • OpenAPI Schema: http://localhost:8000/api/schema/

8. Access Django Admin

Use your superuser credentials to access the admin panel:

  • Admin Panel: http://localhost:8000/admin/

๐ŸŽฏ Pre-built Apps

Users App

  • Custom User model extending Django's AbstractUser
  • User Profile model with phone number field
  • Automatic timestamp tracking (created/modified)
  • Author tracking (who created/modified)

Accounts App

  • Complete REST API for authentication:
    • POST /api/accounts/login/ - User login (returns JWT tokens)
    • POST /api/accounts/logout/ - User logout
    • POST /api/accounts/registration/ - User registration
    • GET/PUT /api/accounts/user/ - Get/update user details
    • POST /api/accounts/password/change/ - Change password
    • POST /api/accounts/password/reset/ - Request password reset
    • POST /api/accounts/password/reset/confirm/<uid>/<token>/ - Confirm password reset

๐Ÿณ Docker Support

Build and run the application using Docker:

# Build the Docker image
docker build -t shirobase:latest .

# Run the container
docker run -p 8000:8000 --env-file .env shirobase:latest

# Run in detached mode
docker run -d -p 8000:8000 --env-file .env shirobase:latest

# Access running container
docker exec -it <container_id> sh

๐Ÿ“ฆ Production Deployment

Before deploying to production:

# Set DEBUG=False in your .env file
DEBUG=False

# Collect static files
uv run python manage.py collectstatic --noinput

# Run migrations
uv run python manage.py migrate

# Create cache table (if using database cache)
uv run python manage.py createcachetable

# Check for common issues
uv run python manage.py check --deploy

๐Ÿงช Running Tests

# Run all tests
uv run pytest

# Run with coverage
uv run pytest --cov

# Run specific test file
uv run pytest path/to/test_file.py

# Run specific test Test Class
uv run pytest path/to/test_file.py::DummyTestClass

# Run specific test function
uv run pytest path/to/test_file.py::DummyTestClass::dummy_test_successful

# Run tests in parallel
uv run pytest -n auto

๐ŸŽจ Code Quality

Linting and Formatting

The project uses Ruff for fast linting and formatting:

# Check code for issues
uv run ruff check .

# Auto-fix issues
uv run ruff check --fix .

# Format code
uv run ruff format .

Debug Tools

When DEBUG=True, the following tools are available:

  • Debug Toolbar: Visible on all pages, provides insights into queries, templates, cache, etc.
  • Browser Reload: Automatically refreshes the browser when code changes are detected

๐Ÿ› ๏ธ Useful Management Commands

Django Extensions provides additional helpful commands:

# Show all URLs in the project
uv run python manage.py show_urls

# Generate UML diagram of models
uv run python manage.py graph_models -a -o models.png

# Run Django shell with auto-imports
uv run python manage.py shell_plus

# Clear all sessions
uv run python manage.py clear_cache

# Validate templates
uv run python manage.py validate_templates

# Show database info
uv run python manage.py sqlcreate

# Drop test database
uv run python manage.py drop_test_database

๐Ÿ“ฆ Included Packages

This project comes pre-configured with:

Authentication & Authorization

  • django-allauth[socialaccount] (v65.13.1+) - Complete authentication system with social auth support
  • dj-rest-auth (v7.0.1+) - REST API endpoints for authentication operations
  • djangorestframework-simplejwt (v5.5.1+) - JWT authentication tokens
  • smartmin (v5.2.2+) - Advanced permissions and user management

API & Documentation

  • djangorestframework - Powerful and flexible toolkit for building Web APIs
  • drf-spectacular (v0.29.0+) - OpenAPI 3.0 schema generation and Swagger UI
  • django-filter (v25.2+) - Dynamic QuerySet filtering

Database & Models

  • psycopg[binary] (v3.2.12+) - PostgreSQL adapter for Python
  • django-phonenumber-field[phonenumbers] (v8.3.0+) - Phone number field with validation
  • django-extensions (v4.1+) - Custom management commands and model extensions
  • django-author (v1.2.0+) - Automatic created_by/modified_by tracking
  • django-auditlog (v3.3.0+) - Track model changes and user actions

Development Tools

  • django-debug-toolbar (v6.1.0+) - Debug panel for Django applications
  • django-browser-reload (v1.21.0+) - Auto-reload browser on code changes
  • ruff (v0.14.6+) - Fast Python linter and formatter

Testing

  • pytest-django (v4.11.1+) - Pytest plugin for Django
  • pytest-sugar (v1.1.1+) - Enhanced test output with progress bar
  • pytest-xdist (v3.8.0+) - Parallel test execution

Utilities

  • loguru (v0.7.3+) - Simplified logging with advanced features
  • django-environ (v0.12.0+) - Environment variable management
  • python-dotenv (v1.2.1+) - Load environment variables from .env file
  • whitenoise (v6.11.0+) - Static file serving for production

๐Ÿ—๏ธ Project Structure

shirobase/
โ”œโ”€โ”€ apps/                       # Django applications
โ”‚   โ”œโ”€โ”€ accounts/              # Authentication endpoints & serializers
โ”‚   โ””โ”€โ”€ users/                 # Custom User model and Profile
โ”œโ”€โ”€ django_project/            # Main project configuration
โ”‚   โ”œโ”€โ”€ settings.py           # Project settings
โ”‚   โ”œโ”€โ”€ urls.py               # URL configuration
โ”‚   โ”œโ”€โ”€ middleware.py         # Custom middleware (CSRF handling)
โ”‚   โ”œโ”€โ”€ permissions.py        # Permission definitions
โ”‚   โ””โ”€โ”€ wsgi.py               # WSGI application
โ”œโ”€โ”€ templates/                 # HTML templates
โ”œโ”€โ”€ static/                    # Static files (CSS, JS, images)
โ”œโ”€โ”€ logs/                      # Application logs
โ”œโ”€โ”€ pyproject.toml            # Project dependencies and metadata
โ”œโ”€โ”€ uv.lock                   # Locked dependencies
โ”œโ”€โ”€ pytest.ini                # Pytest configuration
โ”œโ”€โ”€ ruff.toml                 # Ruff linter configuration
โ”œโ”€โ”€ Dockerfile                # Docker container definition
โ”œโ”€โ”€ entrypoint.sh            # Docker entrypoint script
โ”œโ”€โ”€ manage.py                # Django management script
โ”œโ”€โ”€ db.sqlite3               # SQLite database (development)
โ””โ”€โ”€ README.md                # This file

โš™๏ธ Key Configuration

Authentication Settings

The project is configured with:

  • Custom User Model: apps.users.User with email authentication
  • JWT Tokens: Access and refresh tokens with blacklist support
  • Email Verification: Optional (can be set to 'mandatory' or 'none')
  • Login Methods: Email-based authentication
  • Session + JWT: Both session and JWT authentication enabled

Middleware

Custom middleware included:

  • CustomCsrfViewMiddleware: Exempts API endpoints from CSRF (configurable via CSRF_EXEMPT_URLS)
  • LoginRequiredMiddleware: Enforces authentication site-wide (configure exemptions as needed)
  • WhiteNoiseMiddleware: Serves static files efficiently in production
  • AuditlogMiddleware: Tracks all model changes automatically

Logging

Loguru is configured to:

  • Write logs to logs/shirobase.log
  • Rotate log files at 10 MB
  • Retain logs for 10 days

Static Files

  • Development: Served by Django
  • Production: Served by WhiteNoise
  • Static files directory: static/
  • Collected static files: staticfiles/

๐ŸŽจ Customization

This is a skeleton project meant to be customized for your specific needs:

  1. Rename the project: Update django_project folder and all references to match your application name
  2. Add your Django apps: Create new apps in the apps/ directory
  3. Configure database: Switch between SQLite (development) and PostgreSQL (production) via environment variables
  4. Customize authentication: Extend the User and Profile models in apps/users/models.py
  5. Add permissions: Define custom permissions in django_project/permissions.py
  6. Configure CSRF: Add your domains to CSRF_TRUSTED_ORIGINS in settings
  7. Add business logic: Build your features using the pre-configured foundation

๐Ÿ”ง Troubleshooting

Common Issues

Issue: ModuleNotFoundError when running commands

# Make sure you're using uv run before python commands
uv run python manage.py runserver

Issue: Database migration conflicts

# Reset migrations (development only!)
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc" -delete
uv run python manage.py makemigrations
uv run python manage.py migrate

Issue: Static files not loading

# Collect static files
uv run python manage.py collectstatic --noinput

Issue: CSRF errors on API endpoints

  • Ensure your API URLs are prefixed with /api (configured in CSRF_EXEMPT_URLS)
  • Or add your custom patterns to CSRF_EXEMPT_URLS in settings

Issue: Login required on public pages

  • Configure LOGIN_EXEMPT_URLS or modify LoginRequiredMiddleware behavior in settings

๐Ÿค Contributing

This is a base template project. Feel free to fork and customize it for your needs.

๐Ÿ“ License

  • MIT

๐Ÿ”ฎ Roadmap

Completed:

  • โœ… Pre-configured Django apps (users, accounts)
  • โœ… Docker configuration
  • โœ… API documentation setup (drf-spectacular)
  • โœ… Multiple commonly used packages integrated

Planned:

  • Add CI/CD pipeline examples (GitHub Actions, GitLab CI)
  • Celery integration for async tasks
  • Redis caching setup
  • Email template examples
  • Frontend integration examples (React/Vue)
  • Production deployment guides (AWS, DigitalOcean, Railway)
  • Social authentication providers setup
  • File upload handling (S3/local storage)
  • API rate limiting
  • Monitoring and error tracking setup

๐Ÿ“ž Support

For issues, questions, or contributions, please refer to the project's issue tracker.


Built with โค๏ธ to accelerate Django development

About

A production-ready Django skeleton project that serves as a solid starting point for building modern web APIs.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages