Sefism is free for learners. We are here to help you grow, one step at a time.Join for free
Sefism.

Project structure · AI and ML

GenAI RAG app (FastAPI) project structure

Opens with credits

For developers turning a "chat with your documents" demo into an app people can rely on. A FastAPI backend where every layer has a home: ingestion workers, retrieval, prompts as versioned files, model clients with fallbacks and cost caps, guards, evals that gate CI, and tracing, so a wrong answer can be traced to the step that caused it.

Curated by Tauseef FayyazIntermediate229 files and foldersPython 3.14, FastAPI 0.142, Pydantic 2.13Checked October 2026
Explore the filesPick any file to see what it is, why it exists and when you add it.

How it grows

Each stage opens the explorer there

  1. 1Day 1What the scaffold and your first hour give you19 files and folders
  2. 2GrowingWhat a real app with features and tests adds+107 files and folders
  3. ProductionWhat running it for real users adds+62 files and foldersOpens with credits
  4. ExpertWhat a team needs to keep it healthy for years+41 files and foldersOpens with credits

How it is organised

  • One folder per layer of the request: api (HTTP), services (business rules), db (Postgres rows), rag (find the right text), llm (talk to models), guards (check what goes in and out), observability (see what happened). A route never calls a model SDK directly.
  • The orchestrator (`rag/answer.py`) lives outside the routes, so the API, the eval runner and the load test all call the exact same function.
  • Prompts are files with a version in the name, listed in one manifest, reviewed like code and logged with every answer, so any answer can be traced to the exact prompt text.
  • Ingestion is a separate path from answering: documents are parsed, chunked and embedded by a background worker, never inside a chat request.
  • Evals live in the repo next to the prompts they test and gate CI whenever prompts, retrieval or models change. Unit tests never call a real model.
  • Model ids, thresholds, prices and limits come from typed config read from the environment; switching a model never needs a code change. Permissions are enforced in code and in the retrieval query, never only in the prompt.
  • Start as one FastAPI service plus one worker with clear folders, and enforce the layer rules with import-linter once the team grows. Split into separate services only when a part needs to scale or deploy on its own.

At the top of the project

Open one in the explorer for the full story

Learn more on Sefism

Roadmaps, cheat sheets and projects that go with GenAI RAG app (FastAPI).

See 11 more
Checked against 15 official sources, October 2026. If something has changed, the docs win.Show sources

Picked from the other libraries by shared topics.

Work with me

Stuck on something specific?

Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.

  • 1:1 Mentorship
  • Fresh Graduate Mentorship
  • Career Guidance

Brand deals, promos and partnerships: tauseeffayyaz@gmail.com