POST /admin/upload-curriculum now creates a documents record on success.
[2026-02-17] - Architecture Fix: Service Layer Consolidation
Supabase Key Cleanup
RemovedSUPABASE_ANON_KEY and SUPABASE_KEY from config and entire codebase.
Standard: All backend operations now use SUPABASE_SERVICE_ROLE_KEY exclusively.
Removedget_user_client() and get_supabase_client() from auth.py.
Auth/Me/Scraping/Admin routers now use supabase_service singleton from dependencies.py.
Teacher Agent Rewrite
Replaced old wallet.*, retrieval.*, supabase_store.* calls with new service layer.
Billing: Agent now uses wallet_service.reserve() / wallet_service.finalize() (atomic reservation pattern).
Retrieval: Agent now uses retrieval_pipeline.retrieve() instead of old retrieval.retrieve_context().
Logging: Usage logged directly via supabase_service instead of old supabase_store.log_usage().
State: Added reservation_id field to TeacherState.
Chat Router
Replacedfrom app.services import llm, wallet, supabase_store with from app.services.llm import generate_answer.
Added reservation_id to initial agent state.
Admin Ingestion
New endpoint:POST /admin/ingest/{reference_id} - Downloads PDF from URL, chunks, embeds, upserts to Pinecone.
Replaced old pdf_processor, embeddings, pinecone_store, supabase_references imports with embedding_service, pinecone_adapter, supabase_service from dependencies.py.
Legacy:POST /admin/vector-embedding kept as redirect to new endpoint.
Scraping Router
Replacedsupabase_references.* function imports with inline functions using supabase_service directly.
No dependency on old supabase_references.py module.
Wallet: Transactions & Top-Up
New migration:20260217000020_transactions.sql - Financial transactions table for real-money tracking.
New models:TopUpRequest, ExpenseRequest, TransactionResponse, TopUpResponse, TransactionListResponse.
New endpoints:POST /wallet/topup, POST /wallet/transactions/expense, GET /wallet/transactions.
WalletReservationService: Added topup() method and calculate_output_cost() static method.
Cleanup: Deleted Files
Old services (7):wallet.py, supabase_store.py, supabase_references.py, retrieval.py, embeddings.py, pinecone_store.py, reranker.py