Skip to content

imchine/FinTech-Solution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FinSight AI β€” AI Financial Assistant for SMEs

Production-grade SaaS financial intelligence platform powered by GPT-4o, Next.js 15, and PostgreSQL.

Next.js TypeScript PostgreSQL Clerk OpenAI


πŸš€ 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)

Backend

  • Next.js API Routes
  • Prisma ORM with PostgreSQL
  • Zod validation (all inputs)
  • Rate limiting via Redis when REDIS_URL is set (in-process fallback otherwise)
  • Redis-backed dashboard metrics cache with version invalidation on writes

AI

  • OpenAI GPT-4o (assistant responses)
  • OpenAI text-embedding-3-small (embeddings)
  • RAG architecture for financial context
  • Qdrant vector database

Auth & Security

  • 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/health reports whether Redis is configured

Without Redis, rate limits and dashboard metrics use in-process behaviour only.


πŸ“ 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

  1. Fork the repository
  2. Create a feature branch
  3. Make changes with tests
  4. Submit a PR

πŸ“„ License

MIT License β€” see LICENSE file.


Built with ❀️ for SMEs worldwide

About

FinTech AI Solution for SMEs to calculate financial values

Topics

Resources

Stars

51 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages