Arhitektura

Verzija: 1.0 Datum: Januar 2026 Status: Production Ready


Splošen Pregled

O Aplikaciji

Moj AI je napredna AI aplikacija, specializirana za slovensko gradbeno zakonodajo. Aplikacija združuje najnovejše tehnologije umetne inteligence z robustno cloud infrastrukturo za zagotavljanje zanesljivih, varnih in natančnih pravnih odgovorov.

Ključne Tehnologije

  • AI Model: Google Gemini 2.5 Flash (najnovejša generacija)

  • Cloud Platform: Google Cloud Platform (Firebase)

  • Frontend: React 19 + TypeScript + Vite

  • Backend: Cloud Functions (Node.js 20, 2nd Gen)

  • Database: Firestore (NoSQL)

  • Storage: Cloud Storage

  • Payments: Stripe

  • Authentication: Firebase Authentication (Google OAuth)

Arhitekturni Pristop

Aplikacija uporablja serverless mikroservisno arhitekturo za maksimalno skalabilnost in zanesljivost:

  • ✅ Zero server management

  • ✅ Automatic scaling

  • ✅ Pay-per-use model

  • ✅ High availability (99.95% SLA)

  • ✅ Global CDN distribution


Tehnološki Stack

Frontend Layer

Core Technologies

State Management

  • React Context API za globalno stanje

  • Custom Hooks za business logic

  • Local Storage za persistence

UI/UX Features

  • 🎨 Dark/Light mode support

  • 🌍 Multi-language (Slovenščina, English)

  • 📱 Fully responsive (Mobile, Tablet, Desktop)

  • ♿ WCAG 2.1 AA Accessibility compliance

Performance Optimizations

  • Code splitting

  • Lazy loading

  • Image optimization

  • Bundle size optimization

  • Service Worker caching

Backend Layer

Cloud Functions (2nd Gen)

Function Specifications

  • Runtime: Node.js 20

  • Memory: 256MB - 2GB (function-dependent)

  • Timeout: 60s - 300s

  • Concurrency: Auto-scaling

  • Region: us-central1

Core Functions

  • health() - Health check endpoint

  • askGemini() - Main AI orchestration

  • uploadFile() - Document upload handler

  • deleteDocumentFromFileSearch() - Document deletion

  • handleStripeWebhook() - Payment processing

Database Layer

Firestore (NoSQL)

Database Features

  • Real-time synchronization

  • Offline support

  • Automatic indexing

  • Atomic transactions

  • Strong consistency

Storage Layer

Cloud Storage

Storage Features

  • Encrypted at rest

  • Automatic backup

  • CDN integration

  • Multi-region replication

  • Versioning support


Sistemska Arhitektura

High-Level Architecture

Request Flow - Lightning Mode

1

1. User Query → Hosting

User sends query via frontend served from Firebase Hosting (CDN + SSL).

2

2. Authentication Check

Firebase Auth verifies the user session (Google OAuth).

3

3. Cloud Function: askGemini()

  • Load system prompt from Firestore

  • Load Admin RAG Store

  • Call Gemini API (File Search)

  • Process response

  • Save result to Firestore

4

4. Streaming & UI Update

  • Stream response to client

  • Update UI with answer and sources

Request Flow - Frontier Mode

1

1. User Query → Hosting

User sends query via frontend served from Firebase Hosting.

2

2. Authentication Check

Firebase Auth verifies user session.

3

3. Cloud Function: askGemini() → Agent Orchestration

  • classifyQuery() determines routing: RAG? Web? Both?

4

4. Parallel Execution

  • queryRAGAgent(): Load Admin + User RAG Stores → Call Gemini (File Search)

  • queryWebAgent(): Call Gemini (Google Search)

5

5. Result Synthesis

  • synthesizeResults(): Merge RAG + Web results, source attribution, quality check

  • Save to Firestore

  • Stream response to client

Document Upload Flow

1

1. File Selection & Frontend Validation

  • Validate file size (max 5MB), type (PDF, DOCX, ...) and total storage (max 500MB).

2

2. Cloud Function: uploadFile()

  • Stream buffer (Busboy)

  • Upload to Cloud Storage

  • Upload to Gemini File API (Multimodal)

  • Index in File Search Store (RAG)

  • Save metadata in Firestore

3

3. Confirmation

  • Confirm upload and indexing status to user


AI Tehnologija

Google Gemini Integration

Model Selection

  • Lightning Mode: gemini-2.5-flash — Optimized for speed, cost-effective, excellent accuracy

  • Frontier Mode: gemini-2.5-flash (Agent Orchestration) — Comprehensive research, multi-source synthesis, advanced reasoning

RAG System (Retrieval-Augmented Generation)

Architecture

File Search Stores

  • Admin Store: admin-file-search-store — Slovenska gradbena zakonodaja, OPN-ji večjih občin, tehnični predpisi, redno posodobljeno

  • User Stores: user-{userId}-file-search-store — User-uploaded documents, private per user, automatic indexing

Search Capabilities

  • 🔍 Semantic search (not just keywords)

  • 📊 Relevance scoring

  • 🎯 Context-aware retrieval

  • 🔄 Multi-chunk aggregation

  • 📝 Source attribution

Agent Orchestration (Frontier Mode)

Agent Architecture

Agent Functions

  • classifyQuery() — Analyzes query type

  • queryRAGAgent() — Documents specialist

  • queryWebAgent() — Internet specialist

  • synthesizeResults() — Result combiner

  • orchestrateAgents() — Main coordinator

Benefits

  • ✅ Parallel execution (faster)

  • ✅ Best-of-both-worlds (documents + internet)

  • ✅ Intelligent routing

  • ✅ Source verification

  • ✅ Quality assurance

System Prompts

Slovenian-Optimized

  • System prompts v slovenščini, pravna terminologija, gradbeno-specifični kontekst, source attribution rules, response formatting guidelines

Dynamic Configuration

  • Stored in Firestore, admin-configurable, version control, A/B testing capable


Podatkovna Arhitektura

Data Model

User Document

Conversation Document

Document Metadata

Data Flow Patterns

Real-time Synchronization

  • User presence tracking

  • Live conversation updates

  • Multi-device sync

  • Offline-first architecture

Data Consistency

  • Firestore transactions

  • Atomic operations

  • Optimistic updates

  • Conflict resolution


Varnost in Zasebnost

Authentication

Google OAuth 2.0

1

1. User clicks "Continue with Google"

Redirect to Google OAuth.

2

2. Google Authentication

User authenticates and Google returns ID token.

3

3. Firebase Verification & Session

Firebase verifies token, create/update user session, set secure cookies, redirect to dashboard.

Security Features

  • 🔐 Industry-standard OAuth 2.0

  • 🔑 JWT token-based sessions

  • 🛡️ Automatic token refresh

  • 📱 2FA support (if enabled in Google)

  • ⏱️ Session expiration

  • 🚫 No password storage

Data Protection

Encryption

  • In Transit: TLS 1.3

  • At Rest: AES-256

  • Database: Automatic encryption

  • Storage: Encrypted by default

Access Control

Privacy Compliance

GDPR Compliance

  • ✅ Right to access (data export)

  • ✅ Right to erasure (account deletion)

  • ✅ Right to portability (JSON export)

  • ✅ Data minimization

  • ✅ Purpose limitation

  • ✅ Transparent processing

Data Retention

  • Active data: Indefinite (user-controlled)

  • Deleted accounts: 30-day grace period

  • Backups: 30-day retention

  • Logs: 90-day retention

API Security

Cloud Functions Protection

  • HTTPS only (enforced)

  • Firebase Auth verification

  • CORS configuration

  • Rate limiting

  • Input sanitization

  • SQL injection prevention

  • XSS prevention

Gemini API Security

  • API keys stored in environment variables

  • Key rotation capability

  • Request signing

  • No API keys in client code

  • Server-side only calls


Plačilni Sistem

Stripe Integration

Architecture

Payment Flow

1

1. User selects plan

User picks desired subscription tier.

2

2. Checkout

Click "Subscribe" → Redirect to Stripe Checkout → User enters payment details.

3

3. Processing & Webhook

Stripe processes payment and sends webhook to our backend.

4

4. Post-payment

  • Cloud Function verifies signature, processes event, updates user subscription in Firestore

  • Send confirmation email

  • Update UI with new plan

Supported Payment Methods

  • 💳 Credit/Debit cards (Visa, Mastercard, AmEx)

  • 🏦 SEPA Direct Debit (EU)

  • 📱 Apple Pay

  • 📱 Google Pay

Security Features

  • ✅ No card data touches our servers

  • ✅ PCI-DSS Level 1 compliant

  • ✅ 3D Secure authentication

  • ✅ Fraud detection

  • ✅ Webhook signature verification

Subscription Plans

Pricing Model

Billing Features

  • ✅ Monthly billing cycle

  • ✅ Automatic renewals

  • ✅ Prorated upgrades/downgrades

  • ✅ Invoice generation (PDF)

  • ✅ VAT handling (EU)

  • ✅ Reverse charge (B2B)

  • ✅ Cancel anytime

  • ✅ 30-day money-back guarantee


Deployment in Infrastruktura

Hosting Architecture

Firebase Hosting

Domain Configuration

  • Production: app.mojai.xyz

  • SSL: Auto-managed (Let's Encrypt)

  • DNS: Cloudflare (with proxy disabled for Firebase)

  • CDN: Firebase CDN + Cloudflare

Cloud Functions Deployment

CI/CD Pipeline

1

1. Code Changes

  • Git commit → Push to repository

2

2. Build Process

  • npm install

  • TypeScript compilation

  • Unit tests

  • Bundle creation

3

3. Deployment

  • firebase deploy --only functions

  • Health check

  • Rollback on failure

Function Configuration

Environment Management

Environments

  • Development: Local Firebase emulators

  • Staging: firebase-staging project

  • Production: moj-ai-gen-3

Configuration

Backup and Recovery

Automated Backups

  • Firestore: Daily automated exports

  • Cloud Storage: Multi-region replication

  • Configuration: Version control (Git)

Disaster Recovery

  • RTO (Recovery Time Objective): < 1 hour

  • RPO (Recovery Point Objective): < 24 hours

  • Backup Retention: 30 days

  • Geographic Redundancy: Multi-region


Skalabilnost in Performanca

Auto-Scaling

Cloud Functions

Firestore

  • Automatic sharding

  • Global distribution

  • 99.99% availability SLA

  • 10,000+ ops/sec capacity

Performance Optimization

Frontend

Backend

Database

Performance Metrics

Target SLAs

Load Testing

Capacity Planning

  • Concurrent users: 1,000+

  • Requests per second: 100+

  • Database ops: 10,000+ per second

  • Storage throughput: 100MB/s


Monitoring in Analytics

Application Monitoring

Firebase Analytics

Cloud Functions Logs

  • Structured logging (JSON)

  • Log levels (ERROR, WARN, INFO, DEBUG)

  • Request tracing

  • Performance profiling

Error Tracking

Error Monitoring

Alerting

  • Critical errors → Immediate alert

  • Performance degradation → Warning

  • Quota approaching → Notification

  • Failed payments → Email

User Analytics

Usage Metrics


Arhitekturne Prednosti

Zakaj Ta Stack?

Google Cloud Platform

Zanesljivost: 99.95%+ SLA ✅ Skalabilnost: Automatic scaling ✅ Varnost: Enterprise-grade ✅ Performanca: Global CDN ✅ Stroški: Pay-per-use model

Serverless Architecture

Zero server managementAutomatic scalingHigh availabilityCost optimizationFast deployment

Modern Frontend

React 19: Latest features ✅ TypeScript: Type safety ✅ Vite: Fast builds ✅ Tailwind: Rapid styling ✅ Mobile-first: Responsive

AI Integration

Gemini 2.5: State-of-the-art ✅ RAG: Accurate sourcing ✅ Multimodal: Vision capable ✅ Agent Orchestration: Multi-source ✅ Slovenian: Language-optimized


Tehnična Odličnost

Best Practices

Code Quality

  • ✅ TypeScript throughout

  • ✅ ESLint configuration

  • ✅ Prettier formatting

  • ✅ Git version control

  • ✅ Code reviews

Testing

  • ✅ Unit tests (Jest)

  • ✅ Integration tests

  • ✅ End-to-end tests

  • ✅ Performance tests

  • ✅ Security audits

Documentation

  • ✅ API documentation

  • ✅ Architecture diagrams

  • ✅ User guides

  • ✅ Developer onboarding

  • ✅ Change logs

DevOps

  • ✅ CI/CD pipeline

  • ✅ Automated deployments

  • ✅ Rollback capability

  • ✅ Environment parity

  • ✅ Infrastructure as code

Compliance Standards

Security

  • 🔒 HTTPS: TLS 1.3 enforced

  • 🛡️ OAuth 2.0: Industry standard

  • 🔐 Encryption: AES-256

  • 📊 GDPR: Full compliance

  • 🏛️ SOC 2: Google Cloud certified

Reliability

  • ⏱️ Uptime: 99.9%+ target

  • 🔄 Backup: Daily automated

  • 🌍 Multi-region: Redundancy

  • 📈 Monitoring: 24/7

  • 🚨 Alerting: Real-time


Zaključek

Tehnološka Zrelost

Moj AI predstavlja state-of-the-art implementacijo moderne cloud-native aplikacije z:

  1. Napredna AI Tehnologija

    • Najnovejši Google Gemini 2.5 Flash model

    • Dualna RAG arhitektura (Multimodal + Vector Search)

    • Inteligentna agent orkestracija

  2. Enterprise-Grade Infrastruktura

    • Google Cloud Platform (Fortune 500 standard)

    • Serverless arhitektura za maksimalno skalabilnost

    • Multi-region redundanca

  3. Varnost in Zasebnost

    • Industry-standard OAuth 2.0

    • End-to-end encryption

    • GDPR compliance

    • Zero-trust architecture

  4. Performanca in Zanesljivost

    • 99.9%+ uptime SLA

    • Sub-second response times

    • Global CDN distribution

    • Automatic scaling

  5. Uporabniška Izkušnja

    • Modern React interface

    • Multi-language support

    • Mobile-optimized

    • Accessibility compliant

Konkurenčne Prednosti

Tehnološke:

  • ✅ Najnovejša AI tehnologija (Gemini 2.5)

  • ✅ Slovenščina-optimizirano

  • ✅ Hybrid RAG pristop

  • ✅ Agent orchestration

  • ✅ Real-time updates

Poslovno:

  • ✅ Pay-per-question model

  • ✅ No upfront investment

  • ✅ Transparent pricing

  • ✅ Cancel anytime

  • ✅ Enterprise support

Varnost:

  • ✅ Google-level security

  • ✅ GDPR compliant

  • ✅ Data encryption

  • ✅ Private RAG stores

  • ✅ Regular audits


Kontakt

Za tehnične informacije: 📧 [email protected]

Za enterprise integracije: 📧 [email protected]

Spletna stran: 🌐 https://app.mojai.xyz


Moj AI - Powered by Google Cloud Platform & Gemini AI

Verzija dokumenta: 1.0 Datum: Januar 2026 Status: Production