System Architecture

Backend-for-Frontend (BFF) with Centralized AI Processing

Version 6.0 | BUILD #107

High-Level Topology

┌─────────────────────────────────────────────────────────────────┐
│                        YAKKI EDU                                 │
├─────────────────────────────────────────────────────────────────┤
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐          │
│  │   Android   │    │   Flutter   │    │    Web      │          │
│  │   (Kotlin)  │    │   (Dart)    │    │  (Future)   │          │
│  └──────┬──────┘    └──────┬──────┘    └──────┬──────┘          │
│         │                  │                  │                  │
│         └──────────────────┼──────────────────┘                  │
│                            │                                     │
│                    ┌───────▼───────┐                             │
│                    │  yakki-intel  │                             │
│                    │  (Rust+Axum)  │                             │
│                    │ api.yakki.app │                             │
│                    └───────┬───────┘                             │
│                            │                                     │
│                    ┌───────▼───────┐                             │
│                    │  Gemini 2.0   │                             │
│                    │    Flash      │                             │
│                    └───────────────┘                             │
└─────────────────────────────────────────────────────────────────┘

Pattern

Backend-for-Frontend (BFF)

Current State

Hybrid online/offline

Target State

Full multi-platform

Server Architecture (yakki-intel)

Technology Stack

Component Technology Purpose
Framework Axum Async HTTP server
Database SQLite User/Grammar/Vocabulary storage
AI Gemini 2.0 Flash Content generation & validation
Auth bcrypt Password hashing (cost 12)
Runtime Tokio Async runtime

Module Structure

server/yakki-intel/src/
├── main.rs                # Routes & server setup
├── auth_handlers.rs       # Login, registration, user management
├── handlers.rs            # Legacy endpoints
├── batch_handlers.rs      # Parallel mission generation
├── vocabulary_handlers.rs # Grammar rules & vocabulary
├── heartbeat_handlers.rs  # Online status tracking
├── db.rs                  # SQLite operations
├── models.rs              # Data structures
├── config.rs              # Environment configuration
└── gemini.rs              # Gemini AI client

User Hierarchy

ADMIN admin-XXX-YYYYMMDD
  • Can create: Teachers, Learners
  • Can view: ALL learners
  • Seeded at first server start
TEACHER teacher-XXX-YYYYMMDD
  • Created by: Admin
  • Can create: Learners
  • Can view: Only OWN learners (created_by = teacher_id)
LEARNER learner-XXX-YYYYMMDD
  • Created by: Teacher or Admin
  • Can create: Nothing
  • Can view: Only self

Android App Architecture

Module Dependency Graph

┌───────────────────────────────────────────────────────────────────┐
│                           :app                                      │
│  (DI, Navigation, MainActivity, UI Screens, YakkiApp)              │
└────────────────────────┬──────────────────────────────────────────┘
                         │ depends on
        ┌────────────────┼────────────────┬─────────────────┐
        ▼                ▼                ▼                 ▼
   ┌─────────┐    ┌─────────────┐   ┌─────────┐    ┌──────────────┐
   │ :domain │    │   :data     │   │:conductor│   │:intel-reader │
   │(Models) │◀───│(Room+Ktor)  │   │ (Logic) │   │(Feature Mod) │
   └─────────┘    └─────────────┘   └─────────┘    └──────────────┘
        ▲                │                │                │
        └────────────────┴────────────────┴────────────────┘
                        depends on :domain

Intel Reader Module

libraries/intel-reader/
├── di/
│   └── NetworkModule.kt
├── network/
│   └── IntelReaderApiService.kt
├── repository/
│   └── IntelReaderRepository.kt
├── ui/
│   ├── IntelReaderComponent.kt
│   ├── IntelReaderViewModel.kt
│   ├── LoginScreen.kt
│   ├── DebugScreen.kt
│   ├── MissionSelectScreen.kt
│   ├── MissionCreateScreen.kt
│   └── StudentSelectScreen.kt
└── models/
    └── ReadingMission.kt

State Management (MVI)

IntelReaderViewModel

  • _uiState: MutableStateFlow<UiState>
  • _authState: MutableStateFlow<AuthState>
  • _currentUserId: String
  • teacherMode: Boolean

AuthState

  • isLoading, isLoggedIn
  • currentUser: LoggedInUser?
  • error, createUserSuccess/Error

Grammar Rules System

Rule ID Format

GR-{CATEGORY}-{SUBCATEGORY}-{NUMBER}

GR-TENSE-PRES-SIMPLE-001 — Present Simple basics

GR-ARTICLE-DEF-001 — Definite article 'the'

GR-PREP-TIME-001 — Prepositions of time

GR-MODAL-CAN-001 — Modal verb 'can'

Categories (104 rules total)

Category Count CEFR Levels
Tenses 24 A1-B2
Articles 12 A1-B1
Prepositions 18 A1-B2
Pronouns 10 A1-A2
Modals 15 A2-B2
Comparatives 8 A2-B1
Conditionals 9 B1-C1
Passive 8 B1-B2

API Reference (v0.2.0)

Authentication

POST /api/auth/login-password

Request: { first_name, last_name, password }

Response: { user_id, username, display_name, role, rating, cefr_level, token }

POST /api/admin/create-teacher

Header: X-Admin-Id: admin-001-...

Request: { first_name, last_name, password }

POST /api/teacher/create-learner

Header: X-Teacher-Id: teacher-001-...

Request: { first_name, last_name, password, cefr_level? }

Student Data

GET /api/teacher/{teacher_id}/students

Response: [{ id, username, display_name, role, cefr_level, is_online, ... }]

GET /api/student/{id}/vocabulary

Response: { student_id, total, mastered, unmastered, vocabulary: [...] }

POST /api/student/{id}/vocabulary/error

Request: { word, rule_id?, context? }

POST /api/student/{id}/vocabulary/correct

Request: { vocabulary_id } → Response: { correct_count, is_mastered }

Grammar Rules

GET /api/rules

Response: { total: 104, rules: [...] }

GET /api/rules/{id}

Response: { id, category, subcategory, name, description, cefr_level, examples }

GET /api/rules/level/{cefr}

Response: { cefr_level, count, rules: [...] }

Security Considerations

Passwords

  • bcrypt with cost factor 12
  • Never stored in plain text
  • Never logged or exposed

API Security

  • HTTPS via Nginx proxy
  • Admin ops require X-Admin-Id
  • Teacher ops validate created_by

Data Isolation

  • Teachers see only their students
  • Learners access only own data
  • Admin has global access

Deployment

Server (Google Cloud - Israel)

Host

35.252.21.14

Domain

api.yakki.app

Path

/home/baruch/yakki-intel

Service

yakki-intel.service (systemd)

Future Architecture (Flutter)

Parallel Client

yakki_flutter/
├── lib/
│   ├── api/      # Flutter API client
│   ├── models/   # Shared models
│   └── screens/  # iOS/Desktop UI
└── CLAUDE.md     # Flutter-specific docs

Shared Database

  • Same SQLite database on server
  • Same users table (teacher sees all platform students)
  • Separate API endpoints: /api/v1/flutter/*