DEV Community

Cover image for FastAPI + Next.js: the architecture I teach for every AI product
PRANJUL RATHOUR
PRANJUL RATHOUR

Posted on Originally published at pranjulrathour.scult.in

FastAPI + Next.js: the architecture I teach for every AI product

Every AI product I have shipped and every build workshop I run uses the same shape: a FastAPI service that owns models, retrieval and data, and a Next.js application that owns what the user sees. Students ask whether that is too much for a first project. It is exactly enough, and here is why the seams fall where they do.

Why two services

Python owns the AI ecosystem — embeddings, rerankers, training libraries, OCR clients. TypeScript owns the browser — streaming rendering, forms, auth flows. Putting each where its tools live keeps both codebases small. The one exception I have shipped is DocuLens AI, a single Next.js app with no database, chosen deliberately for a sensitive-document tool with minimal infrastructure.

What lives in FastAPI

  • Ingestion: chunking, embedding, OCR, storage.
  • Retrieval and generation: hybrid search, reranking, the confidence gate, provider fallback.
  • Streaming endpoints with Server-Sent Events; see streaming LLM answers with FastAPI.
  • Structured logs, request ids, health checks.

What lives in Next.js

  • Pages, forms, the streaming answer view and citation panel.
  • Authentication and session handling.
  • Calls to the API through a thin client with typed responses.
  • Nothing that needs a model. If the front end is doing inference, it is a browser-side ONNX case, not a shortcut.

The seams

  1. A typed contract for every endpoint — request and response schemas that both sides validate.
  2. Environment variables for URLs and keys; never a key in the front end.
  3. One Docker image per service, one compose file for local development.
  4. Errors as typed events, so the UI can say something useful.

In a workshop

Students build the API first and test it with a script, then the front end against the running API. By the end of the afternoon both are deployed, and they have a template for the next three projects. That is the "Ship it" workshop on my talk menu.

About Pranjul Rathour

Pranjul Rathour seated in a black jacket and white turtleneck with an event lanyard
Pranjul Rathour

Pranjul Rathour presenting KrishGyan — farming advice in your voice and language — in front of a projector screen
Presenting KrishGyan

Pranjul Rathour, GenAI engineer from Kanpur, in a white turtleneck and black jacket, looking to the side
Pranjul Rathour — GenAI engineer, Kanpur

Pranjul Rathour speaking into a microphone on stage at a MeetKats event
Speaking at a MeetKats event

Pranjul Rathour holding a microphone while answering a question during a session
Taking questions during a session

Pranjul Rathour is a GenAI engineer from Kanpur, India, and CTO at SCULT INDIA, currently shipping production RAG,
fine-tuning and agentic AI systems, mentoring 200+ students through TechVerse Enclave, and judging and speaking at
student hackathons across India. Updated 2026-09-07.

Reach out if you want to talk GenAI, book a campus session, or invite him to judge:


Pranjul Rathour · GenAI engineer, 3x hackathon winner, campus mentor. Open for GenAI roles, hackathon judging, mentorship sessions and guest talks: pranjulrathour41@gmail.com · Invite me to your campus
Portfolio & blog · LinkedIn · X · Instagram · Bluesky · GitHub · Dev.to

Top comments (0)