Memoriva Software Design
AI-Powered Study Assistant Architecture & Component Design
System Architecture Overview
High-Level Architecture
Loading diagram...
Frontend Architecture
Component Structure
Study Session Components
- • TipTap Rich Text Editor
- • Image Upload & Processing
- • Study Session Management
- • Progress Tracking
AI Integration Layer
- • RAG Query Interface
- • AI Response Display
- • Context Management
- • Real-time Processing
Authentication & State
- • NextAuth.js Integration
- • User Session Management
- • TanStack Query Caching
- • Optimistic Updates
State Management
// TanStack Query Structure
interface StudySessionStore {
// Session State
sessions: StudySession[]
currentSession: StudySession | null
// Processing State
isProcessing: boolean
processingStatus: ProcessingStatus
// AI State
ragResponses: RAGResponse[]
isQuerying: boolean
// Upload State
uploadProgress: number
uploadedFiles: UploadedFile[]
}
// Prisma Schema Types
interface StudySession {
id: string
title: string
content: string
userId: string
status: SessionStatus
createdAt: Date
updatedAt: Date
images: SessionImage[]
ragResults: RAGResult[]
}RAG (Retrieval-Augmented Generation) Architecture
RAG Pipeline Components
Document Processing
- • Text extraction from images
- • Content chunking strategies
- • Metadata enrichment
- • Quality filtering
Vector Embeddings
- • OpenAI text-embedding-3-small
- • Semantic similarity search
- • Vector indexing optimization
- • Embedding caching
Retrieval System
- • Similarity-based retrieval
- • Context ranking algorithms
- • Multi-modal search
- • Result relevance scoring
Generation Pipeline
- • Context injection
- • Prompt engineering
- • Response synthesis
- • Quality validation
RAG Processing Flow
Loading diagram...
Backend Architecture
Service Architecture
API Layer (Gin)
- • RESTful API endpoints
- • Authentication middleware
- • CORS configuration
- • Request validation
Queue Service
- • Concurrent job processing
- • Worker pool management
- • Job status tracking
- • Error handling & retries
RAG Service
- • Document processing pipeline
- • Vector similarity search
- • Context retrieval
- • Response generation
Storage Services
- • S3 file management
- • PostgreSQL operations
- • Vector database queries
- • Cache management
Service Integration
// Go Service Structure
type Services struct {
Database *DatabaseService
LLM *LLMService
Embedding *EmbeddingService
RAG *RAGService
S3 *S3Service
Queue *QueueService
}
type RAGService struct {
db *DatabaseService
llm *LLMService
embedding *EmbeddingService
vectorDB VectorDatabase
}
type QueueService struct {
workers int
jobs chan Job
results chan Result
ragService *RAGService
dbService *DatabaseService
}Data Models & Schemas
Database Schema (PostgreSQL)
-- Prisma Schema
model User {
id String @id @default(cuid())
email String @unique
name String?
image String?
studySessions StudySession[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model StudySession {
id String @id @default(cuid())
title String
content String?
status SessionStatus @default(PENDING)
userId String
user User @relation(fields: [userId], references: [id])
images SessionImage[]
ragResults RAGResult[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model SessionImage {
id String @id @default(cuid())
filename String
s3Key String
extractedText String?
studySessionId String
studySession StudySession @relation(fields: [studySessionId], references: [id])
createdAt DateTime @default(now())
}
model RAGResult {
id String @id @default(cuid())
query String
response String
context String[]
confidence Float?
studySessionId String
studySession StudySession @relation(fields: [studySessionId], references: [id])
createdAt DateTime @default(now())
}Vector Database Schema
// Vector Database Structure
interface DocumentChunk {
id: string
content: string
embedding: number[]
metadata: {
sessionId: string
userId: string
source: string
chunkIndex: number
timestamp: string
}
}
// API Response Types
interface RAGResponse {
query: string
answer: string
sources: Source[]
confidence: number
processingTime: number
}
interface Source {
content: string
similarity: number
metadata: ChunkMetadata
}
// Processing Job Types
interface ProcessingJob {
id: string
sessionId: string
type: 'DOCUMENT_PROCESSING' | 'RAG_QUERY'
status: 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED'
data: any
createdAt: Date
completedAt?: Date
error?: string
}AI Integration & Performance
AI Service Integration
- OpenAI Integration: Text embeddings and GPT models for content understanding
- DeepSeek API: Alternative LLM for cost-effective processing
- Vector Database: Efficient similarity search and retrieval
- OCR Processing: Text extraction from uploaded images
Performance Optimizations
- Concurrent Processing: Multi-worker queue system for parallel job execution
- Embedding Caching: Redis caching for frequently accessed embeddings
- Chunking Strategy: Optimized text chunking for better retrieval accuracy
- Response Streaming: Real-time status updates during processing