Application operations
CourtListener runs as a Django application with separate web, task, data, and support services. A shared settings layer connects these services to PostgreSQL, Redis, Elasticsearch, object storage, document-processing services, and external support systems. Container commands choose the runtime role for each process.
Runtime composition
The runtime composition separates user-facing requests from background work and supporting data services. Django provides the application boundary, while PostgreSQL stores core data, Redis supports cache and task transport, Elasticsearch supports search, and external services handle selected document, disclosure, and support work.
The main runtime roles are:
| Role | Responsibility |
|---|---|
| Web process | Accepts HTTP requests through the ASGI application and maps them to Django app routes. |
| Task worker | Runs queued background work through Celery. |
| Database services | Provide PostgreSQL data and optional read replicas. |
| Search service | Provides Elasticsearch indexes and search queries. |
| Support services | Provide Redis, browser automation, document extraction, disclosure extraction, and external support tools. |
The web and worker roles use the same Django settings. This keeps database, cache, search, storage, and service endpoint choices consistent across synchronous and asynchronous work.
The runtime relationship is shown below.
flowchart LR
Client[HTTP client] --> Web[Django web process]
Web --> DB[(PostgreSQL)]
Web --> Cache[(Redis)]
Web --> Search[(Elasticsearch)]
Web --> Storage[(Object storage)]
Web --> Queue[(Redis task broker)]
Queue --> Worker[Celery worker]
Worker --> DB
Worker --> Search
Worker --> Storage
Worker --> Services[Document, disclosure, and support services]
References: cl/…/__init__.py• L1-28 cl/…/django.py• L16-31 cl/…/django.py• L72-83 cl/…/django.py• L169-248 cl/…/redis.py• L11-46 cl/…/aws.py• L7-31 cl/…/elasticsearch.py• L40-75
Configuration assembly
The settings package assembles Django defaults with project and third-party settings into one runtime configuration. Environment values select service hosts, credentials, storage targets, feature switches, external integration settings, and development or production behavior without changing the application entry points.
Django starts from DJANGO_SETTINGS_MODULE=cl.settings. The package then imports settings for the application, external services, security, search, queues, storage, APIs, and testing. This gives every process a common view of the system while allowing each environment to supply different values.
The configuration has several important effects:
- PostgreSQL is the primary data store. Optional replica connections support read paths and API routing.
- Redis has separate logical databases for task transport, cache, statistics, and alerts. Redis clients retry transient failures with exponential backoff and run health checks.
- Development changes process behavior. For example, it uses local static files and eager Celery tasks, while production uses production storage and a separate worker process.
- Elasticsearch settings control search availability, index updates, alert percolation, request time limits, and index capacity. Test settings disable direct Elasticsearch use and set signal behavior for isolated runs.
- The API settings define supported versions, access checks, request limits, and response paging. This gives web clients a stable boundary over the application data.
- Authentication settings keep CourtListener's account flows separate from single sign-on (SSO). Allauth supplies SSO through OpenID Connect and SAML, while CourtListener keeps control of sign-in, registration, email confirmation, password reset, and identity-linking policy.
- Logging sends application and server messages to the process output. It limits repeated unreadable request errors through the cache, while development adds SQL and verbose output.
- Settings also provide credentials and limits for court data sources, analytics, cloud assets, webhooks, OCR, and other external operations.
- Sentry is optional. When a DSN is present, it observes Django, Celery, Redis, and asynchronous work so errors from web and worker processes use one reporting path.
- Alert settings bound scheduled-hit database writes and keep selected SCOTUS webhook paths disabled until their data and API contracts are ready.
The SSO policy adds a separate control for staff access. When enabled, staff and superusers must use the staff organization's identity provider, and existing sessions are checked again at a fixed interval. This policy must be enabled only after the required staff identities are linked.
References: manage.py• L6-11 cl/…/__init__.py• L1-28 cl/…/django.py• L16-67 cl/…/django.py• L85-119 cl/…/allauth.py• L7-65 cl/…/misc.py• L8-15 cl/…/misc.py• L19-48 cl/…/misc.py• L81-115 cl/…/alerts.py• L7-26 cl/…/logging.py• L12-27 cl/…/logging.py• L30-101 cl/…/testing.py• L13-21 cl/…/celery.py• L32-67 cl/…/elasticsearch.py• L7-38 cl/…/redis.py• L11-46 cl/…/rest_framework.py• L13-85 cl/…/sentry.py• L9-58
Request routing
The URL configuration is the public map from HTTP paths to Django applications. It combines routes from domain apps under the site root and adds shared concerns such as administration, APIs, sitemaps, redirects, media, and development-only tools.
Requests enter through cl.asgi.application and then pass through Django middleware before URL matching. The middleware layer provides security, sessions, authentication, rate limits, replica routing, feature flags, history, and metrics. The root URL map delegates domain behavior to the relevant Django app instead of owning that behavior itself.
The API is a versioned interface for clients that need structured access to CourtListener data. It permits anonymous read access where the model rules allow it, requires an approved authentication path for protected actions, and applies limits that vary by client and operation. Version-specific pagination and response formats help clients consume large result sets without coupling them to internal page behavior.
The SSO routes are part of the authentication boundary. They hand identity-provider sign-in to the SSO application, which applies the configured account and organization policy instead of treating an identity-provider email match as automatic account linking.
Sitemaps are part of the public routing surface. Their index and section URLs use cached responses from the database-backed cache, with keys that distinguish the sitemap section and page. The endpoint also applies a rate limit and a robots header, and it can return Last-Modified so unchanged pages use a 304 Not Modified response.
References: cl/asgi.py• L1-7 cl/…/django.py• L146-172 cl/…/logging.py• L30-91 cl/…/allauth.py• L34-65 cl/…/rest_framework.py• L13-85 cl/urls.py• L21-31 cl/urls.py• L33-75 cl/urls.py• L109-118 cl/sitemap.py• L18-125
Asynchronous execution
Asynchronous execution moves slow or repeatable work out of the web request path. Celery uses Redis as both its broker and result store, discovers tasks from Django apps, and sends work to named queues so workers can be assigned to suitable workloads.
The worker command starts a prefork Celery worker. It listens to the configured queue set and applies the deployment's concurrency and prefetch limits. Development runs tasks eagerly for simpler local use and tests, while production uses separate worker processes with longer task visibility and result retention settings.
For the detailed worker model and task flow, see runtime-and-workers.
References: cl/celery_init.py• L8-20 cl/…/celery.py• L7-30 cl/…/celery.py• L32-67 cl/…/redis.py• L18-46 docker/…/docker-entrypoint.sh• L4-14 cl/…/testing.py• L13-21
Service integration
The application calls selected capabilities through configured service endpoints instead of placing all processing in the Django process. The service map gives each capability a stable name, target URL, and time limit, which lets request and task code use the same contract in each environment.
The configured services cover document extraction, OCR, file and audio utilities, conversion, disclosure extraction, and embedding operations. Zoho provides an external path for customer support and CRM work, with issue types mapped to support agents. Default hosts match the local container network or a host-side service, while environment values can redirect them for other deployments.
References: cl/…/microservices.py• L1-23 cl/…/microservices.py• L25-115 cl/…/zoho.py• L12-46 docker/…/docker-compose.yml• L121-150 docker/…/docker-compose.yml• L233-243
Container deployment
The container image packages the Python environment, front-end assets, and Django application into one reusable image. The entrypoint selects the process role at startup, so the same image can serve web traffic, run Celery, or execute a named maintenance daemon.
The development Compose stack supplies the local service graph. It waits for PostgreSQL, Redis, Elasticsearch, and the required support services before starting Django, while health checks distinguish a running container from a service that is ready for use. The Django development role applies migrations and creates the cache table before serving requests.
Production web processes run Gunicorn with an ASGI worker. The worker settings allow multiple processes, request time limits, and periodic worker replacement so long-running service processes can be recycled without changing the application contract.
References: docker/…/Dockerfile• L1-21 docker/…/Dockerfile• L34-81 docker/…/docker-entrypoint.sh• L16-37 docker/…/docker-compose.yml• L41-59 docker/…/docker-compose.yml• L121-219 compose.yaml• L1-16
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the ASGI application path, Gunicorn worker class, and web container command aligned. A change in one can leave the web image unable to start.
- Keep Celery queue names aligned between task routing settings and worker startup. A queue that is configured but not consumed can silently accumulate work.
- Keep service host names aligned between environment defaults and Compose service names. Container networking depends on these stable names.
- Keep Redis logical database assignments stable across cache, task, statistics, and alert clients. Reuse of a database can mix unrelated data.
- Keep Redis retry and health-check settings within the failure and load limits of the shared service. A change can affect both request paths and workers.
- Keep health-check dependencies aligned with startup actions. Django migration and cache setup need ready PostgreSQL and Redis, not only started containers.
- Keep static storage mode aligned with the deployment mode. Production assets use the manifest-backed storage path, while development and tests use local static storage.
- Keep API version, authentication, throttle, and pagination settings aligned with client contracts. A default or limit change can affect clients without changing a route.
- Keep allauth's SSO-only settings aligned with CourtListener's account and email rules. Enabling allauth account flows or automatic identity linking can change sign-in and account ownership behavior.
- Keep staff SSO enforcement aligned with linked staff identities and the session recheck interval. Enabling enforcement too early can block staff access.
- Keep logging filters that use Redis on the cache database. A cache key or database change can alter which request errors reach operations staff.
- Keep Elasticsearch availability and signal switches aligned with the process role. Disabling the service or its update signals changes search freshness and alert behavior.
- Keep alert-hit batch limits within the database and worker memory budget. A larger batch changes the peak cost of scheduled-alert processing.
- Keep SCOTUS webhook enablement behind the data and API prerequisites that its setting documents. Email alerts do not use this switch.
- Keep sitemap cache keys aligned with the request values that affect the response. Cache changes must also preserve rate-limit and conditional-response behavior.
- Keep Zoho credentials, timeouts, organization identifiers, and issue-type agent mappings aligned with the support workflow. A missing mapping can route a ticket to the wrong support path.
- Keep Sentry's DSN and integration scope aligned across web and worker processes. An unset DSN disables error reporting without changing request or task execution.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A required PostgreSQL, Redis, or Elasticsearch service is not ready | Django startup, migrations, search, or queued work fails or remains unavailable | Compose health checks and dependency conditions gate service startup. |
| A Celery queue name differs between task routing and worker startup | Tasks remain pending even though the worker is healthy | Keep the queue settings and CELERY_QUEUES worker list in sync. |
| A service host points to a name outside the container network | Extraction, disclosure, or embedding tasks time out | Use the Compose service name or an environment override that is reachable from the process. |
| Production static storage is not configured for the built assets | Static files can be missing or served from the wrong location | Preserve the production static storage selection and manifest build step. |
| A task visibility timeout is shorter than its countdown | Redis can make the same task visible again before its scheduled run | Keep the broker visibility timeout longer than the largest task delay. |
| Redis retry settings do not cover transient service failures | Short Redis outages can fail requests, task transport, or log filtering | Keep client retry, backoff, and health-check settings aligned with Redis service behavior. |
| Scheduled alert hits are written with a batch that is too large | A worker can use excessive memory while the database builds the insert | Keep SCHEDULED_ALERT_HIT_BATCH_SIZE within the configured memory budget. |
| Elasticsearch is disabled or its update signals are disabled for a live role | Search indexes or search alerts can become stale without an obvious web error | Match Elasticsearch switches to the role and the data that it must keep current. |
| An API client uses an unsupported version or exceeds its operation limit | The request is rejected or throttled even when the route exists | Keep client use within the allowed API versions and throttle contract. |
| Allauth email login, verification, or automatic account linking is enabled | SSO can compete with CourtListener's account rules or attach an identity to the wrong account | Keep allauth limited to SSO and enforce linking through the CourtListener SSO policy. |
| Staff SSO enforcement starts before staff identities are linked | Staff and superusers can lose access to their accounts | Link every required staff identity before enabling the policy. |
| A sitemap cache key omits a request value that changes its page | One sitemap response can be served for another request | Preserve the section and page key contract when changing sitemap inputs. |
| Zoho credentials or support mappings are incomplete | Support or CRM work cannot be created or reaches the wrong agent | Provide the required Zoho settings and validate issue-type mappings. |
| Sentry has no DSN in a deployed process | Web and worker failures have no Sentry event | Provide the DSN where operational error reporting is required. |
Key files
| File | Why to read it |
|---|---|
| cl/…/__init__.py | Shows how the shared runtime configuration is assembled. |
| cl/…/django.py | Defines the Django application boundary and core data, cache, middleware, and app settings. |
| cl/…/allauth.py | Defines the SSO-only boundary and the staff identity policy. |
| cl/…/misc.py | Defines credentials, external operation limits, and public service links used across the application. |
| cl/…/alerts.py | Sets operational bounds for scheduled alert writes and SCOTUS alert webhooks. |
| cl/…/logging.py | Defines process logging and cache-backed filtering for repeated request errors. |
| cl/urls.py | Shows how public requests are delegated across application areas. |
| cl/asgi.py | Defines the web process entry point. |
| cl/sitemap.py | Defines the cached public sitemap response and its HTTP safeguards. |
| cl/…/celery.py | Defines the queue model and environment-specific worker behavior. |
| cl/…/elasticsearch.py | Defines search availability, index behavior, alert switches, and search capacity controls. |
| cl/…/redis.py | Defines Redis roles, retry behavior, health checks, and client connections. |
| cl/…/rest_framework.py | Defines the API version, access, rate, and response contract. |
| cl/…/sentry.py | Defines optional error reporting for web, task, cache, and asynchronous activity. |
| cl/…/zoho.py | Defines the external CRM and support service connection. |
| cl/celery_init.py | Defines Celery's Django integration and task discovery entry point. |
| cl/…/microservices.py | Maps application capabilities to external service endpoints and time limits. |
| docker/…/docker-entrypoint.sh | Shows how the image becomes a web process, worker, or maintenance process. |
| docker/…/docker-compose.yml | Describes the local service graph and readiness rules. |
docker/django/Dockerfile | Shows how the deployable application image is built. |