FinTech AI Solution for SMEs to calculate financial values
FinSight AI โ AI Financial Assistant for SMEs
Production-grade SaaS financial intelligence platform powered by GPT-4o, Next.js 15, and PostgreSQL.
๐ Features
Core Modules
| Module | Description | |--------|-------------| | Financial Dashboard | Real-time revenue, expenses, profit, invoice metrics | | Invoice Management | Create, send, track, record payments | | Expense Tracking | Manual entry, CSV import, categorization | | Transaction Ledger | Full double-entry transaction history | | Bank Statement Analyzer | Upload PDF/CSV, extract & categorize transactions | | AI Financial Assistant | RAG-based chatbot with real financial data context | | AI Insights Engine | Auto-detected anomalies, risks, opportunities | | Cash Flow Forecasting | Deterministic 3-month linear trend forecasts | | Financial Reports | P&L, Expense Summary, Revenue Trends (PDF/Excel) | | Settings & Security | RBAC, audit logs, MFA, organization management |Critical Design Principle
AI NEVER calculates financial values. All calculations are deterministic and performed by the backend using Prisma queries. AI only generates explanations, insights, and narratives based on the pre-calculated data.
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Next.js 15 App Router โ
โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Frontend (RSC) โ API Routes โ
โ - Dashboard โ - /api/dashboard โ
โ - Invoices โ - /api/invoices โ
โ - Expenses โ - /api/expenses โ
โ - AI Assistant โ - /api/ai/chat (SSE streaming) โ
โ - Cash Flow โ - /api/cash-flow โ
โ - Reports โ - /api/reports โ
โ - Insights โ - /api/insights โ
โโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
Clerk Auth Prisma ORM
โ โ
PostgreSQL DB OpenAI GPT-4o
โ โ
Qdrant Vector DB RAG Pipeline
RAG Pipeline
User Question
โ Intent Classification (GPT-4o-mini)
โ Data Retrieval (Prisma queries = REAL numbers)
โ Context Assembly
โ OpenAI GPT-4o Response Generation
โ Streaming SSE to Frontend
๐ Tech Stack
Frontend
- Next.js 15 (App Router, RSC, Streaming)
- TypeScript 5
- Tailwind CSS + ShadCN UI components
- Recharts (interactive financial charts)
- React Query (server state management)
- Zustand (client state)
- Next.js API Routes
- Prisma ORM with PostgreSQL
- Zod validation (all inputs)
- Rate limiting via Redis when
REDIS_URLis set (in-process fallback otherwise) - Redis-backed dashboard metrics cache with version invalidation on writes
- OpenAI GPT-4o (assistant responses)
- OpenAI text-embedding-3-small (embeddings)
- RAG architecture for financial context
- Qdrant vector database
- Clerk Authentication (OAuth, MFA, RBAC)
- OWASP Top 10 compliant
- CSRF protection in middleware
- SQL injection prevention (Prisma parameterized queries)
- Complete audit logging
๐๏ธ Database Schema
Organizations โโโฌโโ OrganizationMembers โโ Users
โโโ Clients
โโโ Vendors
โโโ Categories
โโโ Transactions โโ Categories
โโโ Invoices โโโโโโฌโโ InvoiceItems
โ โโโ Payments
โโโ Expenses โโ Categories
โโโ BankStatements โโ Transactions
โโโ Reports
โโโ AIChats โโ AIChatMessages
โโโ Insights
โโโ CashFlowForecasts
โโโ Notifications
โโโ AuditLogs
โโโ Anomalies
๐ Security Implementation
| Security Layer | Implementation | |----------------|---------------| | Authentication | Clerk JWT + MFA | | Authorization | RBAC (Admin/Accountant/Employee/Viewer) | | CSRF Protection | Origin/Host validation in middleware | | Rate Limiting | Per-IP sliding window (100 req/min default) | | Input Validation | Zod schemas on all API endpoints | | SQL Injection | Prisma ORM parameterized queries | | XSS Prevention | Next.js built-in + CSP headers | | Audit Logging | All CRUD operations logged with user/IP | | Sensitive Data | Prisma field-level encryption ready | | File Upload | Type validation, size limits, S3 signed URLs |
๐ Quick Start
Prerequisites
- Node.js 20+
- PostgreSQL 16+
- OpenAI API key
- Clerk account
1. Clone & Install
git clone https://github.com/imchine/FinTech-Solution.git
cd finsight-ai
npm install
2. Environment Setup
cp .env.example .env.local
Fill in your API keys
3. Database Setup
# Apply schema
npx prisma migrate dev --name init
Generate client
npx prisma generate
4. Run Development
npm run dev
Open http://localhost:3000
5. Docker (Full Stack)
docker-compose up -d
Redis (optional)
Redis is optional but recommended for production and multi-instance deployments.
docker compose up -d redis
set in .env.local:
REDIS_URL=redis://localhost:6379
When REDIS_URL is set:
- Rate limiting โ shared across API routes (
/api/transactions,/api/invoices,/api/ai/chat, etc.) - Dashboard cache โ metrics cached for 2 minutes; invalidated when transactions, expenses, or invoices change
- Health check โ
GET /api/healthreports whether Redis is configured
๐ Folder Structure
finsight-ai/
โโโ src/
โ โโโ app/
โ โ โโโ (auth)/ # Sign in/up pages (Clerk)
โ โ โโโ (dashboard)/ # All protected dashboard pages
โ โ โ โโโ dashboard/ # Main financial dashboard
โ โ โ โโโ invoices/ # Invoice management
โ โ โ โโโ expenses/ # Expense tracking
โ โ โ โโโ transactions/# Transaction ledger
โ โ โ โโโ ai-assistant/# AI chatbot interface
โ โ โ โโโ cash-flow/ # Cash flow & forecasting
โ โ โ โโโ insights/ # AI insights engine
โ โ โ โโโ reports/ # Financial reports
โ โ โ โโโ bank-statements/ # Bank statement analyzer
โ โ โ โโโ settings/ # Account & org settings
โ โ โโโ api/ # All API routes
โ โโโ components/
โ โ โโโ ui/ # ShadCN UI components
โ โ โโโ charts/ # Recharts wrappers
โ โ โโโ dashboard/ # Dashboard-specific components
โ โ โโโ layout/ # Sidebar, Header
โ โ โโโ shared/ # Providers, theme
โ โโโ lib/
โ โ โโโ prisma.ts # Database client
โ โ โโโ auth.ts # Auth helpers & audit logging
โ โ โโโ openai.ts # AI integration & RAG
โ โ โโโ financial-calculations.ts # ALL financial math
โ โ โโโ validations.ts # Zod schemas
โ โ โโโ rate-limit.ts # API rate limiting
โ โ โโโ utils.ts # Utilities & formatters
โ โโโ middleware.ts # Auth & security middleware
โ โโโ types/ # TypeScript types
โโโ prisma/
โ โโโ schema.prisma # Complete DB schema
โโโ docker-compose.yml # Full stack Docker setup
โโโ Dockerfile # Production container
โโโ .env.example # Environment template
๐ API Endpoints
| Method | Endpoint | Description | |--------|----------|-------------| | GET | /api/health | Health check | | GET | /api/dashboard | Dashboard metrics | | GET | /api/dashboard/trends | Monthly trends | | GET | /api/dashboard/categories | Expense categories | | GET/POST | /api/invoices | List/create invoices | | GET/PATCH/DELETE | /api/invoices/[id] | Invoice operations | | GET/POST | /api/expenses | List/create expenses | | GET/POST | /api/transactions | List/create transactions | | POST | /api/ai/chat | AI chat (SSE streaming) | | GET | /api/ai/chat | Chat history | | GET | /api/cash-flow | Historical + forecasts | | GET/POST | /api/reports | Report management | | GET | /api/insights | AI insights |
๐ข Deployment
Vercel (Frontend)
vercel deploy --prod
Environment Variables (Production)
Set all variables from.env.example in your deployment platform.
Database Migration (Production)
npx prisma migrate deploy
๐งช Testing Strategy
- Unit Tests: Financial calculation functions (Jest)
- Integration Tests: API routes with Prisma mocks
- E2E Tests: Playwright for critical user flows
- Security Tests: OWASP ZAP scanning
- Load Tests: k6 for API performance
๐ Performance
- Server-side rendering for initial dashboard load
- React Query caching (60s stale time)
- Optimized Prisma queries with proper indexes
- Streaming AI responses (SSE)
- Image optimization via Next.js
- Lazy loading of chart components
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make changes with tests
- Submit a PR
๐ License
MIT License โ see LICENSE file.
Built with โค๏ธ for SMEs worldwide