How ameyasingh23/inline_explainer works
1. Repository shape
- This is a two-app monorepo: apps/web is the Next.js frontend and apps/api is the FastAPI backend.
- The project is centered on one workflow: a user submits a public repo URL, the backend analyzes the repo structure, and the frontend presents an IDE-like workspace with code, explanations, and chat.
2. Frontend boundary: workspace and presentation
- apps/web owns all browser UX: landing page, GitHub login, repo workspace, profile/account pages, privacy/terms.
- The main architecture surface is the workspace route app/(workspace)/[owner]/[repo], which renders a file tree, code viewer, explanation panel, and chat tray side by side.
- WorkspaceShell, FileTree, CodePanel, ExplanationPanel, and ChatTray are the core UI composition units.
3. Frontend state and session management
- Supabase is used on the web side for auth/session handling via lib/supabase/client.ts, lib/supabase/server.ts, and middleware.ts.
- useChatSession.ts owns chat session state, streaming message handling, and persistence across reloads.
- The browser also performs some direct data access patterns, such as loading repo/file structure and auth state, while the backend handles analysis and AI generation.
4. Backend boundary: analysis, explanation, and chat
- apps/api is the authoritative service for repo ingestion, graph extraction, explanation generation, chat responses, user profile/repo listing, and account deletion.
- The backend is split into routers by concern: ingest.py, explain.py, chat.py, and user.py.
- Shared cross-cutting concerns live in core/: config loading, JWT auth verification, rate limiting, and Supabase access.
5. Repo ingestion pipeline
- POST /api/ingest is the backend entry point for analyzing a public repository.
- repo_service.py clones the repo with GitPython, validates it, and runs Graphify/tree-sitter extraction to build a code graph.
- That graph is stored in Supabase as graph_json on the repositories record, along with repository metadata and processing status.
- This is the system’s main offline-like processing step, but it happens on demand through the API.
6. Explanation pipeline
- POST /api/explain generates a file-level explanation as a streaming SSE response.
- The backend combines the target file with connected graph context: imports, callers, callees, and nearby related files.
- Explanations are persisted in Supabase so revisiting a file can load cached output immediately without re-running the model.
7. Chat pipeline
- POST /api/chat is the conversational interface for follow-up questions.
- The frontend supports two chat scopes: repo-level chat and file-level chat.
- Repo chat uses repository context such as README and file tree; file chat uses the selected file code, its explanation, and optional selected text from the editor or explanation panel.
- GET /api/chat/session restores persisted conversation history for a file.
8. Data model and persistence boundary
- Supabase Postgres is the main persistent store for repositories, explanations, chat_sessions, and users.
- repositories stores repo identity plus the extracted graph.
- explanations caches generated explanations per repository/file.
- chat_sessions stores message history keyed by repository and file.
- users links app identity to Supabase Auth users and GitHub identity.
9. Authentication and trust model
- GitHub OAuth is handled through Supabase Auth on the frontend.
- The backend does not share auth secrets with the frontend; it verifies Supabase JWTs using JWKS in core/auth.py.
- Every backend endpoint in the main API path expects a bearer token, which makes the browser-to-backend and backend-to-Supabase trust boundaries explicit.
10. Model/provider layer
- The backend routes LLM requests through a multi-provider waterfall router.
- The repository design mentions Groq, Google Gemini, and NVIDIA NIM as fallback providers.
- This provider abstraction matters architecturally because the frontend never talks directly to model APIs; all model selection and fallback behavior stays behind the backend.
11. Cross-cutting controls
- core/rate_limiter.py applies per-user, per-endpoint limits with different caps for ingest, explain, and chat.
- Cache hits do not count against rate limits, which means the system distinguishes expensive generation from cheap retrieval.
- psutil is used during ingestion to monitor memory use, reflecting that repo analysis is the most resource-sensitive backend path.
12. External integrations and deployment
- Supabase provides auth, Postgres, and likely row-level security for user data.
- The frontend is designed for Vercel deployment, while the backend is designed for Render.
- The browser also relies on GitHub’s public repository APIs for file tree navigation in the workspace.
- A health endpoint exists to support uptime/cold-start mitigation for the backend.
13. What to show in an architecture diagram
- The clearest diagram should separate: browser/UI, FastAPI API, Supabase, and external model/repo services.
- The key flows are:
- login/session via Supabase Auth,
- repo ingest from browser to backend to Supabase,
- file explanation from browser to backend to LLM provider to Supabase cache,
- chat from browser to backend to LLM provider with persisted session state in Supabase.
- The central architectural idea is that the frontend is a thin interactive workspace, while the backend owns analysis, caching, auth verification, and all AI calls.
Main entry points: WorkspaceShell.tsx WorkspaceShell · explain.py Explain router · chat.py Chat router · main.py FastAPI app
Components 22
Web App
Next.js frontend for auth, workspace, and account UX
- Home · Landing entry for the app
apps/web/app/page.tsx - Login · GitHub sign-in entry
apps/web/app/(auth)/login/page.tsx - Workspace · Main repo workspace view
apps/web/app/(workspace)/[owner]/[repo]/page.tsx - WorkspaceShell · Coordinates the split-pane workspace
apps/web/components/workspace/WorkspaceShell.tsx - FileTree · Shows repository structure and file selection
apps/web/components/workspace/FileTree.tsx - CodePanel · Displays source code and selections
apps/web/components/workspace/CodePanel.tsx - ExplanationPanel · Renders file explanations and cached content
apps/web/components/workspace/ExplanationPanel.tsx - ChatTray · Repo and file scoped chat interface
apps/web/components/workspace/ChatTray.tsx - useChatSession · Streams and persists chat history
apps/web/hooks/useChatSession.ts - Supabase client · Browser session and middleware auth plumbing
apps/web/lib/supabase/client.ts - Supabase server · Server-side auth/session helpers
apps/web/lib/supabase/server.ts - Middleware · Protects workspace and session routes
apps/web/middleware.ts
API Service
FastAPI backend for ingestion, explanation, chat, and user data
- FastAPI app · API application wiring and startup
apps/api/main.py - Ingest router · Public repo analysis endpoint
apps/api/routers/ingest.py - Explain router · Streaming file explanation endpoint
apps/api/routers/explain.py - Chat router · Repo and file chat endpoints
apps/api/routers/chat.py - User router · Profile, repo listing, and account deletion
apps/api/routers/user.py - Repo service · Clones, validates, and builds code graphs
apps/api/services/repo_service.py - Core controls · JWT verification, rate limits, config, and Supabase access
apps/api/core
External Services
Auth, storage, source repos, and model providers
- Supabase · Auth, Postgres storage, and cached app data
- GitHub · Public repositories used for ingestion and file navigation
- LLM providers · Fallback generation providers for explanations and chat
Connections 30
- Home → Login: sign in · Users move from landing to authentication
- Login → Supabase client: start session · Client-side Supabase auth flow
- Supabase server → Supabase: session lookup · Server-side session validation and user data access
- Middleware → Supabase client: gate routes · Protects authenticated workspace pages
- Workspace → WorkspaceShell: compose · Workspace page renders the main shell
- WorkspaceShell → FileTree: layout · File tree occupies the navigation pane
- WorkspaceShell → CodePanel: layout · Code viewer occupies the editor pane
- WorkspaceShell → ExplanationPanel: layout · Explanation panel sits beside code
- WorkspaceShell → ChatTray: layout · Chat tray anchors the conversation area
- ChatTray → useChatSession: state · Chat UI delegates session persistence and streaming
- Workspace → Ingest router: analyze repo · Workspace triggers repository ingestion when needed
- Workspace → Explain router: explain file · Workspace requests file explanations
- ChatTray → Chat router: ask · Chat UI sends repo or file scoped prompts
- FileTree → GitHub: browse source · Browser uses public GitHub data for navigation
- FastAPI app → Ingest router: mount · Registers the ingest router
- FastAPI app → Explain router: mount · Registers the explain router
- FastAPI app → Chat router: mount · Registers the chat router
- FastAPI app → User router: mount · Registers the user router
- Ingest router → Repo service: pipeline · Ingest delegates clone and graph extraction
- Ingest router → Core controls: guard · Applies auth, config, and rate limits
- Explain router → Core controls: guard · Uses shared auth and rate-limit controls
- Chat router → Core controls: guard · Uses shared auth and rate-limit controls
- User router → Core controls: guard · Uses shared auth and data access helpers
- Repo service → GitHub: clone · Fetches public repositories for analysis
- Repo service → Supabase: store graph · Persists repository metadata and graph JSON
- Explain router → LLM providers: generate · Streams file explanations from model providers
- Chat router → LLM providers: respond · Generates conversational answers through provider fallback
- Explain router → Supabase: cache · Caches generated explanations for reuse
- Chat router → Supabase: session store · Persists and restores chat history
- User router → Supabase: profiles · Reads and updates user and repository records