# Architecture Overview - AI Study Assistant ## πŸ—οΈ ACTUAL SYSTEM ARCHITECTURE > ⚠️ **Nota importante**: Esta documentaΓ§Γ£o reflete a arquitetura REAL implementada no cΓ³digo. O projeto Γ© uma aplicaΓ§Γ£o Flutter que comunica diretamente com Firebase e Ollama, sem backend Node.js ou Python intermediΓ‘rio. --- ## πŸ“‹ OVERVIEW This document provides a comprehensive overview of the AI Study Assistant system architecture, including component interactions, data flow, technology stack, and design decisions. --- ## 🎯 ARCHITECTURE PRINCIPLES ### Core Principles - **Modularity**: Loosely coupled, highly cohesive components - **Scalability**: Horizontal scaling capabilities - **Maintainability**: Clean, well-documented code - **Security**: Defense-in-depth security approach - **Performance**: Optimized for educational workloads - **Accessibility**: Universal design for learning ### Design Patterns - **Clean Architecture**: Separation of concerns - **Microservices**: Service-oriented architecture - **Event-Driven**: Asynchronous communication - **CQRS**: Command Query Responsibility Segregation - **Repository Pattern**: Data access abstraction --- ## πŸ›οΈ HIGH-LEVEL ARCHITECTURE ### System Overview (Real Implementation) ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ PRESENTATION LAYER β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Flutter App β”‚ Web App β”‚ (Same codebase) β”‚ β”‚ (Mobile/Web) β”‚ (Flutter Web) β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ FLUTTER SERVICES β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Auth β”‚ Tutor β”‚ Quiz β”‚ Gamification β”‚ β”‚ Service β”‚ Service β”‚ Service β”‚ Service β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ RAG β”‚ Chat β”‚ Content β”‚ Vector β”‚ β”‚ Service β”‚ Memory β”‚ Service β”‚ Service (Mock) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ EXTERNAL SERVICES β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Firebase β”‚ Ollama LLM β”‚ β”‚ β€’ Auth β”‚ β€’ Model: qwen3-coder:30b β”‚ β”‚ β€’ Firestore β”‚ β€’ Endpoint: /api/chat β”‚ β”‚ β€’ Storage β”‚ β”‚ β”‚ β€’ Analytics β”‚ β”‚ β”‚ β€’ Crashlytics β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Architecture Notes - **No Backend Server**: The Flutter app communicates directly with Firebase and Ollama - **RAG Implementation**: Keyword-based search with windowing, implemented in Dart - **Embeddings**: Mock/simulated embeddings (384 dimensions) using text hashing - **Vector Store**: Not FAISS - simple in-memory Firestore storage with cosine similarity --- ## πŸ“± FRONTEND ARCHITECTURE ### Flutter Application Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ PRESENTATION β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Features β”‚ β”‚ Shared β”‚ β”‚ Core β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Auth β”‚ β”‚ β€’ Widgets β”‚ β”‚ β€’ Config β”‚ β”‚ β”‚ β”‚ β€’ Tutor β”‚ β”‚ β€’ Utils β”‚ β”‚ β€’ Constants β”‚ β”‚ β”‚ β”‚ β€’ Quiz β”‚ β”‚ β€’ Extensions β”‚ β”‚ β€’ Errors β”‚ β”‚ β”‚ β”‚ β€’ Analytics β”‚ β”‚ β€’ Models β”‚ β”‚ β€’ Network β”‚ β”‚ β”‚ β”‚ β€’ Content β”‚ β”‚ β€’ Services β”‚ β”‚ β€’ Storage β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ BUSINESS LOGIC β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Repositories β”‚ β”‚ Use Cases β”‚ β”‚ Entities β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Auth Repo β”‚ β”‚ β€’ Sign In β”‚ β”‚ β€’ User β”‚ β”‚ β”‚ β”‚ β€’ Tutor Repo β”‚ β”‚ β€’ Ask Tutor β”‚ β”‚ β€’ Question β”‚ β”‚ β”‚ β”‚ β€’ Quiz Repo β”‚ β”‚ β€’ Submit Quiz β”‚ β”‚ β€’ Quiz β”‚ β”‚ β”‚ β”‚ β€’ Analytics Repoβ”‚ β”‚ β€’ Track Progressβ”‚ β”‚ β€’ Progress β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ DATA LAYER β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Remote β”‚ β”‚ Local β”‚ β”‚ Cache β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Firebase Auth β”‚ β”‚ β€’ SharedPrefs β”‚ β”‚ β€’ Memory Cache β”‚ β”‚ β”‚ β”‚ β€’ Firestore β”‚ β”‚ β€’ Hive β”‚ β”‚ β€’ Image Cache β”‚ β”‚ β”‚ β”‚ β€’ Storage β”‚ β”‚ β€’ Secure Storageβ”‚ β”‚ β€’ API Cache β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Component Architecture ```dart // Clean Architecture Layers // Presentation Layer class AskTutorScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Consumer( builder: (context, ref, child) { final tutorState = ref.watch(tutorProvider); return AskTutorView( state: tutorState, onAskQuestion: (question) => ref.read(tutorProvider.notifier).askQuestion(question), ); }, ), ); } } // Business Logic Layer class AskTutorUseCase { final TutorRepository _repository; AskTutorUseCase(this._repository); Future> call(TutorRequest request) async { try { final response = await _repository.askTutor(request); return Right(response); } catch (e) { return Left(ServerFailure(e.toString())); } } } // Data Layer class TutorRepositoryImpl implements TutorRepository { final TutorRemoteDataSource _remoteDataSource; final TutorLocalDataSource _localDataSource; TutorRepositoryImpl( this._remoteDataSource, this._localDataSource, ); @override Future askTutor(TutorRequest request) async { // Cache check final cached = await _localDataSource.getCachedResponse(request); if (cached != null) return cached; // Remote call final response = await _remoteDataSource.askTutor(request); // Cache response await _localDataSource.cacheResponse(request, response); return response; } } ``` --- ## ⚑ BACKEND ARCHITECTURE > ⚠️ **Nota**: NΓ£o existe backend Node.js/Cloud Functions. A arquitetura descrita abaixo Γ© para referΓͺncia futura apenas. ### Actual Backend The "backend" consists of: 1. **Firebase Services** (managed by Google) 2. **Ollama Instance** (self-hosted at 89.114.196.110:11434) ### Cloud Functions Architecture (NOT IMPLEMENTED) ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ API GATEWAY LAYER β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Middleware β”‚ Validation β”‚ Rate Limiting β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Auth β”‚ β€’ Input Check β”‚ β€’ Per-User Limits β”‚ β”‚ β€’ CORS β”‚ β€’ Schema Valid β”‚ β€’ Per-Endpoint Limits β”‚ β”‚ β€’ Logging β”‚ β€’ Sanitization β”‚ β€’ Global Limits β”‚ β”‚ β€’ Error Handl β”‚ β€’ Type Check β”‚ β€’ Burst Protection β”‚ Note: This layer does not exist in the current implementation. β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ SERVICE LAYER β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Auth β”‚ Tutor β”‚ Quiz β”‚ Analytics β”‚ β”‚ Service β”‚ Service β”‚ Service β”‚ Service β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Sign Up β”‚ β€’ Ask Tutor β”‚ β€’ Create β”‚ β€’ Track Progress β”‚ β”‚ β€’ Sign In β”‚ β€’ Get Historyβ”‚ β€’ Submit β”‚ β€’ Generate Reports β”‚ β”‚ β€’ Validate β”‚ β€’ Feedback β”‚ β€’ Grade β”‚ β€’ Calculate Mastery β”‚ β”‚ β€’ Refresh β”‚ β€’ Rate Limitβ”‚ β€’ Analytics β”‚ β€’ Recommendations β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ INTEGRATION LAYER β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Database β”‚ Storage β”‚ Cache β”‚ External APIs β”‚ β”‚ Service β”‚ Service β”‚ Service β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Firestore β”‚ β€’ File Uploadβ”‚ β€’ Redis β”‚ β€’ OpenAI β”‚ β”‚ β€’ Queries β”‚ β€’ Download β”‚ β€’ MemCache β”‚ β€’ Anthropic β”‚ β”‚ β€’ Transactionsβ”‚ β€’ Metadata β”‚ β€’ Session β”‚ β€’ Monitoring β”‚ β”‚ β€’ Indexing β”‚ β€’ Security β”‚ β€’ Cache β”‚ β€’ Analytics β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Service Architecture ```typescript // Service Layer Structure export class TutorService { constructor( private ragService: RAGService, private llmService: LLMService, private cacheService: CacheService, private analyticsService: AnalyticsService, ) {} async askTutor(request: TutorRequest): Promise { // 1. Validate request await this.validateRequest(request); // 2. Check cache const cached = await this.cacheService.get(request); if (cached) return cached; // 3. Process with RAG const context = await this.ragService.retrieveContext(request.query); // 4. Generate response with LLM const response = await this.llmService.generateResponse({ query: request.query, context: context, mode: request.mode, }); // 5. Cache response await this.cacheService.set(request, response); // 6. Track analytics await this.analyticsService.trackInteraction({ userId: request.userId, query: request.query, response: response, mode: request.mode, }); return response; } } ``` --- ## πŸ€– AI/ML ARCHITECTURE (DART IMPLEMENTATION) ### RAG Engine Architecture (Real Implementation) ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ INPUT PROCESSING (Dart) β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Text Input β”‚ Content β”‚ Query Processing β”‚ β”‚ Processing β”‚ Processing β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Text Cleaning β”‚ β€’ PDF Parsing β”‚ β€’ Keyword Extraction β”‚ β”‚ β€’ LaTeX Filter β”‚ β€’ Text Extract β”‚ β€’ Window Search β”‚ β”‚ β€’ Normalization β”‚ β€’ Chunking β”‚ β€’ Similarity Matching β”‚ β”‚ β€’ Validation β”‚ β€’ Cache (Hive) β”‚ β€’ Content Ranking β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ VECTOR STORE (Mock/Simple) β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Embeddings β”‚ Storage β”‚ Retrieval β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Hash-based β”‚ β€’ Firestore β”‚ β€’ Cosine Similarity β”‚ β”‚ β€’ 384 dims β”‚ β€’ contentChunks β”‚ β€’ Keyword Matching β”‚ β”‚ β€’ Deterministic β”‚ β€’ materials β”‚ β€’ Window-based Search β”‚ β”‚ β€’ Fast/Cheap β”‚ β€’ No FAISS β”‚ β€’ No Approximate Search β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ LLM INTEGRATION β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Prompt β”‚ Generation β”‚ Post-Processing β”‚ β”‚ Engineering β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Context Embed β”‚ β€’ Ollama API β”‚ β€’ UTF-8 Encoding β”‚ β”‚ β€’ User Persona β”‚ β€’ qwen3-coder β”‚ β€’ Response Formatting β”‚ β”‚ β€’ PDF Content β”‚ β€’ 30B model β”‚ β€’ Citation Handling β”‚ β”‚ β€’ Constraints β”‚ β€’ Direct HTTP β”‚ β€’ Error Handling β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### RAG Pipeline Implementation (Dart) ```dart // Real implementation in lib/core/services/rag_ai_service.dart class RAGAIService { static const String _baseUrl = 'http://89.114.196.110:11434/api/chat'; static const String _model = 'qwen3-coder:30b'; static Future askTutor({ required String question, required List materialIds, required String mode, }) async { // Step 1: Retrieve context from materials (keyword-based) final context = await MaterialsRAGService.getContextForQuestion( question: question, materialIds: materialIds, ); // Step 2: Build prompt with embedded context final prompt = _buildPrompt( question: question, context: context, mode: mode, ); // Step 3: Call Ollama API directly final response = await http.post( Uri.parse(_baseUrl), headers: {'Content-Type': 'application/json; charset=utf-8'}, body: utf8.encode(jsonEncode({ 'model': _model, 'messages': [ {'role': 'system', 'content': _systemPrompt}, {'role': 'user', 'content': prompt}, ], })), ); // Step 4: Process response return _processResponse(response); } } // MaterialsRAGService - keyword window search class MaterialsRAGService { static Future getContextForQuestion({ required String question, required List materialIds, }) async { // PDF extraction with syncfusion_flutter_pdf // Keyword matching with windowing (1200 chars) // No FAISS, no embeddings, no vector search } } ``` ### Key Differences from Original Design - ❌ **No Python RAG Engine**: Implemented entirely in Dart - ❌ **No FAISS**: Uses keyword matching and simple cosine similarity - ❌ **No Sentence Transformers**: Hash-based mock embeddings (384 dims) - ❌ **No OpenAI/Anthropic**: Only Ollama (qwen3-coder:30b) - βœ… **PDF Processing**: syncfusion_flutter_pdf for text extraction - βœ… **Caching**: Hive for PDF content caching - βœ… **Firestore**: Stores contentChunks with simple vector data --- ## πŸ—„οΈ DATA ARCHITECTURE ### Database Schema (Actual Implementation) ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ FIRESTORE DATABASE β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ USERS β”‚ MATERIALS β”‚ CONTENTCHUNKS β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ uid β”‚ β€’ id β”‚ β€’ id β”‚ β”‚ β€’ email β”‚ β€’ teacherId β”‚ β€’ text β”‚ β”‚ β€’ role β”‚ β€’ fileName β”‚ β€’ subject β”‚ β”‚ β€’ schoolId β”‚ β€’ fileUrl β”‚ β€’ concept β”‚ β”‚ β€’ displayName β”‚ β€’ type β”‚ β€’ embedding (List) β”‚ β”‚ β€’ createdAt β”‚ β€’ createdAt β”‚ β€’ metadata β”‚ β”‚ β”‚ β”‚ β€’ createdAt β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ QUIZZES β”‚ CONVERSATIONS β”‚ CLASSES/ENROLLMENTS β”‚ β”‚ β”‚ (userChats/*) β”‚ β”‚ β”‚ β€’ id β”‚ β”‚ β€’ id β”‚ β”‚ β€’ teacherId β”‚ β€’ id β”‚ β€’ teacherId/classId β”‚ β”‚ β€’ title β”‚ β€’ title β”‚ β€’ name/code β”‚ β”‚ β€’ description β”‚ β€’ selectedMaterialsβ”‚ β€’ studentId β”‚ β”‚ β€’ questions β”‚ β€’ createdAt β”‚ β€’ createdAt/joinedAt β”‚ β”‚ β€’ createdAt β”‚ β€’ hasUserMessageβ”‚ β”‚ β”‚ β”‚ β€’ messages/* β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Collections NOT Implemented - ❌ `learningStates` - Not in codebase - ❌ `auditLogs` - Not implemented - ❌ `quizAttempts` - Not implemented - ❌ `interactions` - Replaced by userChats/{uid}/conversations ### Roles (Only 2 implemented) - βœ… `student` - Can view content, take quizzes, ask tutor - βœ… `teacher` - Can upload materials, create quizzes, view analytics - ❌ `admin` - NOT IMPLEMENTED - ❌ `super_admin` - NOT IMPLEMENTED ### Data Flow Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ DATA FLOW PATTERNS β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Write Path β”‚ Read Path β”‚ Analytics Path β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ 1. User Action β”‚ 1. Cache Check β”‚ 1. Event Capture β”‚ β”‚ 2. Validation β”‚ 2. DB Query β”‚ 2. Stream Processing β”‚ β”‚ 3. DB Write β”‚ 3. Cache Updateβ”‚ 3. Aggregation β”‚ β”‚ 4. Cache Update β”‚ 4. Response β”‚ 4. Storage β”‚ β”‚ 5. Event Emit β”‚ 5. Analytics β”‚ 5. Dashboard Update β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## πŸ” SECURITY ARCHITECTURE ### Security Layers ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ SECURITY LAYERS β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Network β”‚ Application β”‚ Data β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ HTTPS/TLS β”‚ β€’ Authenticationβ”‚ β€’ Encryption at Rest β”‚ β”‚ β€’ CORS Policy β”‚ β€’ Authorizationβ”‚ β€’ Field-Level Encryption β”‚ β”‚ β€’ Rate Limiting β”‚ β€’ Input Validationβ”‚ β€’ Access Control β”‚ β”‚ β€’ DDoS Protectionβ”‚ β€’ Output Encodingβ”‚ β€’ Audit Logging β”‚ β”‚ β€’ VPN Access β”‚ β€’ Session Mgmt β”‚ β€’ Data Retention β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ COMPLIANCE LAYER β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ GDPR β”‚ FERPA β”‚ Educational Standards β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Data Consent β”‚ β€’ Directory Infoβ”‚ β€’ Accessibility β”‚ β”‚ β€’ Right to Accessβ”‚ β€’ Educational β”‚ β€’ Privacy by Design β”‚ β”‚ β€’ Data Portabilityβ”‚ Records β”‚ β€’ Age Appropriateness β”‚ β”‚ β€’ Right to Erasureβ”‚ β€’ Parent Accessβ”‚ β€’ Content Filtering β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## πŸš€ DEPLOYMENT ARCHITECTURE ### Infrastructure Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ INFRASTRUCTURE β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Frontend β”‚ Backend β”‚ AI/ML β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Firebase Host β”‚ β€’ Cloud Functionsβ”‚ β€’ Vector Database β”‚ β”‚ β€’ CDN β”‚ β€’ Auto Scaling β”‚ β€’ Model Servers β”‚ β”‚ β€’ Edge Caching β”‚ β€’ Load Balancer β”‚ β€’ GPU Resources β”‚ β”‚ β€’ SSL/TLS β”‚ β€’ Monitoring β”‚ β€’ Model Caching β”‚ β”‚ β€’ CI/CD β”‚ β€’ Logging β”‚ β€’ Batch Processing β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ MONITORING & LOGGING β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Application β”‚ Infrastructureβ”‚ Security β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Error Tracking β”‚ β€’ Resource Usageβ”‚ β€’ Threat Detection β”‚ β”‚ β€’ Performance β”‚ β€’ Uptime β”‚ β€’ Access Logs β”‚ β”‚ β€’ User Analytics β”‚ β€’ Health Checksβ”‚ β€’ Vulnerability Scanning β”‚ β”‚ β€’ A/B Testing β”‚ β€’ Alerts β”‚ β€’ Compliance Monitoring β”‚ β”‚ β€’ Feature Flags β”‚ β€’ Metrics β”‚ β€’ Audit Trails β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## πŸ“Š SCALABILITY ARCHITECTURE ### Horizontal Scaling Strategy ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ SCALING PATTERNS β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Database β”‚ Application β”‚ AI/ML β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Sharding β”‚ β€’ Load Balancerβ”‚ β€’ Model Sharding β”‚ β”‚ β€’ Replication β”‚ β€’ Auto Scaling β”‚ β€’ Distributed Inference β”‚ β”‚ β€’ Caching β”‚ β€’ Microservicesβ”‚ β€’ Batch Queues β”‚ β”‚ β€’ Read Replicas β”‚ β€’ Containerizationβ”‚ β€’ GPU Pooling β”‚ β”‚ β€’ Connection Poolβ”‚ β€’ Serverless β”‚ β€’ Model Versioning β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Performance Optimization ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ PERFORMANCE LAYERS β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Frontend β”‚ Backend β”‚ Database β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Lazy Loading β”‚ β€’ Caching β”‚ β€’ Indexing β”‚ β”‚ β€’ Code Splittingβ”‚ β€’ Connection Poolβ”‚ β€’ Query Optimization β”‚ β”‚ β€’ Image Opt β”‚ β€’ Batch Ops β”‚ β€’ Data Compression β”‚ β”‚ β€’ Memory Mgmt β”‚ β€’ Async Processingβ”‚ β€’ Partitioning β”‚ β”‚ β€’ Bundle Size β”‚ β€’ Rate Limiting β”‚ β€’ Caching Strategy β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## πŸ”§ TECHNOLOGY STACK (ACTUAL) ### Frontend Technologies ```yaml Flutter Framework: - SDK: ^3.11.5 (Dart 3.0+) - Language: Dart 3.0+ - State Management: Riverpod 2.4.9 - Navigation: GoRouter 12.1.3 - UI: Material Design 3 - Testing: Flutter Test, Integration Test (not implemented) Firebase Services: - Authentication: firebase_auth ^4.17.8 - Database: cloud_firestore ^4.15.8 - Storage: firebase_storage ^11.6.9 - Analytics: firebase_analytics ^10.8.0 - Crashlytics: firebase_crashlytics ^3.5.7 - Messaging: firebase_messaging ^14.9.3 - Performance: NOT IMPLEMENTED - Remote Config: NOT IMPLEMENTED Third-Party Libraries: - HTTP: Dio ^5.4.0, http ^1.1.2 - PDF Processing: syncfusion_flutter_pdf ^33.2.6 - Caching: cached_network_image ^3.3.0, hive ^2.2.3 - Fonts: google_fonts ^6.1.0 - Animations: flutter_animate ^4.2.0, lottie ^2.7.0 - Charts: fl_chart ^0.64.0 - File Handling: file_selector ^1.0.3, image_picker ^1.0.4 - Utilities: intl ^0.20.2, uuid ^4.2.1, equatable ^2.0.5 ``` ### Backend Technologies (NOT IMPLEMENTED) ```yaml Status: NO BACKEND SERVER The following technologies are documented but NOT implemented: ❌ Firebase Cloud Functions - Not used ❌ Node.js / TypeScript - Not used ❌ Python RAG Engine - Not used ❌ FAISS Vector Database - Not used ❌ Sentence Transformers - Not used ❌ OpenAI API - Not used ❌ Anthropic Claude - Not used Actual Implementation: βœ… Flutter app calls Ollama directly via HTTP βœ… Firebase services handle auth, database, storage βœ… RAG logic implemented in Dart (keyword matching) βœ… Embeddings: Mock/hash-based in Dart ``` ### Infrastructure Technologies ```yaml Cloud Platform: - Provider: Google Firebase (BaaS) - Services: Firebase Auth, Firestore, Storage - Hosting: Firebase Hosting (for web builds) - Self-hosted: Ollama LLM server (89.114.196.110:11434) Database: - Primary: Cloud Firestore (NoSQL) - Cache: Hive (local), Memory cache - Search: Not implemented (no Elasticsearch) - Backup: Firebase automated backups Security: - TLS: HTTPS for all communications - Authentication: Firebase Auth (email/password, Google) - Authorization: Client-side role checks (student/teacher) - Note: No admin role implemented CI/CD: - Pipeline: Manual builds - Build: flutter build web/apk - Deploy: Firebase CLI (manual) - Testing: No automated tests implemented ``` --- ## πŸ”„ INTEGRATION PATTERNS ### Service Communication ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ COMMUNICATION PATTERNS β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Synchronous β”‚ Asynchronous β”‚ Event-Driven β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ HTTP/REST β”‚ β€’ Message Queue β”‚ β€’ Event Streaming β”‚ β”‚ β€’ GraphQL β”‚ β€’ Pub/Sub β”‚ β€’ CQRS β”‚ β”‚ β€’ gRPC β”‚ β€’ Background Jobsβ”‚ β€’ Event Sourcing β”‚ β”‚ β€’ WebSocket β”‚ β€’ Worker Threadsβ”‚ β€’ Saga Pattern β”‚ β”‚ β€’ API Gateway β”‚ β€’ Batch Processingβ”‚ β€’ Domain Events β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Data Integration ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ DATA INTEGRATION β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Real-time β”‚ Batch β”‚ Hybrid β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Firestore β”‚ β€’ Cloud Storage β”‚ β€’ Stream Processing β”‚ β”‚ β€’ Realtime DB β”‚ β€’ BigQuery β”‚ β€’ Lambda Architecture β”‚ β”‚ β€’ WebSocket β”‚ β€’ Dataflow β”‚ β€’ Change Data Capture β”‚ β”‚ β€’ Pub/Sub β”‚ β€’ Cloud Functionsβ”‚ β€’ Event-Driven Updates β”‚ β”‚ β€’ Webhooks β”‚ β€’ Scheduled Jobsβ”‚ β€’ Reactive Programming β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## 🎯 DESIGN DECISIONS ### Architectural Decisions #### 1. Clean Architecture **Decision**: Adopt Clean Architecture principles **Rationale**: - Separation of concerns - Testability - Maintainability - Framework independence #### 2. Microservices Architecture **Decision**: Use microservices for backend **Rationale**: - Independent scaling - Technology diversity - Fault isolation - Team autonomy #### 3. Firebase as Backend **Decision**: Use Firebase as primary backend **Rationale**: - Rapid development - Built-in security - Real-time capabilities - Managed infrastructure #### 4. RAG for AI Tutoring **Decision**: Use Retrieval-Augmented Generation **Rationale**: - Context-aware responses - Reduced hallucinations - Educational content integration - Explainable AI #### 5. Flutter for Cross-Platform **Decision**: Use Flutter for frontend **Rationale**: - Single codebase - Native performance - Consistent UI - Rapid development ### Technology Trade-offs #### Firebase vs. Custom Backend **Firebase Chosen**: - βœ… Rapid development - βœ… Built-in security - βœ… Real-time features - βœ… Managed infrastructure - ❌ Vendor lock-in - ❌ Limited customization - ❌ Cost at scale #### Vector Database Options **FAISS Chosen**: - βœ… Performance - βœ… Open source - βœ… Python integration - ❌ Limited features - ❌ No managed service - ❌ Scaling complexity #### LLM Provider Strategy **Multiple Providers**: - βœ… Redundancy - βœ… Cost optimization - βœ… Feature diversity - ❌ Integration complexity - ❌ Consistency challenges --- ## πŸ“ˆ PERFORMANCE ARCHITECTURE ### Performance Optimization Layers ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ PERFORMANCE LAYERS β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Frontend β”‚ Backend β”‚ Database β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Code Splittingβ”‚ β€’ Function Cold β”‚ β€’ Query Optimization β”‚ β”‚ β€’ Lazy Loading β”‚ Starts β”‚ β€’ Indexing Strategy β”‚ β”‚ β€’ Image Opt β”‚ β€’ Connection β”‚ β€’ Caching Layers β”‚ β”‚ β€’ Memory Mgmt β”‚ Pooling β”‚ β€’ Data Sharding β”‚ β”‚ β€’ Bundle Size β”‚ β€’ Batch Ops β”‚ β€’ Read Replicas β”‚ β”‚ β€’ Animations β”‚ β€’ Async Processingβ”‚ β€’ Compression β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Caching Strategy ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ CACHING HIERARCHY β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Client Cache β”‚ Edge Cache β”‚ Server Cache β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Memory Cache β”‚ β€’ CDN Cache β”‚ β€’ Redis Cache β”‚ β”‚ β€’ Local Storage β”‚ β€’ Browser Cache β”‚ β€’ Application Cache β”‚ β”‚ β€’ Image Cache β”‚ β€’ API Cache β”‚ β€’ Database Cache β”‚ β”‚ β€’ Response Cache β”‚ β€’ Static Assets β”‚ β€’ Session Cache β”‚ β”‚ β€’ Offline Cache β”‚ β€’ Global Cache β”‚ β€’ Distributed Cache β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## πŸ” MONITORING ARCHITECTURE ### Monitoring Stack ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ MONITORING STACK β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Application β”‚ Infrastructureβ”‚ Business β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Error Trackingβ”‚ β€’ Resource Usageβ”‚ β€’ User Analytics β”‚ β”‚ β€’ Performance β”‚ β€’ Health Checksβ”‚ β€’ Learning Metrics β”‚ β”‚ β€’ User Behavior β”‚ β€’ Uptime β”‚ β€’ Engagement Tracking β”‚ β”‚ β€’ Feature Usage β”‚ β€’ Latency β”‚ β€’ Content Analytics β”‚ β”‚ β€’ A/B Testing β”‚ β€’ Throughput β”‚ β€’ Progress Analytics β”‚ β”‚ β€’ Custom Events β”‚ β€’ Error Rates β”‚ β€’ Quiz Performance β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Alerting Strategy ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ ALERTING LAYERS β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Technical β”‚ Business β”‚ Security β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Error Rate β”‚ β€’ User Activityβ”‚ β€’ Threat Detection β”‚ β”‚ β€’ Response Time β”‚ β€’ Conversion β”‚ β€’ Access Violations β”‚ β”‚ β€’ Memory Usage β”‚ β€’ Engagement β”‚ β€’ Anomalous Behavior β”‚ β”‚ β€’ CPU Usage β”‚ β€’ Learning β”‚ β€’ Data Breaches β”‚ β”‚ β€’ Disk Space β”‚ β€’ Quiz Completionβ”‚ β€’ Compliance Violations β”‚ β”‚ β€’ Network Latencyβ”‚ β€’ Content Usageβ”‚ β€’ Authentication Failures β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## πŸš€ FUTURE ARCHITECTURE ### Scalability Roadmap ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ EVOLUTION PATH β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Phase 1 β”‚ Phase 2 β”‚ Phase 3 β”‚ β”‚ (Current) β”‚ (6 months) β”‚ (1 year) β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Firebase β”‚ β€’ Hybrid Cloud β”‚ β€’ Multi-Region β”‚ β”‚ β€’ Single Region β”‚ β€’ Custom Backendβ”‚ β€’ Edge Computing β”‚ β”‚ β€’ Basic AI β”‚ β€’ Advanced AI β”‚ β€’ Federated Learning β”‚ β”‚ β€’ Mobile/Web β”‚ β€’ Desktop Apps β”‚ β€’ AR/VR Support β”‚ β”‚ β€’ Basic Analyticsβ”‚β€’ Advanced Analyticsβ”‚β€’ Predictive Analytics β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Technology Evolution ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ TECHNOLOGY ROADMAP β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Frontend β”‚ Backend β”‚ AI/ML β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ Flutter Web β”‚ β€’ GraphQL API β”‚ β€’ Custom Models β”‚ β”‚ β€’ Desktop Apps β”‚ β€’ Microservicesβ”‚ β€’ Fine-tuned LLMs β”‚ β”‚ β€’ AR/VR Support β”‚ β€’ Event Sourcingβ”‚ β€’ Multi-modal AI β”‚ β”‚ β€’ Voice UI β”‚ β€’ CQRS β”‚ β€’ Real-time Learning β”‚ β”‚ β€’ Offline Mode β”‚ β€’ Distributed β”‚ β€’ Federated Learning β”‚ β”‚ β€’ Progressive β”‚ Systems β”‚ β€’ Edge AI β”‚ β”‚ Web Apps β”‚ β€’ Kubernetes β”‚ β€’ Custom Hardware β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## πŸ“š DOCUMENTATION ARCHITECTURE ### Documentation Structure ``` docs/ β”œβ”€β”€ technical/ # Technical documentation β”‚ β”œβ”€β”€ api/ # API documentation β”‚ β”œβ”€β”€ architecture/ # Architecture docs β”‚ β”œβ”€β”€ database/ # Database docs β”‚ └── security/ # Security docs β”œβ”€β”€ user/ # User documentation β”‚ β”œβ”€β”€ student/ # Student guides β”‚ β”œβ”€β”€ teacher/ # Teacher guides β”‚ └── admin/ # Admin guides β”œβ”€β”€ development/ # Development docs β”‚ β”œβ”€β”€ setup/ # Setup guides β”‚ β”œβ”€β”€ contributing/ # Contributing guide β”‚ β”œβ”€β”€ testing/ # Testing guide β”‚ └── deployment/ # Deployment guide └── business/ # Business documentation β”œβ”€β”€ requirements/ # Requirements β”œβ”€β”€ roadmap/ # Product roadmap └── metrics/ # Business metrics ``` --- ## 🎯 CONCLUSION The AI Study Assistant architecture is designed to be: - **Scalable**: Handle growth in users and content - **Maintainable**: Clean, well-documented code - **Secure**: Multi-layered security approach - **Performant**: Optimized for educational workloads - **Accessible**: Universal design principles - **Innovative**: Cutting-edge AI/ML integration This architecture provides a solid foundation for delivering high-quality educational experiences while maintaining flexibility for future enhancements and scaling requirements. --- *Last Updated: 2026-05-06* *Version: 1.0.0* *Architecture Team: System Design & Engineering*