A full-stack invoice management system for creating invoices, tracking payments, running analytics, and automating reminders across email/SMS/voice channels.
- Overview
- Key Features
- Architecture at a Glance
- Tech Stack
- Project Structure
- Prerequisites
- Environment Variables
- Local Setup
- Database Setup and Migrations
- Running the App
- Reminder Automation (Local and Cloud)
- API Surface
- Security Model
- Performance Guidelines
- Troubleshooting
- Documentation Map
- License
- Frontend: Next.js App Router pages and client components.
- Backend: Next.js route handlers under
app/api/**/route.ts. - Data: PostgreSQL via Prisma ORM.
- Auth: NextAuth v5 with Google OAuth and Credentials.
- Automation: daily reminder sweep via Vercel Cron or Windows Task Scheduler.
This repository already contains backend functionality. A separate backend service is not required for normal scaling at current scope.
- Professional invoice create/read/update/delete lifecycle.
- PDF invoice generation and mail delivery.
- Automated reminders with idempotent reminder logs.
- Multi-channel delivery support (email, SMS, voice, Telegram mirror).
- Dashboard analytics for KPIs, revenue trend, and risk insights.
- Bulk imports for invoices and customers (YAML/Tally-oriented flows).
flowchart LR
U[User Browser] --> FE[Next.js Frontend\napp/**/page.tsx]
FE --> API[Next.js Backend APIs\napp/api/**/route.ts]
API --> AUTH[NextAuth\nlib/auth.ts]
API --> PRISMA[Prisma Client\nlib/db.ts]
PRISMA --> DB[(PostgreSQL)]
API --> CH[Email / SMS / Voice / Telegram]
CRON[Vercel Cron or Task Scheduler] --> RA[/api/reminders/auto]
sequenceDiagram
autonumber
participant U as User Browser
participant L as Login/Register UI
participant N as NextAuth API
participant P as Provider/DB Check
participant S as Session/JWT
participant A as Protected API Route
participant DB as PostgreSQL
U->>L: Submit credentials or OAuth sign-in
L->>N: POST /api/auth/[...nextauth]
N->>P: Validate with Google or Credentials
P-->>N: User verified
N->>S: Create session token (JWT)
S-->>U: Session cookie/token returned
U->>A: Request protected endpoint
A->>N: auth() session check
alt authorized
N-->>A: userId
A->>DB: Query only user data
DB-->>A: records
A-->>U: 200 + JSON
else unauthorized
N-->>A: no valid session
A-->>U: 401 Unauthorized
end
sequenceDiagram
autonumber
participant U as User Browser
participant P as Dashboard Invoices Page
participant A as /api/invoices
participant AU as NextAuth (auth())
participant PR as Prisma Client
participant DB as PostgreSQL
U->>P: Open Invoices page
P->>A: GET /api/invoices?withItems=false
A->>AU: Validate session
AU-->>A: userId
A->>PR: invoice.findMany(where: userId)
PR->>DB: SQL query
DB-->>PR: invoice rows
PR-->>A: mapped records
A-->>P: JSON response
P-->>U: Render invoice list + stats
sequenceDiagram
autonumber
participant C as Cron (Vercel/Local Script)
participant R as /api/reminders/auto
participant PR as Prisma Client
participant DB as PostgreSQL
participant S as Reminder Service
participant E as Email/SMS/Voice Providers
C->>R: POST /api/reminders/auto (secret)
R->>R: Authorize cron secret
R->>PR: find eligible unpaid invoices
PR->>DB: Query invoices + customer flags
DB-->>PR: due invoices
loop each eligible invoice
R->>S: getReminderMatchForDate + sendInvoiceReminderById
S->>E: Send via configured channel(s)
E-->>S: delivery result
alt sent successfully
R->>PR: create InvoiceReminderLog
PR->>DB: INSERT reminder log
else failed/skipped
R->>R: count failure/skip
end
end
R-->>C: summary JSON (sent/skipped/failed)
flowchart LR
subgraph Cloud[Cloud Runtime]
V[Vercel Deployment]
VC[Vercel Cron\n30 13 * * *]
AR[/api/reminders/auto]
end
subgraph Local[Local Runtime]
TS[Windows Task Scheduler]
BAT[scripts/automation/run-reminders.bat]
JS[scripts/automation/run-reminders.js]
ARL[/api/reminders/auto]
end
DB[(PostgreSQL)]
CH[Email/SMS/Voice Channels]
VC --> AR
TS --> BAT --> JS --> ARL
AR --> DB
ARL --> DB
AR --> CH
ARL --> CH
For full diagrams, see Documentation/architecture/system-architecture-diagrams.md.
For complete architecture narrative, see Documentation/architecture/system-architecture.md.
- Framework: Next.js 16.x (App Router)
- Runtime: Node.js
- UI: React 19, Tailwind CSS, Radix/Shadcn components
- Data: Prisma 5 + PostgreSQL
- Authentication: next-auth v5
- Notifications: Gmail API/SMTP, Telegram, (SMS/Voice Coming Soon)
- Charts and reporting: Recharts
app/ Next.js pages and API routes
app/api/ Backend route handlers
components/ Shared UI components
lib/ Auth, DB, reminders, messaging, PDF, helpers
prisma/ Schema and migrations
scripts/ Operational scripts grouped by purpose
scripts/automation/ Reminder trigger and scheduling launchers
scripts/maintenance/ Database and tenancy maintenance scripts
scripts/integration/ External provider integration test utilities
logs/ Runtime logs (local reminder scheduler)
data/ Bulk import sample files
Documentation/ Additional project docs (SRS, etc.)
- Node.js 18.17+
- npm or pnpm
- PostgreSQL database
- Optional provider accounts: Google, Twilio, Telegram, VAPI
Create .env in repository root.
DATABASE_URL="postgresql://<user>:<password>@<host>:<port>/<db>?schema=public"
DIRECT_URL="postgresql://<user>:<password>@<host>:<port>/<db>?schema=public"
AUTH_SECRET="replace-with-strong-random-secret"
SITE_URL="http://localhost:3000"GOOGLE_CLIENT_ID="..."
GOOGLE_CLIENT_SECRET="..."GMAIL_USER="your-email@gmail.com"
GMAIL_APP_PASSWORD="your-app-password"TWILIO_ACCOUNT_SID="..."
TWILIO_AUTH_TOKEN="..."
TWILIO_PHONE_NUMBER="+1..."TELEGRAM_BOT_TOKEN="..."
TELEGRAM_CHAT_ID="..."# Voice Reminders (Future Update)
# VAPI_API_KEY="..."
# VAPI_PHONE_NUMBER_ID="..."
# VAPI_ASSISTANT_ID="..."
SARVAM_API_KEY="..."CRON_SECRET="set-a-long-random-value"
# Optional legacy alias (if present, keep it identical)
REMINDER_CRON_SECRET="same-value-as-cron-secret"npm install
npx prisma generate
npx prisma migrate deploy
npm run devpnpm alternative:
pnpm install
pnpm prisma generate
pnpm prisma migrate deploy
pnpm devIf you are starting from a clean local DB and want schema sync quickly:
npx prisma db push- Schema source of truth:
prisma/schema.prisma - Migration files:
prisma/migrations/** - Generate Prisma client after schema changes:
npx prisma generate- Dev server:
npm run dev- Build:
npm run build- Production start:
npm run startvercel.jsontriggers/api/reminders/autodaily at 7:00 PM IST (30 13 * * *UTC).- Set
CRON_SECRETin Vercel Project Environment Variables (important: Vercel cron uses this name for bearer auth). - Keep
REMINDER_CRON_SECRETonly as an optional legacy compatibility alias, with the same value asCRON_SECRET. - After changing env vars, redeploy the project.
- Launcher:
scripts/automation/run-reminders.bat - Script:
scripts/automation/run-reminders.js - Logs:
logs/reminder-cron.log - Ensure target URL is reachable when scheduler runs:
- Set
REMINDER_TARGET_URL(orSITE_URL) to your live app URL, or - Keep localhost and ensure Next.js server is running at schedule time.
- Set
Manual test run:
node --env-file=.env scripts/automation/run-reminders.jsRepresentative route groups:
- Auth:
app/api/auth/[...nextauth]/route.ts - Dashboard:
app/api/dashboard/stats/route.ts - Invoices:
app/api/invoices/route.ts,app/api/invoices/[id]/route.ts - Customers:
app/api/customers/route.ts - Products:
app/api/products/route.ts - Payments:
app/api/payments/route.ts - Reminders:
app/api/reminders/auto/route.ts,app/api/reminders/send/route.ts - Integrations: OCR, SMS, voice, TTS endpoints under
app/api/**
- Protected dashboard routes via
middleware.tsmatcher. - API-level auth checks with
auth()in route handlers. - User-scoped queries in invoice/dashboard endpoints.
- Secret-based authorization for cron-triggered reminder sweep.
Apply these before considering a separate backend service:
- Prefer server-side data loading for heavy dashboard views.
- Use endpoint caching/revalidation where appropriate.
- Paginate large invoice lists and avoid over-fetching fields.
- Keep indexes aligned with real filters (
userId,status,dueDate). - Move long-running work to background execution paths.
- Monitor slow queries and p95 endpoint latency.
- Verify Node version:
node -v - Reinstall dependencies:
npm install - Confirm
.envvalues are present.
- Regenerate client:
npx prisma generate - Apply migrations:
npx prisma migrate deploy - Verify DB connectivity in
DATABASE_URL.
- Check
REMINDER_CRON_SECRETandCRON_SECRETvalues. - Confirm scheduler invokes
scripts/automation/run-reminders.bat. - Inspect
logs/reminder-cron.log. - Test endpoint manually via script command above.
- If you see
ECONNREFUSED, your target URL is down/unreachable at runtime. - If you see
401 Unauthorizedfrom Vercel cron, setCRON_SECRETin Vercel and redeploy.
- Validate Twilio/VAPI environment variables.
- Check provider account status and sender number permissions.
- Documentation index:
Documentation/README.md - Main architecture narrative:
Documentation/architecture/system-architecture.md - Detailed diagrams:
Documentation/architecture/system-architecture-diagrams.md - Product/system requirements:
Documentation/SRS.md - Script operations guide:
scripts/README.md
Project developed for B2B Invoice Management. All rights reserved.
The data/ folder now includes hardware-company fixtures that match the live import routes and are suitable for demos, presentations, and bulk import testing.
data/hardware_customers.ymldata/hardware_transactions.ymldata/hardware_end_to_end.ymldata/hardware_bulk_demo.yml
heetmehta18125@gmail.comommistry5559@gmail.comheetpersonal1812@gmail.com
- Realistic hardware retail and wholesale customers.
- Invoice imports with stock items, GST allocations, and due dates.
- Reminder-ready transactions with email and SMS/BOTH channels.
- End-to-end linking between customer data and invoices.
- Import
hardware_customers.yml. - Import
hardware_bulk_demo.ymlorhardware_end_to_end.yml. - Open the dashboard and review customer risk and overdue balances.
- Explain how reminder rules are derived from due dates and invoice status.