How tensormax/django-chatapp works
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 Chat views · urls.py Global routes · manage.py Django runtime · authapp/views.py Account views
Components 19
Runtime & deployment
- Container build
Dockerfile - Python dependencies
requirements.txt - Django runtime · Runs locally or under Gunicorn in production.
manage.py
Django project
- Project settings · Loads environment secrets, apps, middleware, database, and static configuration.
auth/settings.py - Global routes
auth/urls.py - Production entry
auth/wsgi.py
Account experience
- Account routes
authapp/urls.py - Account views · Handles signup, login, logout, and dashboard rendering.
authapp/views.py - Account forms
authapp/forms.py - Account templates
authapp/templates/authapp/layout.html
Chat domain & UI
- Chat routes
chatapp/urls.py - Chat API routes
chatapp/api_urls.py - Chat views · Coordinates authenticated sessions, persistence, templates, and LLM calls.
chatapp/views.py - Chat models · Defines persistent chat sessions and messages.
chatapp/models.py - Local chat storage
db.sqlite3 - OpenRouter client · Uses OPENROUTER_KEY to call the selected OpenRouter model.
chatapp/utils.py - Chat templates
chatapp/templates/chatapp/chat.html - Chat styles
chatapp/static/chatapp/css/chat.css
Other components
- OpenRouter API · Principal latency and failure boundary.
Connections 19
- 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