Metadata-Version: 2.4
Name: django-schematic
Version: 1.3.12
Summary: Interactive schema visualization for Django projects — React Flow + force-directed layout
Project-URL: Homepage, https://github.com/jsheffie/django-schematic
Project-URL: Issues, https://github.com/jsheffie/django-schematic/issues
Project-URL: Changelog, https://github.com/jsheffie/django-schematic/releases
Author-email: Jeff Sheffield <jeff.sheffield@gmail.com>
License: MIT License
        
        Copyright (c) 2026 jsheffie
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: django,graph,models,schema,visualization
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 5.1
Classifier: Framework :: Django :: 5.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.12
Requires-Dist: django>=5.1
Provides-Extra: ci
Requires-Dist: playwright; extra == 'ci'
Provides-Extra: dev
Requires-Dist: django-stubs; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-django; extra == 'dev'
Description-Content-Type: text/markdown

# django-schematic

[![Latest on Django Packages](https://img.shields.io/badge/Django%20Packages-django--schematic-8c3c26.svg)](https://djangopackages.org/packages/p/django-schematic/)
[![PyPI version](https://img.shields.io/pypi/v/django-schematic)](https://pypi.org/project/django-schematic/)
[![PyPI downloads](https://img.shields.io/pypi/dm/django-schematic)](https://pypi.org/project/django-schematic/)
[![Python versions](https://img.shields.io/pypi/pyversions/django-schematic)](https://pypi.org/project/django-schematic/)
[![License](https://img.shields.io/pypi/l/django-schematic)](https://github.com/jsheffie/django-schematic/blob/main/LICENSE)
[![Python Tests](https://github.com/jsheffie/django-schematic/actions/workflows/tests.yml/badge.svg)](https://github.com/jsheffie/django-schematic/actions/workflows/tests.yml)
[![UI Tests](https://github.com/jsheffie/django-schematic/actions/workflows/ui-tests.yml/badge.svg)](https://github.com/jsheffie/django-schematic/actions/workflows/ui-tests.yml)
[![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
[![React](https://img.shields.io/badge/React-18-61DAFB?logo=react&logoColor=black)](https://react.dev/)
[![Vite](https://img.shields.io/badge/Vite-6-646CFF?logo=vite&logoColor=white)](https://vite.dev/)
[![React Flow](https://img.shields.io/badge/@xyflow%2Freact-React%20Flow-ff0072)](https://reactflow.dev/)
[![d3-force](https://img.shields.io/badge/layout-d3--force-F9A03C?logo=d3dotjs&logoColor=white)](https://d3js.org/d3-force)
[![dagre](https://img.shields.io/badge/layout-dagre-4A90D9)](https://github.com/dagrejs/dagre)
[![ELK](https://img.shields.io/badge/layout-ELK-5C9E4A)](https://eclipse.dev/elk/)

*If this is useful to you, a star helps others find it.*

Interactive schema visualization for Django projects.

See all your models, fields, and relationships as an interactive, force-directed graph — directly in your browser. Zero Node.js required at runtime.

## Features

- Export/Import view state as a PNG with location/canvas placement data.
- Export/Import view state as JSON
- Clean JSON API endpoint (`GET /schema/api/`)
- Force-directed layout with physics settle animation (drag-to-pin support)
- Hierarchical layout via dagre
- Click to expand/collapse field lists per model
- App-based color coding
- Show/hide models and apps via sidebar
- Django 5.x + Python 3.12+ only

## Live Demo
- [Live Demo](https://jeffield.net/schema/)

## Visualize

<img width="800" height="450" alt="output" src="https://github.com/user-attachments/assets/f93c55d0-5e25-4e8e-8581-e281c4ed91e6" />


## Frontend Stack

| Aspect | Technology |
|---|---|
| Framework | React 18 |
| Language | TypeScript |
| Graph Visualization | React Flow (`@xyflow/react` 12) |
| Layout Engines | d3-force + dagre + ELK (3 options) |
| UI / Styling | TailwindCSS 4 |
| State Management | Zustand 5 |
| Bundler | Vite 6 |
| Type Safety | Full TypeScript |
| Testing | Vitest + ESLint |
| CDN Dependencies | None (all bundled) |
| Package Manager | npm |

## Exported PNG file with embedded config data

This is an example output PNG file, that can be re-imported into django-schematic


<img width="900" height="495" alt="schematic2-900" src="https://github.com/user-attachments/assets/4c464d60-bb10-4dda-b7f4-33a496024ad1" />


## Quick Start

```bash
pip install django-schematic
```

Add to `INSTALLED_APPS`:

```python
INSTALLED_APPS = [
    ...
    "schematic",
]
```

Add to `urls.py`:

```python
from django.urls import include, path

urlpatterns = [
    ...
    path("schema/", include("schematic.urls")),
]
```

Visit `http://localhost:8000/schema/` — your model graph will be there.

## Security

The viewer is only accessible when `DEBUG = True`. In production (`DEBUG = False`) both the HTML view and the API return 404, making the URL appear non-existent.

To expose the viewer in production behind your own auth layer, set the `visible` option to a callable:

```python
SCHEMATIC = {
    "visible": lambda request: request.user.is_staff,
}
```

## Configuration

```python
# settings.py (all optional — these are the defaults)
SCHEMATIC = {
    "visible": lambda request: settings.DEBUG,  # or any callable, or True/False
    "include_apps": [],           # empty = all apps
    "exclude_apps": ["admin", "contenttypes", "sessions", "auth"],
    "exclude_models": {},         # {"myapp": ["InternalModel"]}
    "include_abstract": False,
    "include_proxy": True,
}
```

## API

The schema is also available as JSON:

```
GET /schema/api/
GET /schema/api/?apps=myapp,otherapp
```

## Development

```bash
# Backend
pip install -e ".[dev]"
pytest

# Frontend
cd ui
npm install
npm run dev   # Vite dev server with HMR
npm run build # Outputs to schematic/static/schematic/
```

## License

MIT
