System Design

Architecture

NutriShastho AI uses a Next.js frontend, FastAPI backend, Neon/Postgres database, and an MCP server for AI tool orchestration.

Key Points

Next.js owns user experience, sessions, and AI-facing API routes.

FastAPI owns authentication, data validation, and database writes.

FastMCP exposes health, nutrition, and exercise tools over Streamable HTTP.

1

Request Flow

The browser talks to Next.js pages and API routes. Authenticated Next.js API routes forward bearer-token requests to the FastAPI backend. AI routes may also call the MCP server for tool-based intelligence.

Browser -> Next.js App Router pages.

Next.js API routes -> FastAPI backend.

Next.js AI routes -> MCP server -> backend and AI providers.

FastAPI -> Neon/Postgres through SQLAlchemy.

2

Service Boundaries

The frontend avoids direct database access. The backend is the trusted persistence layer. The MCP server handles AI tools and remote health-intelligence workflows.

Frontend: UI, session cookie, dashboard pages, public documentation.

Backend: auth, users, health profiles, budgets, exercise plans, food, clinics.

MCP: tool calls for food search, clinic search, health guidance, and exercise generation.

3

Deployment Shape

A free-first deployment can run the frontend on Vercel, backend on Render or Railway, MCP on Hugging Face Spaces or Render, and database on Neon.