How viru143/spendwiseai works
Project Type and Purpose
• This is a full-stack (primarily front-end) Next.js web application named “SpendWise AI.”
• Its primary purpose is expense tracking with built-in AI features—receipt scanning and category suggestions—using Google’s Gemini models via the Genkit API.
• All persistent data (expenses) live in the browser’s local storage; no dedicated backend database or server-side data store is present.
High-Level Architecture Components
a. Client Browser (Next.js App)
• UI Layer: React components (src/components and src/app) built with TypeScript, Tailwind CSS, and ShadCN primitives.
• State & Persistence: React hooks (src/hooks/use-local-storage) manage in-memory state and sync to localStorage.
• AI Module: src/ai contains Genkit client logic and “flows” for receipt analysis and category suggestion.
• Utility Layer: src/lib houses constants, data types, and common helper functions.
b. Next.js Runtime
• Static/SSR Hosting: next.config.ts and apphosting.yaml configure build/deployment.
• Routing & Layout: src/app/layout.tsx orchestrates global styles and wrappers; src/app/page.tsx is the entry point.
c. External Services
• Genkit API Gateway: invoked by the AI Module (src/ai/genkit.ts)
• Google Gemini Model: underlying LLM service behind Genkit
d. Data Store
• Browser Local Storage: persistent storage for expenses via a custom hook.
Relationships and Data Flow
1. User interacts with the UI in the browser.
2. UI components call custom hooks (useLocalStorage) to read/write expense data.
3. When a user uploads a receipt or requests a suggestion, the AI Module packages the request and calls the Genkit REST API.
4. Genkit forwards to Google Gemini, processes the image/text, returns structured data.
5. The AI Module parses the response and updates UI state, which in turn persists to localStorage.
6. Next.js server delivers initial HTML/JS bundles, but runtime interactions occur client-side.
Architectural Patterns & Principles
• Component-Based UI (Atomic design via ShadCN).
• Separation of Concerns: UI vs. AI logic vs. utilities.
• Hook Abstraction: encapsulate cross-cutting concerns (persistence, toast notifications, mobile detection).
• Externalization of AI calls: isolating Genkit client from UI code.