# sufiandev20/ai_research_assistant architecture

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

- Interactive diagram: https://gitdiagram.com/sufiandev20/ai_research_assistant
- Repository: https://github.com/sufiandev20/ai_research_assistant

## Overview

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: [`Research_Assistant/Research_AI_Assistant/views.py`](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/views.py) (App Views), [`Research_Assistant/Research_AI_Assistant/views_performance.py`](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/views_performance.py) (Perf Views), [`Research_Assistant/Research_AI_Assistant/models.py`](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/models.py) (Domain Models), [`Research_Assistant/Research_AI_Assistant/services/pdf_service.py`](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/pdf_service.py) (PDF Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_ui["UI / Templates"]
  node_node_index_template["Main UI<br/>template<br/>[index.html]"]
  node_node_scripts["Frontend JS<br/>browser script<br/>[scripts.js]"]
  node_node_styles["Styles<br/>css<br/>[styles.css]"]
end

subgraph group_group_web["Django Web"]
  node_node_views["App Views<br/>django views<br/>[views.py]"]
  node_node_perf_views["Perf Views<br/>monitoring views"]
  node_node_urls["App Routes<br/>urlconf<br/>[urls.py]"]
  node_node_settings["Project Settings<br/>django config<br/>[settings.py]"]
  node_node_project_urls["Project URLs<br/>project urlconf<br/>[urls.py]"]
end

subgraph group_group_services["Core Services"]
  node_node_openalex["OpenAlex<br/>metadata service"]
  node_node_openrouter["OpenRouter<br/>llm service"]
  node_node_prompt_builder["Prompt Builder<br/>prompting<br/>[prompt_builder.py]"]
  node_node_extract["Extract Service<br/>document extraction<br/>[extract_service.py]"]
  node_node_pdf["PDF Service<br/>pdf pipeline<br/>[pdf_service.py]"]
  node_node_tracker["Perf Tracker<br/>model monitoring"]
end

subgraph group_group_data["Data / Tracking"]
  node_node_models[("Domain Models<br/>django models<br/>[models.py]")]
  node_node_migrations["Migrations<br/>schema history<br/>[0001_initial.py]"]
  node_node_serializer["Serializers<br/>api serialization<br/>[serializers.py]"]
end

subgraph group_group_ops["Admin / Ops"]
  node_node_admin_template["Perf Dashboard<br/>admin template"]
  node_node_init_models["Init Models<br/>management command"]
  node_node_admin_py["Admin Hooks<br/>admin config<br/>[admin.py]"]
end

node_node_scripts -->|"search / fetch"| node_node_views
node_node_scripts -->|"metrics UI"| node_node_perf_views
node_node_index_template -->|"loads"| node_node_scripts
node_node_index_template -->|"styles"| node_node_styles
node_node_views -->|"paper search"| node_node_openalex
node_node_views -->|"build prompt"| node_node_prompt_builder
node_node_views -->|"answer / summarize"| node_node_openrouter
node_node_views -->|"pdf flow"| node_node_pdf
node_node_pdf -->|"extract text"| node_node_extract
node_node_pdf -->|"construct prompt"| node_node_prompt_builder
node_node_pdf -->|"generate answer"| node_node_openrouter
node_node_openrouter -->|"track call"| node_node_tracker
node_node_openrouter -->|"persist telemetry"| node_node_models
node_node_tracker -->|"update stats"| node_node_models
node_node_perf_views -->|"read stats"| node_node_models
node_node_perf_views -->|"format payload"| node_node_serializer
node_node_admin_template -->|"renders data"| node_node_perf_views
node_node_init_models -->|"seed records"| node_node_models
node_node_admin_py -->|"register dashboard"| node_node_admin_template
node_node_urls -->|"route app"| node_node_views
node_node_urls -->|"route monitoring"| node_node_perf_views
node_node_project_urls -->|"include app"| node_node_urls
node_node_settings -->|"enable app"| node_node_views
node_node_migrations -->|"shape schema"| node_node_models

click node_node_index_template "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/templates/index.html"
click node_node_scripts "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/templates/static/scripts.js"
click node_node_styles "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/templates/static/styles.css"
click node_node_views "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/views.py"
click node_node_perf_views "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/views_performance.py"
click node_node_urls "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/urls.py"
click node_node_settings "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/settings.py"
click node_node_project_urls "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_Assistant/urls.py"
click node_node_openalex "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/openalex_service.py"
click node_node_openrouter "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/openrouter_service.py"
click node_node_prompt_builder "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/prompt_builder.py"
click node_node_extract "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/extract_service.py"
click node_node_pdf "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/pdf_service.py"
click node_node_tracker "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/performance_tracker.py"
click node_node_models "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/models.py"
click node_node_migrations "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/migrations/0001_initial.py"
click node_node_serializer "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/serializers.py"
click node_node_admin_template "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/templates/admin/performance_dashboard.html"
click node_node_init_models "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/management/commands/initialize_models.py"
click node_node_admin_py "https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/admin.py"

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_node_index_template,node_node_scripts,node_node_styles toneBlue
class node_node_views,node_node_perf_views,node_node_urls,node_node_settings,node_node_project_urls toneAmber
class node_node_openalex,node_node_openrouter,node_node_prompt_builder,node_node_extract,node_node_pdf,node_node_tracker toneMint
class node_node_models,node_node_migrations,node_node_serializer toneRose
class node_node_admin_template,node_node_init_models,node_node_admin_py toneIndigo
```

## Components

### UI / Templates

Browser-facing interface and static assets

- [Main UI](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/templates/index.html): template · Primary search and research experience · `Research_Assistant/Research_AI_Assistant/templates/index.html`
- [Frontend JS](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/templates/static/scripts.js): browser script · Interactive search, filters, loading, and chat-like updates · `Research_Assistant/Research_AI_Assistant/templates/static/scripts.js`
- [Styles](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/templates/static/styles.css): css · Presentation styling for the UI shell · `Research_Assistant/Research_AI_Assistant/templates/static/styles.css`

### Django Web

Project wiring and request handlers

- [App Views](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/views.py): django views · User-facing endpoints for search, details, and summarization · `Research_Assistant/Research_AI_Assistant/views.py`
- [Perf Views](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/views_performance.py): monitoring views · Analytics and model-health endpoints · `Research_Assistant/Research_AI_Assistant/views_performance.py`
- [App Routes](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/urls.py): urlconf · Request routing for the Django app · `Research_Assistant/Research_AI_Assistant/urls.py`
- [Project Settings](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/settings.py): django config · Django configuration and installed components · `Research_Assistant/Research_AI_Assistant/settings.py`
- [Project URLs](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_Assistant/urls.py): project urlconf · Top-level URL wiring for the project · `Research_Assistant/Research_Assistant/urls.py`

### Core Services

Domain logic and external integration boundary

- [OpenAlex](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/openalex_service.py): metadata service · Paper, author, citation, abstract, and concept lookup · `Research_Assistant/Research_AI_Assistant/services/openalex_service.py`
- [OpenRouter](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/openrouter_service.py): llm service · LLM calls for summaries and question answering · `Research_Assistant/Research_AI_Assistant/services/openrouter_service.py`
- [Prompt Builder](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/prompt_builder.py): prompting · Constructs prompts for model calls · `Research_Assistant/Research_AI_Assistant/services/prompt_builder.py`
- [Extract Service](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/extract_service.py): document extraction · Text extraction support for document-based answering · `Research_Assistant/Research_AI_Assistant/services/extract_service.py`
- [PDF Service](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/pdf_service.py): pdf pipeline · PDF ingest and answering workflow · `Research_Assistant/Research_AI_Assistant/services/pdf_service.py`
- [Perf Tracker](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/services/performance_tracker.py): model monitoring · 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](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/models.py): django models · Query logs, model performance, reliability, response logs, and paper PDFs · `Research_Assistant/Research_AI_Assistant/models.py`
- [Migrations](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/migrations/0001_initial.py): schema history · Database evolution for telemetry and paper artifacts · `Research_Assistant/Research_AI_Assistant/migrations/0001_initial.py`
- [Serializers](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/serializers.py): api serialization · Structured API response objects · `Research_Assistant/Research_AI_Assistant/serializers.py`

### Admin / Ops

Monitoring dashboard and maintenance command

- [Perf Dashboard](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/templates/admin/performance_dashboard.html): admin template · Monitoring dashboard surface in admin · `Research_Assistant/Research_AI_Assistant/templates/admin/performance_dashboard.html`
- [Init Models](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/management/commands/initialize_models.py): management command · Seeds or prepares model-tracking records · `Research_Assistant/Research_AI_Assistant/management/commands/initialize_models.py`
- [Admin Hooks](https://github.com/sufiandev20/ai_research_assistant/blob/main/Research_Assistant/Research_AI_Assistant/admin.py): admin config · Admin registration and dashboard integration · `Research_Assistant/Research_AI_Assistant/admin.py`

## Connections

- 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
