CODE-GUIDE.md
A guided tour of the repository and where to find the code shown in the tutorial.
If you've watched the MongoDB tutorial, this guide will help you find the code behind each section of the project.
Rather than documenting every file, this guide focuses on the parts of the repository that illustrate the core ideas.
The repository is organized into a few major areas.
app/
lib/
tools/Each serves a different purpose.
| Directory | Purpose |
|---|---|
tools/ | Offline processing and command-line tools. |
lib/ | Shared application logic and MongoDB query pipelines. |
app/ | Next.js frontend and API routes. |
If you're following the tutorial, we'll move through these in roughly that order.
📺 Video: 4:44
Start here:
tools/process/This is where raw images become MongoDB documents.
The processing pipeline performs several steps:
The nice thing about this design is that every step has a single responsibility.
The first file worth opening is:
tools/process/config.jsThis controls things like:
Most of the project can be customized from here.
Next, look at:
tools/process/services/You'll find the different services responsible for talking to the language models.
Instead of mixing prompts throughout the application, they're isolated into their own files, making experimentation much easier.
Prompt engineering is an important part of the project.
Rather than hiding prompts inside the code, they're stored as separate files.
That gives you a few advantages:
See:
prompts/The accompanying PROMPTS.md document explains the philosophy behind them.
📺 Video: 8:33
Once metadata has been generated, everything revolves around MongoDB.
One of my goals was to avoid scattering information across multiple systems.
Every image becomes a single MongoDB document that gradually grows as more information is added.
Open:
lib/image/Most of the application logic starts here.
MongoDB Search is the first search capability added to the application.
Look at:
lib/image/queries/You'll find aggregation pipelines dedicated to keyword search.
Rather than placing aggregation logic directly inside API routes, the queries live in their own layer.
This makes them easier to test, easier to read, and easier to evolve.
📺 Video: 13:09
Embeddings are intentionally generated in a separate process.
Start with:
tools/process/generate-embeddings.jsThis script:
Separating this from image analysis means embeddings can always be regenerated later using a newer model.
📺 Video: 20:25
Hybrid search combines MongoDB Search with MongoDB Vector Search.
The interesting part isn't that both searches run.
The interesting part is how they're combined.
Look inside:
lib/image/queries/You'll see pipelines using MongoDB's $rankFusion stage to merge the results into a single ranked list.
This is where the application starts to feel much more natural.
The Next.js API routes stay intentionally thin.
Their primary job is to:
Keeping business logic inside lib/ makes the routes easy to follow.
See:
app/api/Finally, explore:
app/The frontend is intentionally simple.
Its purpose isn't to demonstrate React architecture.
Its purpose is to make it easy to experiment with the different search techniques.
That keeps the focus on MongoDB rather than UI complexity.
If you're exploring the repository for the first time, I'd recommend this order:
That mirrors the progression of the MongoDB tutorial and builds the project one concept at a time.