How sufiandev20/ai_research_assistant works
1. Overall shape
- This is a single Django application with one main domain app, Research_AI_Assistant, plus the standard project configuration (manage.py, project settings.py, urls.py, asgi.py, wsgi.py).
- The system is centered on academic paper search, paper summarization, and model-performance monitoring.
2. Primary request path
- User interaction starts in the Django views and template-based frontend.
- The frontend issues requests to backend endpoints for paper search, paper details, summarization, and performance stats.
- Responses are rendered either as HTML pages or API payloads for the JavaScript-driven interface.
3. Presentation layer
- templates/index.html is the main UI shell, backed by static/scripts.js and static/styles.css.
- The UI is not just static search: it supports interactive browsing, filters, loading more results, and a chat-like research response view.
- The admin-side template templates/admin/performance_dashboard.html is a separate monitoring surface.
4. Web/API layer
- views.py contains the user-facing application endpoints.
- views_performance.py exposes the monitoring and analytics endpoints for model health and comparison.
- serializers.py indicates DRF-style structured API responses for key objects.
5. Core service boundary
- Business logic is pushed into services/, which is the main architectural boundary in the repo.
- openalex_service.py handles paper and author lookup against OpenAlex.
- openrouter_service.py handles LLM calls for summaries and question answering.
- prompt_builder.py constructs prompts for the LLM layer.
- extract_service.py and pdf_service.py support document extraction / PDF-based answering.
- performance_tracker.py is the cross-cutting service for model scoring, logging, and fallback selection.
6. External integrations
- OpenAlex is the academic metadata source: search, author lookup, citations, abstracts, concepts, and publication data.
- OpenRouter is the LLM provider: the app uses free models with fallback logic rather than a single fixed model.
- These are the two key external system boundaries, and most backend complexity exists around making them reliable.
7. Persistence and domain data
- The database stores model-tracking and request-history data, not just user content.
- Migration names suggest entities such as QueryLog, ModelPerformance, ModelReliability, ResponseLog, and PaperPDF.
- This means the app keeps both operational telemetry and paper-related artifacts for later analysis and admin visibility.
8. Performance intelligence subsystem
- A major subsystem is the model-monitoring pipeline: every OpenRouter call is tracked for success, latency, failures, and format compliance.
- Reliability scoring drives model selection order, so the app dynamically chooses the best-performing model rather than hardcoding one.
- Circuit-breaker behavior is part of the design: repeatedly failing models are automatically demoted or disabled.
9. Admin and observability
- The performance dashboard is a first-class feature, accessible through Django admin at a dedicated dashboard route.
- It shows model tiers, recent activity, response logs, error patterns, and format-compliance metrics.
- This makes observability part of the product architecture, not an external ops concern.
10. Initialization and maintenance
- management/commands/initialize_models.py seeds or prepares the performance-tracking model records.
- This command is important because the monitoring layer depends on preconfigured model metadata and tiers.
- The repo also includes performance/consistency test scripts at the top level, showing that model behavior is actively validated outside the web app.
11. Document/PDF flow
- The repository supports answering questions from PDFs via extraction services.
- The likely flow is: uploaded or referenced PDF → text extraction → prompt building → LLM answer generation → optional persistence/logging.
- This is a separate ingest-and-answer path from the OpenAlex paper-search path.
12. Architecture summary for a diagram
- Draw the system as four main zones: browser/UI, Django web layer, service layer, and external APIs.
- Add a parallel persistence/monitoring lane for logs, model stats, and PDF/artifact records.
- The most important arrows are: UI → views → services → OpenAlex/OpenRouter, and services → database for telemetry and model performance.
Main entry points: views.py App Views · views_performance.py Perf Views · models.py Domain Models · pdf_service.py PDF Service
Components 20
UI / Templates
Browser-facing interface and static assets
- Main UI · Primary search and research experience
Research_Assistant/Research_AI_Assistant/templates/index.html - Frontend JS · Interactive search, filters, loading, and chat-like updates
Research_Assistant/Research_AI_Assistant/templates/static/scripts.js - Styles · Presentation styling for the UI shell
Research_Assistant/Research_AI_Assistant/templates/static/styles.css
Django Web
Project wiring and request handlers
- App Views · User-facing endpoints for search, details, and summarization
Research_Assistant/Research_AI_Assistant/views.py - Perf Views · Analytics and model-health endpoints
Research_Assistant/Research_AI_Assistant/views_performance.py - App Routes · Request routing for the Django app
Research_Assistant/Research_AI_Assistant/urls.py - Project Settings · Django configuration and installed components
Research_Assistant/Research_AI_Assistant/settings.py - Project URLs · Top-level URL wiring for the project
Research_Assistant/Research_Assistant/urls.py
Core Services
Domain logic and external integration boundary
- OpenAlex · Paper, author, citation, abstract, and concept lookup
Research_Assistant/Research_AI_Assistant/services/openalex_service.py - OpenRouter · LLM calls for summaries and question answering
Research_Assistant/Research_AI_Assistant/services/openrouter_service.py - Prompt Builder · Constructs prompts for model calls
Research_Assistant/Research_AI_Assistant/services/prompt_builder.py - Extract Service · Text extraction support for document-based answering
Research_Assistant/Research_AI_Assistant/services/extract_service.py - PDF Service · PDF ingest and answering workflow
Research_Assistant/Research_AI_Assistant/services/pdf_service.py - Perf Tracker · Scoring, logging, reliability, and fallback selection
Research_Assistant/Research_AI_Assistant/services/performance_tracker.py
Data / Tracking
Models, migrations, and persistence for telemetry
- Domain Models · Query logs, model performance, reliability, response logs, and paper PDFs
Research_Assistant/Research_AI_Assistant/models.py - Migrations · Database evolution for telemetry and paper artifacts
Research_Assistant/Research_AI_Assistant/migrations/0001_initial.py - Serializers · Structured API response objects
Research_Assistant/Research_AI_Assistant/serializers.py
Admin / Ops
Monitoring dashboard and maintenance command
- Perf Dashboard · Monitoring dashboard surface in admin
Research_Assistant/Research_AI_Assistant/templates/admin/performance_dashboard.html - Init Models · Seeds or prepares model-tracking records
Research_Assistant/Research_AI_Assistant/management/commands/initialize_models.py - Admin Hooks · Admin registration and dashboard integration
Research_Assistant/Research_AI_Assistant/admin.py
Connections 24
- Frontend JS → App Views: search / fetch · Frontend requests drive paper browsing and research actions
- Frontend JS → Perf Views: metrics UI · Dashboard interactions request model-health data
- Main UI → Frontend JS: loads · Main UI shell is powered by client-side behavior
- Main UI → Styles: styles · Presentation layer styling
- App Views → OpenAlex: paper search · User queries are resolved against OpenAlex metadata
- App Views → Prompt Builder: build prompt · Research responses and summaries are prepared for the LLM
- App Views → OpenRouter: answer / summarize · LLM-backed generation for research responses
- App Views → PDF Service: pdf flow · Document-based question answering path
- PDF Service → Extract Service: extract text · PDF content is normalized before prompting
- PDF Service → Prompt Builder: construct prompt · Extracted text is turned into model input
- PDF Service → OpenRouter: generate answer · PDF answers are produced by the LLM layer
- OpenRouter → Perf Tracker: track call · Every model call is scored for latency, success, and compliance
- OpenRouter → Domain Models: persist telemetry · Performance and reliability state is stored
- Perf Tracker → Domain Models: update stats · Reliability scores and circuit-breaker state are maintained
- Perf Views → Domain Models: read stats · Monitoring endpoints surface tracked metrics
- Perf Views → Serializers: format payload · Analytics responses are structured for the UI
- Perf Dashboard → Perf Views: renders data · Admin dashboard consumes monitoring endpoints
- Init Models → Domain Models: seed records · Initial model metadata and tiers are prepared
- Admin Hooks → Perf Dashboard: register dashboard · Admin integration exposes the performance surface
- App Routes → App Views: route app · Application URLs map to user-facing handlers
- App Routes → Perf Views: route monitoring · Separate route set exposes performance endpoints
- Project URLs → App Routes: include app · Project-level URL configuration includes the app routes
- Project Settings → App Views: enable app · Project configuration activates the Django app
- Migrations → Domain Models: shape schema · Database schema reflects the tracked domain entities