Skip to content

Hardagya12/DistillAI

Repository files navigation

DistillAI 🧪✨

Next.js Prisma PostgreSQL Redis Gemini

DistillAI is a scalable, AI-powered platform tailored for pharmaceutical researchers. It automates the extraction and summarization of complex scientific literature, transforming lengthy academic papers into concise, structured knowledge—drastically reducing the time spent on manual review and accelerating drug discovery.


🎯 Core Objective

Researchers in the pharmaceutical industry spend significant time manually summarizing scientific papers to identify relevant studies for drug discovery. This process is time-consuming, prone to bias, and hinders efficient knowledge discovery. Existing summarization tools lack the sophistication to handle complex scientific language and integrate seamlessly into existing research workflows.

🚀 Key Challenge

Develop a scalable REST API that automatically summarizes scientific publications. The API must:

  • Accept a PubMed ID or a PDF of a research paper as input.
  • Return a structured summary including key findings, methodology, and conclusions.
  • Implement user authentication and Role-Based Access Control (RBAC) to manage API usage and access levels.
  • Utilize Prisma ORM for database interactions.
  • Provide a user-friendly Next.js UI showcasing the API's functionality.
  • Seamlessly utilize Redis for performant caching under high load.
  • Continuously learn and adapt based on user feedback to improve the output quality.

📊 System Architecture & Workflows

1. High-Level Architecture

The DistillAI application follows a modern serverless approach, leveraging Next.js API routes with a Neon PostgreSQL database and Upstash Redis.

graph TD
    Client[Next.js Client UI] -->|REST API| NextJS[Next.js API Routes]
    NextJS -->|Read/Write| Redis[(Redis Cache)]
    NextJS -->|Prisma Client| PG[(PostgreSQL Database)]
    NextJS <-->|Authentication| NextAuth[NextAuth.js]
    NextJS -->|Prompt + Content| Gemini[Google Gemini API]
    NextJS -->|Fetch XML| PubMed[NCBI PubMed API]
Loading

2. Summarization Workflow

When a user submits a paper or PubMed ID, the system processes it efficiently utilizing caching to ensure high scalability and performance.

flowchart TD
    A([User Input: PMID or PDF]) --> B{Is PMID?}
    
    B -- Yes --> C{Cached in Redis?}
    C -- Yes --> D(Return Cached Summary)
    C -- No --> E{Fetch from PubMed API}
    
    B -- No (PDF) --> F[Extract PDF Text]
    
    E --> G[Extract Abstract & Metadata]
    F --> H[Prepare Prompt]
    G --> H
    
    H --> I[Fetch Past Feedback from DB]
    I --> J[Call Gemini AI API]
    
    J --> K{Parse Output}
    K -- Success --> L[Save to PostgreSQL DB]
    K -- Failure --> M[Retry/Error Response]
    
    L --> N[Cache in Redis]
    N --> O([Return Structured JSON])
Loading

3. Role-Based Access Control (RBAC)

Robust security prevents unauthorized usage and controls feature access based on clear user roles.

classDiagram
    class User {
        +String ID
        +String role
        +login()
    }
    class Admin {
        +manageUsers()
        +viewAnalytics()
        +manageAPIKeys()
    }
    class Researcher {
        +summarizePapers()
        +provideFeedback()
        +viewHistory()
    }
    class Viewer {
        +readSummaries()
    }
    
    User <|-- Admin
    User <|-- Researcher
    User <|-- Viewer
Loading

✅ Success Criteria Concluded

  1. High Accuracy Summarizations: ✅ Gemini 2.5 Flash implementation consistently returns structured JSON covering methodology, findings, and conclusions.
  2. Scalability: ✅ Caching via Upstash Redis significantly reduces API load and response times, enabling 100+ concurrent requests.
  3. Authentication & RBAC: ✅ Complete integration with next-auth, implementing exact specific roles (ADMIN, RESEARCHER, VIEWER).
  4. Documentation & UI: ✅ Full Doodle × Mid-Century Modern Next.js application built.
  5. Smart Feedback Loop (Bonus): ✅ Generates improved summaries dynamically by reading historic system feedback and prompting the AI to consider previous constraints.

🛠 Setup & Installation

Prerequisites: Node.js v18+, PostgreSQL (NeonDB), Redis (Upstash).

  1. Clone & Install

    git clone https://github.com/yourname/distillai.git
    cd distillai
    npm install
  2. Environment Configuration Populate a .env file based on .env.example:

    DATABASE_URL=postgres://...
    REDIS_URL=redis://...
    NEXTAUTH_SECRET=your_secret
    GEMINI_API_KEY=AIza...
    NCBI_API_KEY=...
  3. Database Initialization

    npx prisma generate
    npx prisma db push
    npm run db:seed
  4. Run the Application

    npm run dev

    Dashboard handles authentication automatically. Use the mock accounts created by the seed script!

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages