How bitcrowd/exmeralda works
Project type and purpose
• Exmeralda is a full-stack Phoenix web application (Phoenix LiveView + Ecto) that lets users chat with documentation-style “libraries” using LLM embeddings (pgvector + external AI APIs).
• Key features: user accounts, chat sessions, embedding generation, background workers (Oban), Postgres with pgvector, multiple LLM sources (Groq, Jina, Ollama), and email notifications.
File structure for architectural clues
• Top-level directories:
• assets (JS/Tailwind CSS/front-end build)
• lib/exmeralda (contexts: accounts, chats, topics, repo, mailer)
• lib/exmeralda_web (Phoenix endpoint, LiveView, controllers, components)
• priv/repo (Postgres migrations, seeds)
• rel (release scripts for Docker/Fly.io)
• Config files for Oban, Tailwind, esbuild, Phoenix endpoint, mailer, database, and runtime environments
• Background jobs under lib/exmeralda/topics/*_worker.ex
Main components of the system
a. Frontend (Web Browser / Static Assets)
• assets/js/app.js, assets/css, Phoenix LiveView templates (HEEx)
• Served via Phoenix.Endpoint → static plug & LiveView WebSocket
b. Phoenix Web Server
• Endpoint (lib/exmeralda_web/endpoint.ex) handles HTTP/WS
• Router → Controllers & LiveViews (lib/exmeralda_web/controllers, lib/exmeralda_web/live)
c. Application Contexts (Hexagonal / “Domain” layer)
• Accounts (user registration & auth)
• Chats (chat sessions, messages, LLM orchestration)
• Topics (library ingestion, chunking, embeddings, vector search)
• Mailer (email delivery via external SMTP/API)
d. Persistence
• Ecto Repo (lib/exmeralda/repo.ex) → Postgres with pgvector extension
• Migrations & seeds under priv/repo
e. Background Processing
• Oban job queue (config/oban.ex)
• Workers: generate_embeddings_worker, ingest_library_worker, etc.
f. External Services
• AI Embedding & LLM APIs (Groq, Jina, Ollama CLI)
• Email provider (SMTP/API)
• Docker & Fly.io for deployment
Relationships and interactions
1. Browser ↔ Phoenix.Endpoint (HTTP & LiveView WS)
2. Endpoint → Router → Controller/LiveView → Context functions
3. Contexts → Ecto.Repo → Postgres DB
4. Contexts → Oban.enqueue → Worker processes
5. Workers → External LLM/Embedding APIs → Contexts → Repo
6. Contexts → Mailer → External Email API
Architectural patterns & design principles
• MVC + Phoenix LiveView for reactive UI
• Hexagonal/Layered architecture: Web adapters (lib/exmeralda_web) ↔ Domain contexts ↔ Infrastructure (Ecto, Oban, external APIs)
• Asynchronous processing via Oban for long-running tasks (embeddings, ingestion)
• Separation of concerns: authentication, chat messaging, topic ingest/search, and mailing all live in distinct contexts.
Elements
• Blue for UI/Web (assets, LiveView)
• Green for Domain Contexts
• Orange for Data stores (Postgres, vector store)
• Purple for External services/APIs
Final checklist
• Verify all contexts and their interactions are shown
• Background jobs and vector search path
• Call out LLM providers as external dependencies
• Environment/deployment artifacts (Docker, Fly.toml) at the periphery if desired