# lecoeurdelest/memeradar architecture

> Architecture diagram of the GitHub repository lecoeurdelest/memeradar, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lecoeurdelest/memeradar
- Repository: https://github.com/lecoeurdelest/memeradar

## Overview

1. **Overall shape**
   - MemeRadar is a two-tier system: a Python backend API plus a React/Vite frontend.
   - The backend is not just request handling; it also owns ingestion, enrichment, and batch analytics that populate the search indexes and graph store.
   - The main architectural boundary is between the **online query path** and the **offline data/metric pipelines**.

2. **Frontend subsystem**
   - `frontend/` is a Vite-built SPA (`App.jsx`, `main.jsx`, `components/MutationRadar.jsx`).
   - It talks to the backend over HTTP via `frontend/src/api.js`.
   - The UI appears to center on search/browse plus a mutation visualization panel, with the same backend powering both interactive search and graph/mutation views.

3. **API and application runtime**
   - `backend/main.py` is the FastAPI entry point.
   - The backend exposes at least:
     - `/health`
     - `/search`
     - `/mutations`
   - This makes the backend the orchestration layer that joins vector search results, metadata, and graph lineage into a single response for the UI.

4. **Persistence and retrieval stores**
   - The system uses **Qdrant** as the vector store and **Neo4j** as the graph store, configured through `backend/clients.py` and `backend/config.py`.
   - Qdrant holds searchable meme points and probably named vectors for multimodal retrieval.
   - Neo4j holds relationship/lineage structure, especially template/member ancestry and enrichment data used by the “lineage panel.”

5. **External model/service dependencies**
   - The backend depends on outside AI services for core enrichment:
     - **Twelve Labs** for video/image retrieval embeddings or multimodal representations.
     - **Mistral** for caption/decoder/enrichment generation and embeddings used for irony/semantic signals.
   - These are not incidental; they materially define the multimodal ranking and enrichment pipeline.
   - `backend/decoder.py`, `backend/translate.py`, and `backend/enrich_cognee.py` suggest distinct AI-assisted transformation steps rather than a single monolithic model call.

6. **Offline ingestion pipeline**
   - `scripts/crawl_reddit.py` pulls candidate meme posts from Reddit.
   - `backend/ingest.py` then processes that data into the system’s stores, likely extracting media, metadata, and embeddings before inserting into Qdrant and Neo4j.
   - The ingestion flow is intentionally staged: crawl first, ingest second, then enrich, which keeps source collection separate from index materialization.

7. **Data normalization and asset storage**
   - The `data/` directory contains committed snapshot datasets such as `imgflip_memes.json` and `knowyourmeme_latest/`.
   - This suggests the repo supports both live crawling and reproducible local corpora for development/testing.
   - `backend/storage.py` and `backend/mutation.py` imply local file/data management alongside datastore writes, with `DATA_DIR` as the filesystem boundary.

8. **Search fusion and ranking**
   - `backend/search.py` and `scripts/rrf_sweep.py` indicate the search engine combines multiple relevance signals, likely through reciprocal-rank fusion or a similar weighted blend.
   - The README’s visual/irony slider confirms the user can tune the balance between visual similarity and semantic/ironic relevance.
   - This is the key online ranking boundary: the API merges outputs from different retrieval dimensions before returning a unified result set.

9. **Graph lineage and semantic enrichment**
   - `backend/enrich_cognee.py` and the Neo4j dependency point to a graph-enrichment layer that turns raw meme records into connected templates, variants, and related nodes.
   - The “lineage panel” in the demo implies each search result can be expanded into its graph neighborhood, not just retrieved as an isolated item.
   - This graph layer is a separate concern from vector search; it provides explainability and meme-family structure.

10. **Mutation analytics as a batch subsystem**
   - `scripts/compute_mutation_metrics.py` computes template drift, centroid behavior, and a `trending_mutation` flag.
   - The README makes clear this is a decoupled batch job: it writes summary metrics to Neo4j/Qdrant but is not on the hot search path.
   - That separation matters architecturally because the online API reads precomputed mutation state instead of performing dense-vector analytics during search.

11. **Operational/tooling boundary**
   - The repo is designed for local native runtimes, not containers: Python via `uv`, Node via npm/Vite, plus running Qdrant and Neo4j as separate services.
   - Startup scripts (`start.sh`, `start.ps1`) package the backend launch and optional frontend build, but datastore processes remain distinct.
   - This means the architecture diagram should show at least four runtime nodes: frontend dev server, FastAPI backend, Qdrant, and Neo4j.

12. **How the main data flows connect**
   - Source data comes from Reddit and committed datasets into the ingestion pipeline.
   - Ingestion/enrichment populates Qdrant for retrieval and Neo4j for lineage/relationships.
   - The frontend queries FastAPI; FastAPI performs fused retrieval against Qdrant, enriches/joins with graph data from Neo4j, and returns ranked results.
   - Batch mutation analytics periodically update drift-related fields, which the API reads directly when serving mutation views.

Main entry points: [`backend/ingest.py`](https://github.com/lecoeurdelest/memeradar/blob/main/backend/ingest.py) (Ingest flow), [`backend/clients.py`](https://github.com/lecoeurdelest/memeradar/blob/main/backend/clients.py) (Store clients), [`backend/main.py`](https://github.com/lecoeurdelest/memeradar/blob/main/backend/main.py) (FastAPI app), [`backend/search.py`](https://github.com/lecoeurdelest/memeradar/blob/main/backend/search.py) (Search fusion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["UI shell<br/>Vite SPA<br/>[App.jsx]"]
  node_frontend_api["API client<br/>HTTP client<br/>[api.js]"]
  node_frontend_mutation["Mutation radar<br/>visualization<br/>[MutationRadar.jsx]"]
end

subgraph group_backend["Backend"]
  node_backend_main["FastAPI app<br/>API runtime<br/>[main.py]"]
  node_backend_search{{"Search fusion<br/>ranking<br/>[search.py]"}}
  node_backend_ingest["Ingest flow<br/>indexing pipeline<br/>[ingest.py]"]
  node_backend_enrich{{"Graph enrich<br/>semantic enrichment<br/>[enrich_cognee.py]"}}
  node_backend_mutation{{"Mutation metrics<br/>batch analytics<br/>[mutation.py]"}}
  node_backend_clients["Store clients<br/>connectors<br/>[clients.py]"]
  node_backend_config["Config<br/>[config.py]"]
  node_backend_storage["Storage<br/>filesystem boundary<br/>[storage.py]"]
  node_backend_decoder["Decoder<br/>AI transform<br/>[decoder.py]"]
  node_backend_translate["Translate<br/>AI transform<br/>[translate.py]"]
end

subgraph group_stores["Stores"]
  node_qdrant[("Qdrant<br/>vector store")]
  node_neo4j[("Neo4j<br/>graph store")]
end

subgraph group_pipelines["Pipelines"]
  node_reddit["Reddit crawl<br/>source ingest<br/>[crawl_reddit.py]"]
  node_mutation_batch["Metric batch<br/>offline job"]
  node_rrf_sweep["RRF sweep<br/>evaluation job<br/>[rrf_sweep.py]"]
end

subgraph group_data["Data"]
  node_dataset["Meme corpus<br/>snapshot data<br/>[index.json]"]
end

node_frontend_api -->|"HTTP"| node_backend_main
node_frontend_app -->|"uses"| node_frontend_api
node_frontend_app -->|"renders"| node_frontend_mutation
node_backend_main -->|"search"| node_backend_search
node_backend_main -->|"mutations"| node_backend_enrich
node_backend_search -->|"retrieves"| node_backend_clients
node_backend_enrich -->|"writes/reads"| node_backend_clients
node_backend_ingest -->|"assets"| node_backend_storage
node_backend_ingest -->|"indexes"| node_backend_clients
node_backend_decoder -->|"feeds"| node_backend_ingest
node_backend_translate -->|"feeds"| node_backend_ingest
node_backend_mutation -->|"updates"| node_neo4j
node_backend_mutation -->|"updates"| node_qdrant
node_backend_clients -->|"connects"| node_qdrant
node_backend_clients -->|"connects"| node_neo4j
node_backend_config -->|"configures"| node_backend_clients
node_reddit -->|"source"| node_backend_ingest
node_dataset -->|"seed data"| node_backend_ingest
node_mutation_batch -->|"writes"| node_neo4j
node_rrf_sweep -.->|"tunes"| node_backend_search

click node_frontend_app "https://github.com/lecoeurdelest/memeradar/blob/main/frontend/src/App.jsx"
click node_frontend_api "https://github.com/lecoeurdelest/memeradar/blob/main/frontend/src/api.js"
click node_frontend_mutation "https://github.com/lecoeurdelest/memeradar/blob/main/frontend/src/components/MutationRadar.jsx"
click node_backend_main "https://github.com/lecoeurdelest/memeradar/blob/main/backend/main.py"
click node_backend_search "https://github.com/lecoeurdelest/memeradar/blob/main/backend/search.py"
click node_backend_ingest "https://github.com/lecoeurdelest/memeradar/blob/main/backend/ingest.py"
click node_backend_enrich "https://github.com/lecoeurdelest/memeradar/blob/main/backend/enrich_cognee.py"
click node_backend_mutation "https://github.com/lecoeurdelest/memeradar/blob/main/backend/mutation.py"
click node_backend_clients "https://github.com/lecoeurdelest/memeradar/blob/main/backend/clients.py"
click node_backend_config "https://github.com/lecoeurdelest/memeradar/blob/main/backend/config.py"
click node_backend_storage "https://github.com/lecoeurdelest/memeradar/blob/main/backend/storage.py"
click node_backend_decoder "https://github.com/lecoeurdelest/memeradar/blob/main/backend/decoder.py"
click node_backend_translate "https://github.com/lecoeurdelest/memeradar/blob/main/backend/translate.py"
click node_reddit "https://github.com/lecoeurdelest/memeradar/blob/main/scripts/crawl_reddit.py"
click node_mutation_batch "https://github.com/lecoeurdelest/memeradar/blob/main/scripts/compute_mutation_metrics.py"
click node_rrf_sweep "https://github.com/lecoeurdelest/memeradar/blob/main/scripts/rrf_sweep.py"
click node_dataset "https://github.com/lecoeurdelest/memeradar/blob/main/data/knowyourmeme_latest/index.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_app,node_frontend_api,node_frontend_mutation toneBlue
class node_backend_main,node_backend_search,node_backend_ingest,node_backend_enrich,node_backend_mutation,node_backend_clients,node_backend_config,node_backend_storage,node_backend_decoder,node_backend_translate toneAmber
class node_qdrant,node_neo4j toneMint
class node_reddit,node_mutation_batch,node_rrf_sweep toneRose
class node_dataset toneIndigo
```

## Components

### Frontend

React/Vite SPA for search and mutation visualization

- [UI shell](https://github.com/lecoeurdelest/memeradar/blob/main/frontend/src/App.jsx): Vite SPA · Main React app entry and page composition · `frontend/src/App.jsx`
- [API client](https://github.com/lecoeurdelest/memeradar/blob/main/frontend/src/api.js): HTTP client · Browser-side backend requests and result loading · `frontend/src/api.js`
- [Mutation radar](https://github.com/lecoeurdelest/memeradar/blob/main/frontend/src/components/MutationRadar.jsx): visualization · Mutation and lineage panel in the UI · `frontend/src/components/MutationRadar.jsx`

### Backend

FastAPI API plus retrieval, enrichment, and ingestion logic

- [FastAPI app](https://github.com/lecoeurdelest/memeradar/blob/main/backend/main.py): API runtime · HTTP entry point exposing health, search, and mutation routes · `backend/main.py`
- [Search fusion](https://github.com/lecoeurdelest/memeradar/blob/main/backend/search.py): ranking · Combines multimodal retrieval signals and tunes relevance mix · `backend/search.py`
- [Ingest flow](https://github.com/lecoeurdelest/memeradar/blob/main/backend/ingest.py): indexing pipeline · Materializes crawled data into retrieval and graph stores · `backend/ingest.py`
- [Graph enrich](https://github.com/lecoeurdelest/memeradar/blob/main/backend/enrich_cognee.py): semantic enrichment · Builds lineage and relationship data for meme families · `backend/enrich_cognee.py`
- [Mutation metrics](https://github.com/lecoeurdelest/memeradar/blob/main/backend/mutation.py): batch analytics · Computes drift and trending mutation signals · `backend/mutation.py`
- [Store clients](https://github.com/lecoeurdelest/memeradar/blob/main/backend/clients.py): connectors · Qdrant and Neo4j client setup · `backend/clients.py`
- [Config](https://github.com/lecoeurdelest/memeradar/blob/main/backend/config.py): runtime config · Service credentials, endpoints, and environment settings · `backend/config.py`
- [Storage](https://github.com/lecoeurdelest/memeradar/blob/main/backend/storage.py): filesystem boundary · Local data directory and asset handling · `backend/storage.py`
- [Decoder](https://github.com/lecoeurdelest/memeradar/blob/main/backend/decoder.py): AI transform · Model-assisted decoding and caption transformations · `backend/decoder.py`
- [Translate](https://github.com/lecoeurdelest/memeradar/blob/main/backend/translate.py): AI transform · Caption and language transformation step · `backend/translate.py`

### Stores

External persistence and retrieval systems

- **Qdrant**: vector store · Multimodal search index for meme points
- **Neo4j**: graph store · Lineage, relationships, and mutation-linked graph data

### Pipelines

Offline crawl, ingest, and analytics jobs

- [Reddit crawl](https://github.com/lecoeurdelest/memeradar/blob/main/scripts/crawl_reddit.py): source ingest · Candidate meme collection from Reddit · `scripts/crawl_reddit.py`
- [Metric batch](https://github.com/lecoeurdelest/memeradar/blob/main/scripts/compute_mutation_metrics.py): offline job · Scheduled computation of template drift and trend flags · `scripts/compute_mutation_metrics.py`
- [RRF sweep](https://github.com/lecoeurdelest/memeradar/blob/main/scripts/rrf_sweep.py): evaluation job · Search ranking sweep for fusion tuning · `scripts/rrf_sweep.py`

### Data

Committed meme corpora and snapshots

- [Meme corpus](https://github.com/lecoeurdelest/memeradar/blob/main/data/knowyourmeme_latest/index.json): snapshot data · Committed meme and knowledge-base snapshots · `data/knowyourmeme_latest/index.json`

## Connections

- API client → FastAPI app: HTTP · Frontend queries the FastAPI application
- UI shell → API client: uses · UI delegates data fetching to the client module
- UI shell → Mutation radar: renders · Mutation panel is part of the SPA
- FastAPI app → Search fusion: search · Search endpoint delegates ranking and retrieval fusion
- FastAPI app → Graph enrich: mutations · Mutation views join graph lineage and enrichment data
- Search fusion → Store clients: retrieves · Search uses store clients for vector and graph lookups
- Graph enrich → Store clients: writes/reads · Graph enrichment persists and reads relationship data
- Ingest flow → Storage: assets · Ingest reads local snapshots and media boundaries
- Ingest flow → Store clients: indexes · Ingest writes searchable content and graph nodes
- Decoder → Ingest flow: feeds · Decoder contributes transformed content to ingestion
- Translate → Ingest flow: feeds · Translation step contributes normalized text to ingestion
- Mutation metrics → Neo4j: updates · Batch analytics writes trend and drift metrics to graph store
- Mutation metrics → Qdrant: updates · Batch analytics may annotate retrieval records with mutation state
- Store clients → Qdrant: connects · Vector store client for multimodal retrieval
- Store clients → Neo4j: connects · Graph store client for lineage and relationships
- Config → Store clients: configures · Configuration supplies service endpoints and credentials
- Reddit crawl → Ingest flow: source · Crawled Reddit posts flow into ingestion
- Meme corpus → Ingest flow: seed data · Committed corpora support reproducible local ingestion
- Metric batch → Neo4j: writes · Offline mutation metrics are materialized into graph data
- RRF sweep → Search fusion: tunes · Ranking sweep informs fusion weighting and relevance behavior
