Skip to content

Jpkoech30/jengabooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

179 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation


NestJS 10 React 18 PostgreSQL 15 Redis 7 TypeScript Prisma 5 Expo 51 Vite Turborepo 234 Tests

๐Ÿ—๏ธ๐Ÿ“š JengaBooks

Kenya-first ยท AI-native ยท Offline-first accounting platform
Built for Kenyan SMEs, accounting firms, and enterprise partners.

Features โ€ข Architecture โ€ข Tech Stack โ€ข Quick Start โ€ข API โ€ข Testing โ€ข Deployment



๐ŸŒŸ Overview

JengaBooks is a multi-tenant accounting SaaS purpose-built for the Kenyan market. It treats M-Pesa as a first-class citizen, automates KRA eTIMS submissions, survives offline environments, and gamifies accounting to drive daily engagement.

๐ŸŽฏ The 7 Pillars

  1. ๐Ÿ›ก๏ธ Immutable Audit & Uniqueness โ€” Postgres RLS, eTIMS serial enforcement, fiscal period controls
  2. ๐Ÿ“ก Offline-First Sync โ€” Optimistic locking, NTP clock validation, token-scoped sync
  3. ๐Ÿ“Š Adaptive Data Ingestion โ€” M-Pesa & Bank CSV parsing with column fingerprinting
  4. ๐Ÿค– Agentic AI โ€” 5 DeepSeek agents with auto-fallback to Suspense Account
  5. ๐Ÿ”Œ Fault-Tolerant APIs โ€” Sliding window circuit breaker for KRA eTIMS
  6. ๐Ÿ—๏ธ Tenant Isolation โ€” Dynamic statement timeouts, SKIP LOCKED queries
  7. ๐Ÿ‘ค Human-in-the-Loop โ€” Centralized DLQ, Kanban dashboard, XP gamification


โœจ Features

๐Ÿ“ฑ M-Pesa Integration

  • CSV/PDF/XLSX import with smart column fingerprinting
  • Rule-based + AI-powered auto-categorization
  • Reconciliation engine (exact/fuzzy/amount-only matching)
  • HITL auto-creation for low-confidence matches
  • 3-tier confidence UI (Green โœ“ / Amber ~ / Red !)
  • Auto-post journal entries for โ‰ฅ90% confidence

๐Ÿงพ KRA eTIMS

  • Invoice creation & submission
  • KRA PIN format validation (A123456789B)
  • Circuit breaker for KRA API failures
  • Automatic retry with exponential backoff
  • Queue-based async processing
  • VAT calculation (16% Standard, 0% Exempt/Zero-rated)

๐Ÿค– AI Agents (DeepSeek V4)

  • Reconciliation โ€” Auto-map transactions to accounts
  • Compliance โ€” KRA eTIMS & IFRS validation
  • Fraud Detection โ€” Nightly batch anomaly scanning
  • Advisory โ€” Business insights & recommendations
  • HITL Resolution โ€” Auto-resolve simple conflicts

๐ŸŽฎ Gamification

  • 50-level progression system with titles
  • 9 achievement badges (auto-earned from activity)
  • Sync Streak tracking
  • Early Bird XP bonus (reports before 5th)
  • Company-wide leaderboards
  • Flawless Finisher trophy (lockdown ceremony)

๐Ÿ“’ Double-Entry Ledger

  • Full journal entry management
  • Chart of accounts with hierarchy
  • Fiscal period enforcement with lockdown ceremony
  • Trial balance, P&L, balance sheet, cash flow
  • Recurring journal entry templates
  • Period-over-period comparison with variance

๐Ÿ‘ฅ Multi-Tenant RBAC

  • 7 roles: SUPER_ADMIN โ†’ SME_OWNER
  • Row-Level Security on every query
  • Company switcher for multi-entity users
  • Team management with granular permissions

๐Ÿ”„ Monthly Workflow

  • 5-phase bookkeeping tracker: Data โ†’ Categorize โ†’ Reconcile โ†’ Close โ†’ Report
  • Real-time progress bar per client
  • Phase-by-phase action links
  • Automated status detection from live data

๐Ÿ“Š Reporting

  • Profit & Loss, Balance Sheet, Cash Flow
  • Bank-grade loan application format
  • Period-over-period comparison
  • CSV export with nested data handling
  • Shareable report links (24-hour expiry)
  • Duplicate payment detection


๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        JengaBooks Platform                        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                        โ”‚                                         โ”‚
โ”‚    ๐ŸŒ Web App (Vite)   โ”‚    ๐Ÿ“ฑ Mobile App (Expo/RN)              โ”‚
โ”‚    React 18 + Tailwind โ”‚    WatermelonDB + NativeWind             โ”‚
โ”‚    React Router ยท Axiosโ”‚    Offline-first ยท Socket.io             โ”‚
โ”‚                        โ”‚                                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                    ๐Ÿ“ฆ Shared Package (@jengabooks/shared)           โ”‚
โ”‚            Types ยท Zod Schemas ยท RBAC Permissions ยท Theme Tokens   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                   โ”‚
โ”‚    ๐Ÿš€ NestJS 10 API (Stateless ยท RLS-enabled)                    โ”‚
โ”‚                                                                   โ”‚
โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”‚
โ”‚    โ”‚ Auth Module โ”‚ โ”‚ Ledger Moduleโ”‚ โ”‚ AI Module        โ”‚        โ”‚
โ”‚    โ”‚ JWT ยท Cookieโ”‚ โ”‚ Fiscal Periodโ”‚ โ”‚ 5 DeepSeek Agentsโ”‚        โ”‚
โ”‚    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค        โ”‚
โ”‚    โ”‚ M-Pesa      โ”‚ โ”‚ eTIMS Module โ”‚ โ”‚ HITL Module      โ”‚        โ”‚
โ”‚    โ”‚ CSV Import  โ”‚ โ”‚ Circuit Brkr โ”‚ โ”‚ Kanban ยท Reviews โ”‚        โ”‚
โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚
โ”‚                                                                   โ”‚
โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”‚
โ”‚    โ”‚ Reconciliation       โ”‚  โ”‚ Batch/QA                 โ”‚        โ”‚
โ”‚    โ”‚ Matching Engine      โ”‚  โ”‚ Nightly Fraud Detection  โ”‚        โ”‚
โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚
โ”‚                                                                   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                        โ”‚                                         โ”‚
โ”‚   ๐Ÿ—„๏ธ PostgreSQL 15     โ”‚    โšก Redis 7 (AOF ยท RDB)               โ”‚
โ”‚   pgvector ยท RLS       โ”‚    BullMQ ยท Rate Limiting               โ”‚
โ”‚                        โ”‚    Circuit Breaker State                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


๐Ÿ› ๏ธ Tech Stack

Layer Technology Purpose
Runtime Node.js 20+ JavaScript runtime with TypeScript strict mode
Backend NestJS 10 Modular server framework with DI, guards, interceptors
Database PostgreSQL 15 + pgvector Primary data store with Row-Level Security
ORM Prisma 5 Type-safe database access & migrations
Cache & Queue Redis 7 + BullMQ Job queues, rate limiting, circuit breaker state
AI DeepSeek V4 5 specialized AI agents (Pro + Flash models)
Web Frontend React 18 + Vite + TailwindCSS SPA dashboard with responsive design
Mobile Expo 51 + NativeWind Cross-platform mobile app
Offline DB WatermelonDB Local-first sync database for mobile
Real-time Socket.io Live notifications & sync events
Auth JWT + httpOnly Cookies Stateless auth with refresh token rotation
Monorepo Turborepo Workspace orchestration & caching
Testing Jest 29 + Supertest Unit, integration, and E2E testing


๐Ÿ“ Project Structure

jengabooks/
โ”‚
โ”œโ”€โ”€ apps/
โ”‚   โ”œโ”€โ”€ api/                    # ๐Ÿš€ NestJS Backend
โ”‚   โ”‚   โ”œโ”€โ”€ prisma/             # Schema, migrations, seeds
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ”œโ”€โ”€ common/         # Decorators, filters, interceptors
โ”‚   โ”‚       โ”œโ”€โ”€ config/         # Database, Redis configuration
โ”‚   โ”‚       โ”œโ”€โ”€ modules/        # Feature modules (13 total)
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ auth/       # JWT auth, refresh, switch-company
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ ledger/     # Journal entries, accounts, periods, recurring
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ mpesa/      # CSV/PDF import, categorization, file parser
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ etims/      # KRA invoice submission, circuit breaker
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ ai/         # 5 DeepSeek AI agents + batch service
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ hitl/       # Human-in-the-Loop reviews
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ gamification/# XP, levels, badges, streaks, leaderboard
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ reports/    # P&L, Balance Sheet, Cash Flow, comparisons
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ reconciliation/ # Transaction matching engine
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ sync/       # Offline sync endpoints
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ tenants/    # Multi-tenant management
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ wizard/     # Onboarding wizard
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ health-score/ # Business health scoring
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ workflow/   # Workflow dashboard logic
โ”‚   โ”‚       โ”œโ”€โ”€ prisma/         # Prisma service module
โ”‚   โ”‚       โ”œโ”€โ”€ queues/         # BullMQ queue definitions
โ”‚   โ”‚       โ””โ”€โ”€ e2e/            # End-to-end integration tests
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ web/                    # ๐ŸŒ Web Frontend
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ”œโ”€โ”€ components/     # UI components, forms, layout
โ”‚   โ”‚       โ”œโ”€โ”€ pages/          # Route pages (13 routes)
โ”‚   โ”‚       โ”œโ”€โ”€ hooks/          # React Query hooks
โ”‚   โ”‚       โ”œโ”€โ”€ stores/         # Zustand state stores
โ”‚   โ”‚       โ””โ”€โ”€ lib/            # API client, types, utils
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ mobile/                 # ๐Ÿ“ฑ Mobile App
โ”‚       โ””โ”€โ”€ src/
โ”‚           โ”œโ”€โ”€ app/            # Expo Router pages
โ”‚           โ”œโ”€โ”€ components/     # Mobile UI components
โ”‚           โ”œโ”€โ”€ hooks/          # Mobile hooks
โ”‚           โ”œโ”€โ”€ stores/         # Mobile state stores
โ”‚           โ””โ”€โ”€ lib/            # API client, offline DB
โ”‚
โ”œโ”€โ”€ packages/
โ”‚   โ””โ”€โ”€ shared/                 # ๐Ÿ“ฆ Shared Package
โ”‚       โ””โ”€โ”€ src/                # Types, Zod schemas, RBAC, theme, helpers
โ”‚
โ”œโ”€โ”€ plans/                      # ๐Ÿ“‹ Architecture plans & audit docs
โ”œโ”€โ”€ docker-compose.yml          # ๐Ÿณ Local dev (Postgres + Redis)
โ”œโ”€โ”€ turbo.json                  # โšก Turborepo configuration
โ””โ”€โ”€ package.json                # ๐Ÿ“‹ Monorepo root


๐Ÿš€ Quick Start

Choose your environment below.


๐Ÿง Option A: Linux Native (PostgreSQL + Redis on host)

Best for: Linux workstations, CI/CD runners, production servers.

Prerequisites

Tool Version Check
Node.js >= 20.0.0 node --version
npm 11.x npm --version
PostgreSQL 15+ psql --version
Redis 7+ redis-cli --version

Setup

# 1. Clone & install
git clone https://github.com/Jpkoech30/jengabooks.git
cd jengabooks
npm install

# 2. Configure environment
cp .env.example apps/api/.env

# 3. Create the database
sudo -u postgres psql -c "CREATE DATABASE jengabooks;"

# 4. Run database migrations
cd apps/api && npx prisma migrate dev

# 5. Seed demo data
npx ts-node prisma/seed.ts

# 6. Start development (from root)
cd ../.. && npm run dev

Connection config (.env / apps/api/.env):

DATABASE_URL="postgresql://postgres:postgres@localhost:5432/jengabooks?schema=public"
REDIS_HOST=localhost
REDIS_PORT=6379

๐Ÿณ Option B: Windows + Docker (PostgreSQL + Redis in containers)

Best for: Windows workstations with Docker Desktop.

Prerequisites

Tool Version Check
Node.js >= 20.0.0 node --version
npm 11.x npm --version
Docker Desktop Latest docker --version

Setup

# 1. Clone & install
git clone https://github.com/Jpkoech30/jengabooks.git
cd jengabooks
npm install

# 2. Configure environment
cp .env.example apps/api/.env

# 3. Start infrastructure (Docker)
docker-compose up -d

# 4. Run database migrations
cd apps/api && npx prisma migrate dev

# 5. Seed demo data
npx ts-node prisma/seed.ts

# 6. Start development (from root)
cd ../.. && npm run dev

Connection config (.env / apps/api/.env):

DATABASE_URL="postgresql://postgres:postgres@localhost:5432/jengabooks?schema=public"
REDIS_HOST=localhost
REDIS_PORT=6379

Docker Desktop on Windows maps container ports to localhost by default โ€” no special config needed.


๐ŸชŸ Option C: Windows + WSL (PostgreSQL + Redis inside WSL)

Best for: Windows workstations running services natively in WSL without Docker.

Prerequisites

Tool Version Check Where
Node.js >= 20.0.0 node --version Windows
npm 11.x npm --version Windows
WSL distro Ubuntu 24.04+ wsl -l -v Windows
PostgreSQL 15+ psql --version WSL (inside distro)
Redis 7+ redis-cli --version WSL (inside distro)

โš ๏ธ Important: Node.js runs on Windows, while PostgreSQL and Redis run inside WSL. This means localhost from Node.js on Windows does not reliably forward to WSL services. You must use the WSL instance's network IP.

Step 1: WSL Infrastructure Setup

# Inside WSL โ€” Install PostgreSQL
sudo apt update
sudo apt install -y postgresql postgresql-client redis-server

# Start services
sudo service postgresql start
sudo service redis-server start

# Configure PostgreSQL for external connections
sudo sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/15/main/postgresql.conf
sudo sed -i "s/127.0.0.1\/32/0.0.0.0\/0/" /etc/postgresql/15/main/pg_hba.conf
sudo service postgresql restart

# Create the database
sudo -u postgres psql -c "CREATE DATABASE jengabooks;"

Step 2: Find your WSL IP

# From Windows PowerShell
wsl -- ip addr | findstr "inet "
# Look for an address like 192.168.1.XXX (not 127.0.0.1 or inet6)

Step 3: Configure Connection

# On Windows โ€” Clone & install
git clone https://github.com/Jpkoech30/jengabooks.git
cd jengabooks
npm install

# Configure .env with the WSL IP found above
# Edit .env and apps/api/.env

Connection config (.env / apps/api/.env):

# โŒ Will NOT work:
# DATABASE_URL="postgresql://postgres:postgres@localhost:5432/jengabooks"

# โœ… Use WSL's real IP โ€” disable SSL (local Postgres doesn't need it):
DATABASE_URL="postgresql://postgres:postgres@192.168.1.180:5432/jengabooks?schema=public&sslmode=disable"
REDIS_HOST=localhost
REDIS_PORT=6379

Why localhost fails: Windows' WSL2 port forwarding is unreliable on some configurations. The WSL instance gets a virtual IP that is stable within a session but localhost does not always forward correctly. Direct IP connection with SSL disabled is the confirmed working configuration.

Step 4: Run Migrations & Seed

cd apps/api
npx prisma migrate dev
npx ts-node prisma/seed.ts
cd ../..
npm run dev

Step 5: Verify Connection

# From the project root โ€” tests both WSL IP and localhost
node scripts/test-conn2.js

# Expected output:
# โœ“ WSL IP: [{"db":"jengabooks","ver":"PostgreSQL 18.4..."}]
# โœ— localhost: Can't reach database server at localhost:5432

Automation: One-command start

The dev launcher script handles everything automatically:

.\scripts\dev.ps1

What it does:

  1. Starts WSL (if not running)
  2. Starts PostgreSQL and Redis in WSL
  3. Auto-detects the WSL IP and injects it into DATABASE_URL at runtime
  4. Waits for PostgreSQL and Redis to be ready (retries up to 15 times)
  5. Checks optional 3rd party API connectivity (DeepSeek, KRA eTIMS)
  6. Starts the JengaBooks dev server

Expected output:

=== JengaBooks Dev Environment ===

[1/5] Checking WSL status...
  โœ“ WSL is ready
[2/5] Starting PostgreSQL...
  โœ“ PostgreSQL already running
[3/5] Starting Redis...
  โœ“ Redis already running
[4/5] Detecting WSL IP and configuring connection...
  โœ“ DATABASE_URL configured with WSL IP
    โ†’ postgresql://postgres:postgres@192.168.1.180:5432/jengabooks?schema=public&sslmode=disable
[5/5] Verifying service connectivity...
  โœ“ PostgreSQL is ready
  โœ“ Redis is ready
  - DeepSeek AI API: skipped (no API key configured)
  - KRA eTIMS API: skipped (no KRA_API_URL configured)
  โœ… All services are ready! Starting application...

Options:

# Skip the service health check (faster startup)
.\scripts\dev.ps1 -SkipServiceCheck

# Skip WSL steps entirely (for Docker or Linux)
.\scripts\dev.ps1 -SkipWsl

# Specify a different WSL distro
.\scripts\dev.ps1 -WslDistro Ubuntu-22.04

How IP injection works: The script runs node scripts/wsl-ip.js --export which outputs $env:DATABASE_URL="postgresql://...@<detected-ip>...". This env var overrides whatever is in the .env file, so you never need to edit .env when the WSL IP changes.

If WSL IP Changes (manual fallback)

WSL's IP can change after a reboot. If you're not using dev.ps1, find the new IP:

wsl -- ip addr | findstr "inet "

Then update DATABASE_URL in both:

Or better, use the automated script:

# This detects the IP and exports the correct DATABASE_URL for the current session
$env:DATABASE_URL = "$(node scripts/wsl-ip.js --export)"
npm run dev

๐Ÿ” Demo Credentials

๐Ÿ” Demo Credentials

Role Email Password
Firm Owner admin@jengabooks.com password123


๐Ÿงช Testing

The project has 234 tests across 24 test suites.

Test Types

Type Count What It Tests
Unit (pure logic) ~120 Static methods, DTO validation, calculations, level thresholds, file parsing
Integration (mocked DB) ~100 Services with mocked Prisma: auth, ledger, HITL, reports, reconciliation
E2E (HTTP + real DB) 14 Full request/response cycle: register, login, auth flows

Test Coverage by Module

Module Tests Key Features Tested
Auth 16 Login, register, refresh, profile, DTO validation
Ledger 34 Accounts CRUD, journal entries, trial balance, serial numbers, recurring entries, lockdown
eTIMS 22 Invoices, VAT, KRA PIN validation, submissions, circuit breaker
M-Pesa 75 CSV parsing, file formats, bank templates, AI agents, auto-post, bulk approve, upload validation
HITL 7 Create, assign, resolve with XP
Reports 24 P&L, Balance Sheet, Cash Flow, period comparison, duplicates, share tokens
Gamification 20 Level calculation, sync streaks, early bird, level-up detection
Tenants 6 CRUD, member management, invite
Wizard 6 Progress tracking, step completion
AI Batch 5 Nightly fraud detection
Exception Filter 6 Prisma errors, HTTP errors
Circuit Breaker 6 State transitions, timeout, reset
Confidence Tier 8 3-tier confidence logic
Reconciliation 11 Matching engine (exact/fuzzy), status
Workflow 5 5-phase progress calculation
Total 234

Running Tests

# All unit + integration tests
cd apps/api && npm test

# Watch mode
cd apps/api && npm run test:watch

# With coverage
cd apps/api && npm run test:cov

# Specific module
cd apps/api && npx jest --verbose --testPathPattern="mpesa"

# E2E tests (requires database)
cd apps/api && npx jest --config jest-e2e.config.ts


๐ŸŒ API Reference

All endpoints are prefixed with /api/v1 and protected with JWT authentication (except login & register).

๐Ÿ”‘ Auth

Method Endpoint Description
POST /api/v1/auth/login Sign in with email + password (5 req/min)
POST /api/v1/auth/register Create account + company (3 req/min)
POST /api/v1/auth/refresh Refresh JWT token
POST /api/v1/auth/logout Clear session
GET /api/v1/auth/profile Get user profile + memberships
POST /api/v1/auth/switch-company Switch active company

๐Ÿ“’ Ledger

Method Endpoint Description
GET /api/v1/ledger/accounts List chart of accounts
POST /api/v1/ledger/accounts Create account
GET /api/v1/ledger/entries List journal entries
POST /api/v1/ledger/entries Create journal entry
POST /api/v1/ledger/transactions/income Quick income entry
POST /api/v1/ledger/transactions/expense Quick expense entry
GET /api/v1/ledger/trial-balance Trial balance report
GET /api/v1/ledger/periods Fiscal periods

๐Ÿ’ฐ M-Pesa

Method Endpoint Description
POST /api/v1/mpesa/import Import CSV/XLSX/PDF transactions
GET /api/v1/mpesa List transactions
POST /api/v1/mpesa/:txId/map Map to account

๐Ÿงพ eTIMS

Method Endpoint Description
GET /api/v1/etims/invoices List invoices
POST /api/v1/etims/invoices Create invoice
POST /api/v1/etims/submissions/:id/submit Submit to KRA

๐Ÿค– AI

Method Endpoint Description
POST /api/v1/ai/process Trigger AI processing
POST /api/v1/ai/feedback Submit feedback
POST /api/v1/ai/batch/fraud-detection Manual fraud batch run

๐Ÿ‘ค HITL (Human-in-the-Loop)

Method Endpoint Description
GET /api/v1/hitl List reviews (with filters)
POST /api/v1/hitl Create review
POST /api/v1/hitl/:id/assign Claim task
POST /api/v1/hitl/:id/resolve Resolve with action + XP

๐Ÿ† Gamification

Method Endpoint Description
GET /api/v1/gamification/profile User XP, level, badges
GET /api/v1/gamification/badges Earned & available badges
GET /api/v1/gamification/leaderboard Company ranking

๐Ÿ“Š Reports

Method Endpoint Description
GET /api/v1/reports/profit-loss Profit & Loss statement
GET /api/v1/reports/balance-sheet Balance sheet
GET /api/v1/reports/trial-balance Trial balance
GET /api/v1/reports/cash-flow Cash flow statement

๐Ÿ“‹ Workflow

Method Endpoint Description
GET /api/v1/workflow Monthly workflow progress (all 5 phases)


๐ŸŽฎ Gamification System

Level Progression

Level Range Title XP Required
1โ€“5 ๐Ÿชœ Apprentice 0 โ€“ 1,000
6โ€“10 ๐Ÿ“š Bookkeeper 1,500 โ€“ 4,500
11โ€“20 ๐Ÿงฎ Accountant 5,500 โ€“ 19,000
21โ€“30 ๐Ÿ’ผ Finance Pro 21,000 โ€“ 43,500
31โ€“50 ๐Ÿ† Business Master 46,500 โ€“ 122,500

Badges

Badge Trigger XP
๐Ÿ“š Accountant Set up Chart of Accounts (5+ accounts) 25
๐Ÿ“ฑ M-Pesa Connected M-Pesa transactions exist 25
๐Ÿ“Š Data Driven Import first M-Pesa CSV 25
๐Ÿ’ฐ First Income Record first income 25
๐Ÿ’ณ First Expense Record first expense 25
๐Ÿ›ก๏ธ Tax Compliant Submit first eTIMS invoice (ACCEPTED) 50
๐Ÿ‘ฅ Team Player Invite a team member 25
๐Ÿ“ˆ Analyst Generate first report (5+ entries) 25
๐Ÿค– Trust the AI Bulk approve 10+ AI-categorized transactions 25

Streaks & Bonuses

Mechanic Trigger Reward
Sync Streak Consecutive days of activity Badge at 7/30/90 days
Early Bird Submit reports before 5th of month +50 XP
Flawless Finisher Complete lockdown with 0 errors Trophy badge


๐Ÿ‘ฅ RBAC Roles

Role Level Description
SUPER_ADMIN ๐Ÿ”ด Platform Full system access, DevOps
FIRM_OWNER ๐ŸŸฃ Partner Accounting firm ownership
TENANT_ADMIN ๐ŸŸ  Admin Tenant internal administration
ACCOUNTANT ๐Ÿ”ต Staff Daily accounting operations
SME_OWNER ๐ŸŸข Business SME business owner view
AUDITOR ๐ŸŸก External Read-only audit access
BANK_OFFICER โšช Loan Loan portfolio view


๐Ÿ”ง Environment Variables

Variable Required Default Description
DATABASE_URL โœ… โ€” PostgreSQL connection string
PORT โŒ 3000 API server port
JWT_SECRET โœ… โ€” JWT signing secret
REDIS_HOST โŒ localhost Redis host
REDIS_PORT โŒ 6379 Redis port
DEEPSEEK_API_KEY โš ๏ธ โ€” Required for AI features
KRA_API_URL โŒ โ€” KRA eTIMS API endpoint (mock used if unset)
KRA_CLIENT_ID โš ๏ธ โ€” Required for eTIMS
CORS_ORIGIN โŒ http://localhost:5173 Allowed CORS origin


โ˜๏ธ Deployment

Tier 1 โ€” Single VM (Vultr Johannesburg)

docker-compose -f docker-compose.prod.yml up -d

Tier 2 โ€” Horizontal Scaling

Vultr Load Balancer
    โ”œโ”€โ”€ Node.js VM 1 (API + Web)
    โ”œโ”€โ”€ Node.js VM 2 (API + Web)
    โ””โ”€โ”€ Node.js VM n (Workers)

Tier 3 โ€” High Availability

Vultr Managed PostgreSQL โ†’ Replica set
Vultr Managed Redis      โ†’ Cluster
Vultr Object Storage     โ†’ Backups

Environment Configuration for Production

# Required for production
NODE_ENV=production
JWT_SECRET=<strong-random-secret>
DATABASE_URL=postgresql://user:password@vultr-db:5432/jengabooks

# For AI features (optional, degrades gracefully if unset)
DEEPSEEK_API_KEY=sk-your-key
KRA_API_URL=https://kra-api.go.ke/v1
KRA_CLIENT_ID=your-client-id


๐Ÿ“š Additional Documentation

Document Location Description
Audit Report plans/jengabooks-comprehensive-audit.md Full project audit with 24 issues
Test Strategy plans/jengabooks-test-strategy.md 158-test plan across 5 phases
Workflow Spec plans/acct-workflow-gap-analysis.md Kenyan accounting workflow specification
Gap Analysis plans/acct-workflow-roadmap.md 6-phase implementation roadmap
Pricing Spec plans/accontingspecs.md Full accounting feature specification


๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feat/amazing-feature)
  3. Commit changes (git commit -m 'feat: add amazing feature')
  4. Push to branch (git push origin feat/amazing-feature)
  5. Open a Pull Request

Before submitting: Run the test suite and ensure all tests pass.

cd apps/api && npm test


๐Ÿ“„ License

Private ยท JengaBooks Inc. ยฉ 2026


Built with ๐Ÿ’š for Kenyan businesses
Nairobi ยท Mombasa ยท Kisumu ยท Eldoret

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages