How ritam-05/finmate-ai-powered-financial-advisor works
1. High-level shape
This repo is a two-tier product: a Next.js frontend deployed on Vercel and a FastAPI backend deployed on Hugging Face Spaces. The frontend owns all user interaction and local persistence; the backend owns LLM calls and response normalization.
2. Frontend application shell
The frontend uses the Next.js App Router under src/app. There are two route groups:
- src/app/(marketing) for the public landing page
- src/app/(app) for the authenticated-like product flow: questionnaire and results
src/app/layout.tsx and src/app/globals.css provide the shared application shell and global styling.
3. Primary user flow
The core experience is a linear flow:
- user starts on the marketing page
- completes the questionnaire
- frontend submits answers to the backend API
- backend returns a structured financial plan
- results page renders the plan and educational explanations
The important architectural boundary is that planning happens server-side, while presentation and state orchestration happen client-side.
4. Feature-based FinMate module
Most product logic lives under src/features/finmate. This is where the domain-specific UI, hooks, and utilities are grouped together:
- questionnaire components and hook
- results components and hook
- term-detection and explanation utilities
- questionnaire/insights/terms helpers
This makes FinMate a self-contained feature slice rather than spreading domain logic across the app.
5. Questionnaire subsystem
src/features/finmate/components/questionnaire/questionnaire-form.tsx is the main data-entry UI. The questionnaire is described in the README as collecting structured answers plus a free-text occupation field. use-questionnaire.ts and utils/questionnaire.ts likely coordinate form state, validation, and normalization before submission.
6. Results subsystem
The results experience is split between results-client.tsx and terms-section.tsx, with use-results.ts supporting data loading/state and utils/insights.ts / utils/terms.ts shaping the output for display. The results page is not just a static summary: it also expands financial terms into a learning layer, so the UI includes both advice and education.
7. API boundary and backend responsibility
The frontend talks to the backend through src/lib/api/finmate.ts, using the public URL configured via NEXT_PUBLIC_API_URL from src/lib/config/finmate.ts and src/lib/config/frontend.ts. The backend is a single FastAPI entrypoint at backend/app.py, which exposes:
- GET / for health
- POST /generate for personalized financial advice
- POST /terms/explain for term explanations
This boundary is important for the architecture diagram: the browser never calls the LLM directly.
8. LLM and provider integration
The backend is the only place that integrates with Groq’s OpenAI-compatible API. The README indicates a primary/fallback model strategy and request timeout handling. From an architecture perspective, the backend is acting as an LLM orchestration and sanitization layer, returning strict JSON to protect the UI from malformed model output.
9. State and persistence
The app uses browser-local persistence for questionnaire answers and generated results, implemented via src/lib/storage.ts. This means refresh safety is handled on the client, not through a database or user account system. There is no evidence of server-side persistence in the repo.
10. Shared UI and design system
Reusable presentation components live in src/components, including layout primitives (container, navbar, theme-toggle) and generic UI controls (button, card, input, progress, etc.). Styling is a mix of Tailwind config, src/styles/theme.css, and global CSS, so the visual system is centralized and reusable across both marketing and app routes.
11. Runtime/configuration boundaries
Runtime configuration is intentionally split:
- frontend: NEXT_PUBLIC_API_URL
- backend: GROQ_API_KEY, model names, request timeout
The deployment model depends on these environment variables being set correctly in Vercel and Hugging Face Spaces. This separation is part of the security model: secrets stay on the backend.
12. What to show in an architecture diagram
A correct diagram should show:
- browser user interacting with Next.js UI
- Next.js pages/components and feature hooks managing questionnaire/results state
- browser-local storage for persistence
- outbound HTTP calls from frontend to FastAPI backend
- backend calling Groq
- backend returning normalized JSON and term explanations
The main trust boundary is between browser/frontend and backend; the main computation boundary is between backend and external LLM provider.
Main entry points: finmate.ts API client · app.py FastAPI app · use-questionnaire.ts Questionnaire state · results-client.tsx Results client
Components 19
Next.js frontend
Browser-facing app, feature UI, client state, and local persistence.
- Browser · Runs the Next.js UI and stores local state.
- App shell · Shared layout and global styling for the app.
src/app/layout.tsx - Marketing page · Public landing page and entry point.
src/app/(marketing)/page.tsx - Questionnaire page · Product flow entry for collecting user answers.
src/app/(app)/questionnaire/page.tsx - Results page · Displays the generated plan and explanations.
src/app/(app)/results/page.tsx - FinMate slice · Domain-specific questionnaire, results, and explanation logic.
src/features/finmate - Questionnaire form · Main data-entry interface for structured answers and occupation text.
src/features/finmate/components/questionnaire/questionnaire-form.tsx - Questionnaire state · Manages form state, validation, and submission prep.
src/features/finmate/hooks/use-questionnaire.ts - Results client · Orchestrates result loading, rendering, and local state.
src/features/finmate/components/results/results-client.tsx - Terms section · Expands financial terms into a learning layer.
src/features/finmate/components/results/terms-section.tsx - Results state · Supports results fetching, normalization, and display state.
src/features/finmate/hooks/use-results.ts - Domain utils · Shapes questionnaire, insights, and term data for the UI.
src/features/finmate/utils
FastAPI backend
Server-side planning and term explanation API.
- FastAPI app · Server entrypoint for generation and term explanations.
backend/app.py - Groq API · Model provider used for advice generation and explanation.
Shared UI and lib
Reusable components, client API, config, and storage.
- API client · Frontend bridge to backend endpoints.
src/lib/api/finmate.ts - Runtime config · Public API base URL for the frontend.
src/lib/config/finmate.ts - Local storage · Persists questionnaire answers and generated results in the browser.
src/lib/storage.ts - Shared UI · Reusable layout and form primitives used across routes.
src/components
Other components
- User · Starts on marketing, answers questionnaire, reviews results.
Connections 24
- User → Browser: uses · Interacts with the web app in the browser.
- Browser → Marketing page: opens · Starts from the public landing page.
- Marketing page → Questionnaire page: navigates · Moves into the main product flow.
- Questionnaire page → Questionnaire form: renders · Mounts the FinMate questionnaire UI.
- Questionnaire form → Questionnaire state: uses · Delegates form state and submission prep.
- Questionnaire state → Local storage: persists · Saves answers for refresh safety.
- Questionnaire state → API client: submits · Sends normalized answers to the backend.
- API client → Runtime config: reads · Uses the public backend base URL.
- API client → FastAPI app: POST /generate · Requests the personalized financial plan.
- FastAPI app → Groq API: calls · Orchestrates model requests and fallback handling.
- FastAPI app → API client: returns JSON · Responds with normalized plan data.
- Questionnaire state → Results page: routes · Advances into the results experience after submission.
- Results page → Results client: renders · Mounts the results controller UI.
- Results client → Results state: uses · Coordinates results loading and state.
- Results client → Terms section: includes · Shows educational term explanations alongside advice.
- Results state → Local storage: reads/writes · Restores and caches generated results locally.
- Results state → API client: fetches · Requests plan or explanation data when needed.
- API client → FastAPI app: POST /terms/explain · Requests term explanations from the server.
- FastAPI app → Shared UI: formats for UI · Returns responses intended for the frontend renderer.
- App shell → Shared UI: wraps · Provides global layout and styling around reusable UI.
- FinMate slice → Questionnaire form: contains · Groups the questionnaire slice.
- FinMate slice → Results client: contains · Groups the results slice.
- FinMate slice → Domain utils: contains · Holds domain-specific transforms and explainers.
- Browser → App shell: loads · Bootstraps the shared app shell.