How anujjha27/lattice works
Purpose and deployment
Lattice is a hosted personal learning platform: it maintains a user knowledge graph, ingests and retrieves sources, generates learning artifacts, and tracks review progress. It is a split application: Next.js web on Vercel, FastAPI plus worker on Render, and Supabase for PostgreSQL/pgvector, Auth, and private Storage.
Key runtime entry points are apps/api/app/main.py for the API, apps/api/app/jobs/runner.py for asynchronous work, and apps/web/app/page.tsx / apps/web/app/layout.tsx for the web application.
Web client and session boundary
The Next.js App Router frontend provides graph, library/discovery, pathway, review, and profile experiences. It uses Supabase browser/server clients for magic-link and Google OAuth; the callback route establishes the client session. The web calls the FastAPI service through a centralized API client and feature hooks.
Grounding paths:
• apps/web/app/auth/callback/route.ts
• apps/web/lib/api.ts
• apps/web/lib/supabase/client.ts
• apps/web/hooks/useBrain.ts
API composition, authentication, and persistence
FastAPI assembles domain routers and cross-cutting middleware. Protected requests carry Supabase JWTs; API-side auth verifies them and applies the production email allowlist. SQLAlchemy async models map the persistent learning domain, while Alembic owns schema evolution against Supabase Postgres.
Grounding paths:
• apps/api/app/main.py
• apps/api/app/api.py
• apps/api/app/core/auth.py
• apps/api/app/db/session.py
• apps/api/alembic/versions/0001_baseline.py
Knowledge graph and learner state
The central domain is a per-user concept graph with concepts, learning state, sources, and relationships. Graph construction and validation sit separately from API presentation. Brain endpoints expose this graph, while pathways turn graph state into sequenced learning plans. Reviews and quizzes write back learner progress/mastery signals.
Grounding paths:
• apps/api/app/domain/graph.py
• apps/api/app/db/models/concept.py
• apps/api/app/db/models/learning.py
• apps/api/app/modules/brain/service.py
• apps/api/app/modules/pathways/generator.py
Source ingestion and retrieval pipeline
Users submit URLs, notes, and potentially uploaded documents. The source subsystem classifies, extracts, deduplicates, ranks, chunks, and embeds content. Persisted source/chunk vectors support grounded lesson generation and retrieval; pgvector HNSW resides in Supabase. Discovery supplements user sources through web and academic providers.
Grounding paths:
• apps/api/app/modules/sources/routes.py
• apps/api/app/modules/sources/extraction.py
• apps/api/app/modules/sources/chunking.py
• apps/api/app/modules/retrieval/routes.py
• apps/api/app/providers/embedding.py
AI generation and external-provider boundary
Provider abstractions isolate model and search vendors from learning workflows. Gemini implements the primary LLM interface; Tavily, arXiv, and OpenAlex support discovery. Lessons use source context and citations; generated pathways, quizzes, recommendations, and the AI guide are exposed as module APIs rather than directly from the web client.
Grounding paths:
• apps/api/app/providers/llm.py
• apps/api/app/providers/gemini.py
• apps/api/app/providers/factory.py
• apps/api/app/modules/lessons/generator.py
• apps/api/app/providers/search.py
Background jobs and visual/profile assets
Long-running ingestion and portrait refresh work is persisted as jobs and processed by a Postgres-backed worker, separating API request latency from external calls and generation. Portraits combine learner analytics with visual assets; opt-in photos and uploads use a private Supabase Storage bucket. Visual-source ranking, rights handling, caching, and storage access form a separate asset boundary.
Grounding paths:
• apps/api/app/jobs/queue.py
• apps/api/app/jobs/handlers.py
• apps/api/app/db/models/job.py
• apps/api/app/modules/portrait/service.py
• apps/api/app/modules/visual_sources/service.py
• apps/api/app/providers/storage.py
Main entry points: main.py FastAPI application · extraction.py Source ingestion · session.py Postgres and pgvector · generator.py Pathway generator
Components 21
Web client
Next.js on Vercel.
- Next.js experiences · Graph, library, pathway, review, and profile UI.
apps/web/app/page.tsx - Session callback · Establishes magic-link or Google client session.
apps/web/app/auth/callback/route.ts - Supabase clients
apps/web/lib/supabase/client.ts - API client and hooks
apps/web/lib/api.ts
API and domain
FastAPI on Render.
- FastAPI application · Assembles routers and middleware.
apps/api/app/main.py - JWT authorization · Verifies Supabase JWTs and enforces the email allowlist.
apps/api/app/core/auth.py - Brain graph service · Exposes each learner's concept graph.
apps/api/app/modules/brain/service.py - Knowledge graph · Concepts, relationships, sources, and learner state.
apps/api/app/domain/graph.py - Pathway generator · Sequences graph state into learning plans.
apps/api/app/modules/pathways/generator.py - Lesson generation · Creates cited learning artifacts from retrieved context.
apps/api/app/modules/lessons/generator.py
Async content pipeline
Postgres-backed worker processes long-running work.
- Persistent job queue · Stores ingestion and portrait-refresh work.
apps/api/app/jobs/queue.py - Job handlers · Runs external calls and generation outside requests.
apps/api/app/jobs/handlers.py - Source ingestion · Classifies, extracts, deduplicates, ranks, and chunks submitted content.
apps/api/app/modules/sources/extraction.py - Retrieval API · Queries persisted source and chunk vectors.
apps/api/app/modules/retrieval/routes.py - Portrait and visual assets · Combines learner analytics, visual ranking, rights handling, and cached assets.
apps/api/app/modules/portrait/service.py
External providers
- LLM provider abstraction · Gemini is the primary implementation.
apps/api/app/providers/llm.py - Discovery providers · Tavily, arXiv, and OpenAlex supplement user sources.
apps/api/app/providers/search.py - Embedding provider
apps/api/app/providers/embedding.py
Supabase platform
Postgres with pgvector, Auth, and private Storage.
- Supabase Auth
- Postgres and pgvector · Stores learning domain, jobs, source chunks, and HNSW vectors.
apps/api/app/db/session.py - Private Storage · Holds opt-in photos and uploads.
apps/api/app/providers/storage.py
Connections 25
- Next.js experiences → Session callback: sign-in callback
- Session callback → Supabase clients: establishes session
- Supabase clients → Supabase Auth: OAuth and magic links
- Next.js experiences → API client and hooks: uses
- API client and hooks → FastAPI application: authenticated requests
- FastAPI application → JWT authorization: protects routes
- JWT authorization → Supabase Auth: verifies JWT
- FastAPI application → Brain graph service: brain endpoints
- Brain graph service → Knowledge graph: reads and validates
- Knowledge graph → Postgres and pgvector: persists learner graph
- Pathway generator → Knowledge graph: plans from graph state
- FastAPI application → Pathway generator: pathway APIs
- FastAPI application → Persistent job queue: enqueues long work
- Persistent job queue → Postgres and pgvector: stored in
- Persistent job queue → Job handlers: dispatches
- Job handlers → Source ingestion: runs
- Source ingestion → Embedding provider: embeds chunks
- Source ingestion → Postgres and pgvector: stores sources and vectors
- Retrieval API → Postgres and pgvector: vector search
- Lesson generation → Retrieval API: grounds on context
- Lesson generation → LLM provider abstraction: generates artifacts
- Pathway generator → LLM provider abstraction: generates plans
- Source ingestion → Discovery providers: discovers sources
- Job handlers → Portrait and visual assets: refreshes portraits
- Portrait and visual assets → Private Storage: reads and writes assets