# tensormax/django-chatapp architecture

> Architecture diagram of the GitHub repository tensormax/django-chatapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tensormax/django-chatapp
- Repository: https://github.com/tensormax/django-chatapp

## Overview

#### Purpose and entry points
This is a server-rendered Django AI chat application. Users authenticate, create/manage chat sessions, and submit prompts to an OpenRouter-hosted LLM. Django starts through `manage.py`; production web serving is configured around the project package in `auth/asgi.py` and `auth/wsgi.py`. Container deployment begins at `Dockerfile`.

#### Django project boundary
The `auth` package is the Django project/configuration boundary: settings, global URL dispatch, and ASGI/WSGI application definitions reside in `auth/settings.py`, `auth/urls.py`, and `auth/wsgi.py`. It owns environment-driven secrets, allowed hosts, installed applications, middleware, database/static configuration, and production integration such as WhiteNoise/Gunicorn implied by the README.

#### Authentication and user-facing account flow
`authapp` provides signup, login, logout/dashboard-oriented views and template rendering. URL routing in `authapp/urls.py` maps requests to handlers in `authapp/views.py`; form validation is separated into `authapp/forms.py`. Its pages inherit/layout through templates such as `authapp/templates/authapp/layout.html` and render account-specific screens including `dashboard.html`.

#### Chat domain and persistence
`chatapp` owns the chat data model and lifecycle. Persistent session/message structures are defined in `chatapp/models.py`, with schema history in `chatapp/migrations/0001_initial.py` and `chatapp/migrations/0002_chatsession_updated_at_alter_chatsession_title_and_more.py`. The SQLite database (`db.sqlite3`) supports local persistence; Django ORM mediates views and models rather than exposing storage directly to templates.

#### Chat request and LLM-response pipeline
Chat UI requests enter through `chatapp/urls.py` and API-oriented routes in `chatapp/api_urls.py`, then are handled by `chatapp/views.py`. The view layer coordinates authenticated user/session state, persisted conversation records, and the OpenRouter request boundary. `chatapp/utils.py` isolates LLM API-call logic, using the `OPENROUTER_KEY` environment variable; model selection is described as OpenRouter’s `amazon/nova-2-lite-v1:free`. This external call is the principal latency/failure boundary.

#### Presentation layer
The application is HTML/CSS, Django-template driven rather than a separate frontend runtime. Chat templates live at `chatapp/templates/chatapp/base.html` and `chatapp/templates/chatapp/chat.html`; account templates live under `authapp/templates/authapp/`. App-owned styles are in `chatapp/static/chatapp/css/chat.css` and `authapp/static/authapp/css/auth.css`, with collected deployable assets under `staticfiles/`.

#### Runtime and deployment
Local development uses Django with environment variables for `DEBUG`, `DJANGO_SECRET`, `OPENROUTER_KEY`, and `ALLOWED_HOSTS`. Production is intended for Render, served by Gunicorn and with static assets handled by WhiteNoise. `Dockerfile` defines the container boundary, while `requirements.txt` fixes Python/Django and integration dependencies. The application’s external infrastructure dependencies are the OpenRouter API and Render-hosted process/runtime; SQLite is repository-local unless replaced through Django settings.

Main entry points: [`chatapp/views.py`](https://github.com/tensormax/django-chatapp/blob/main/chatapp/views.py) (Chat views), [`auth/urls.py`](https://github.com/tensormax/django-chatapp/blob/main/auth/urls.py) (Global routes), [`manage.py`](https://github.com/tensormax/django-chatapp/blob/main/manage.py) (Django runtime), [`authapp/views.py`](https://github.com/tensormax/django-chatapp/blob/main/authapp/views.py) (Account views)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime & deployment"]
  node_docker["Container build<br/>Docker"]
  node_dependencies["Python dependencies<br/>[requirements.txt]"]
  node_django{{"Django runtime<br/>Web runtime<br/>[manage.py]"}}
end

subgraph group_project["Django project"]
  node_settings["Project settings<br/>Django config<br/>[settings.py]"]
  node_root_urls["Global routes<br/>URL dispatcher<br/>[urls.py]"]
  node_production_entry["Production entry<br/>WSGI app<br/>[wsgi.py]"]
end

subgraph group_accounts["Account experience"]
  node_account_routes["Account routes<br/>URL routes<br/>[urls.py]"]
  node_account_views["Account views<br/>Django views<br/>[views.py]"]
  node_account_forms["Account forms<br/>Validation<br/>[forms.py]"]
  node_account_templates["Account templates<br/>Django templates<br/>[layout.html]"]
end

subgraph group_chat["Chat domain & UI"]
  node_chat_routes["Chat routes<br/>URL routes<br/>[urls.py]"]
  node_chat_api_routes["Chat API routes<br/>[api_urls.py]"]
  node_chat_views["Chat views<br/>Request orchestration<br/>[views.py]"]
  node_chat_models[("Chat models<br/>Django ORM models<br/>[models.py]")]
  node_sqlite[("Local chat storage<br/>SQLite database<br/>[db.sqlite3]")]
  node_llm_client{{"OpenRouter client<br/>LLM gateway<br/>[utils.py]"}}
  node_chat_templates["Chat templates<br/>Django templates<br/>[chat.html]"]
  node_chat_styles["Chat styles<br/>Static CSS<br/>[chat.css]"]
end

node_openrouter{{"OpenRouter API<br/>External LLM"}}

node_docker -->|"runs"| node_django
node_dependencies -->|"provides"| node_django
node_django -->|"loads"| node_settings
node_django -->|"serves via"| node_production_entry
node_settings -->|"configures"| node_root_urls
node_root_urls -->|"dispatches"| node_account_routes
node_root_urls -->|"dispatches"| node_chat_routes
node_root_urls -->|"dispatches"| node_chat_api_routes
node_account_routes -->|"maps to"| node_account_views
node_account_views -->|"validates with"| node_account_forms
node_account_views -->|"renders"| node_account_templates
node_chat_routes -->|"maps to"| node_chat_views
node_chat_api_routes -->|"maps to"| node_chat_views
node_chat_views -->|"reads and writes"| node_chat_models
node_chat_models -->|"persists to"| node_sqlite
node_chat_views -->|"submits prompts"| node_llm_client
node_llm_client -->|"API request"| node_openrouter
node_chat_views -->|"renders"| node_chat_templates
node_chat_templates -->|"uses"| node_chat_styles

click node_docker "https://github.com/tensormax/django-chatapp/tree/main/Dockerfile"
click node_dependencies "https://github.com/tensormax/django-chatapp/blob/main/requirements.txt"
click node_django "https://github.com/tensormax/django-chatapp/blob/main/manage.py"
click node_settings "https://github.com/tensormax/django-chatapp/blob/main/auth/settings.py"
click node_root_urls "https://github.com/tensormax/django-chatapp/blob/main/auth/urls.py"
click node_production_entry "https://github.com/tensormax/django-chatapp/blob/main/auth/wsgi.py"
click node_account_routes "https://github.com/tensormax/django-chatapp/blob/main/authapp/urls.py"
click node_account_views "https://github.com/tensormax/django-chatapp/blob/main/authapp/views.py"
click node_account_forms "https://github.com/tensormax/django-chatapp/blob/main/authapp/forms.py"
click node_account_templates "https://github.com/tensormax/django-chatapp/blob/main/authapp/templates/authapp/layout.html"
click node_chat_routes "https://github.com/tensormax/django-chatapp/blob/main/chatapp/urls.py"
click node_chat_api_routes "https://github.com/tensormax/django-chatapp/blob/main/chatapp/api_urls.py"
click node_chat_views "https://github.com/tensormax/django-chatapp/blob/main/chatapp/views.py"
click node_chat_models "https://github.com/tensormax/django-chatapp/blob/main/chatapp/models.py"
click node_sqlite "https://github.com/tensormax/django-chatapp/blob/main/db.sqlite3"
click node_llm_client "https://github.com/tensormax/django-chatapp/blob/main/chatapp/utils.py"
click node_chat_templates "https://github.com/tensormax/django-chatapp/blob/main/chatapp/templates/chatapp/chat.html"
click node_chat_styles "https://github.com/tensormax/django-chatapp/blob/main/chatapp/static/chatapp/css/chat.css"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_docker,node_dependencies,node_django toneBlue
class node_settings,node_root_urls,node_production_entry toneAmber
class node_account_routes,node_account_views,node_account_forms,node_account_templates toneMint
class node_chat_routes,node_chat_api_routes,node_chat_views,node_chat_models,node_sqlite,node_llm_client,node_chat_templates,node_chat_styles toneRose
class node_openrouter toneNeutral
```

## Components

### Runtime & deployment

- [Container build](https://github.com/tensormax/django-chatapp/tree/main/Dockerfile): Docker · `Dockerfile`
- [Python dependencies](https://github.com/tensormax/django-chatapp/blob/main/requirements.txt): Dependencies · `requirements.txt`
- [Django runtime](https://github.com/tensormax/django-chatapp/blob/main/manage.py): Web runtime · Runs locally or under Gunicorn in production. · `manage.py`

### Django project

- [Project settings](https://github.com/tensormax/django-chatapp/blob/main/auth/settings.py): Django config · Loads environment secrets, apps, middleware, database, and static configuration. · `auth/settings.py`
- [Global routes](https://github.com/tensormax/django-chatapp/blob/main/auth/urls.py): URL dispatcher · `auth/urls.py`
- [Production entry](https://github.com/tensormax/django-chatapp/blob/main/auth/wsgi.py): WSGI app · `auth/wsgi.py`

### Account experience

- [Account routes](https://github.com/tensormax/django-chatapp/blob/main/authapp/urls.py): URL routes · `authapp/urls.py`
- [Account views](https://github.com/tensormax/django-chatapp/blob/main/authapp/views.py): Django views · Handles signup, login, logout, and dashboard rendering. · `authapp/views.py`
- [Account forms](https://github.com/tensormax/django-chatapp/blob/main/authapp/forms.py): Validation · `authapp/forms.py`
- [Account templates](https://github.com/tensormax/django-chatapp/blob/main/authapp/templates/authapp/layout.html): Django templates · `authapp/templates/authapp/layout.html`

### Chat domain & UI

- [Chat routes](https://github.com/tensormax/django-chatapp/blob/main/chatapp/urls.py): URL routes · `chatapp/urls.py`
- [Chat API routes](https://github.com/tensormax/django-chatapp/blob/main/chatapp/api_urls.py): API routes · `chatapp/api_urls.py`
- [Chat views](https://github.com/tensormax/django-chatapp/blob/main/chatapp/views.py): Request orchestration · Coordinates authenticated sessions, persistence, templates, and LLM calls. · `chatapp/views.py`
- [Chat models](https://github.com/tensormax/django-chatapp/blob/main/chatapp/models.py): Django ORM models · Defines persistent chat sessions and messages. · `chatapp/models.py`
- [Local chat storage](https://github.com/tensormax/django-chatapp/blob/main/db.sqlite3): SQLite database · `db.sqlite3`
- [OpenRouter client](https://github.com/tensormax/django-chatapp/blob/main/chatapp/utils.py): LLM gateway · Uses OPENROUTER_KEY to call the selected OpenRouter model. · `chatapp/utils.py`
- [Chat templates](https://github.com/tensormax/django-chatapp/blob/main/chatapp/templates/chatapp/chat.html): Django templates · `chatapp/templates/chatapp/chat.html`
- [Chat styles](https://github.com/tensormax/django-chatapp/blob/main/chatapp/static/chatapp/css/chat.css): Static CSS · `chatapp/static/chatapp/css/chat.css`

### Other components

- **OpenRouter API**: External LLM · Principal latency and failure boundary.

## Connections

- Container build → Django runtime: runs
- Python dependencies → Django runtime: provides
- Django runtime → Project settings: loads
- Django runtime → Production entry: serves via
- Project settings → Global routes: configures
- Global routes → Account routes: dispatches
- Global routes → Chat routes: dispatches
- Global routes → Chat API routes: dispatches
- Account routes → Account views: maps to
- Account views → Account forms: validates with
- Account views → Account templates: renders
- Chat routes → Chat views: maps to
- Chat API routes → Chat views: maps to
- Chat views → Chat models: reads and writes
- Chat models → Local chat storage: persists to
- Chat views → OpenRouter client: submits prompts
- OpenRouter client → OpenRouter API: API request
- Chat views → Chat templates: renders
- Chat templates → Chat styles: uses
