Skip to content

yousafzeb-byte/AI-Business-Assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Business Operations Assistant β€” React | Flask | PostgreSQL | CI/CD

React TypeScript Flask PostgreSQL Redis Docker CI

🎯 Project: Full-Stack AI Business Operations Platform

A production-ready full-stack web application that helps small business owners automate daily operations using AI. Upload invoices, notes, contracts, and tasks β€” get instant summaries, extracted data, cost tracking, and actionable insights powered by OpenAI GPT-4o.

Recruiter Snapshot

  • Built a full-stack app with React 19 + TypeScript frontend and Flask REST API backend
  • JWT authentication with access tokens (30 min) and refresh token rotation (7 days)
  • OpenAI GPT-4o-mini integration for AI-powered document analysis with structured JSON output
  • Production security: fail-fast secrets, Marshmallow validation, MIME checks, rate limiting, security headers
  • 36 automated tests covering auth, records, analytics, soft delete, and token refresh
  • Containerized with Docker Compose (Postgres + Redis + Backend + Frontend) and CI/CD via GitHub Actions

Architecture At A Glance

  • Application Factory pattern with Blueprint-based routes and Marshmallow validation
  • React 19 + TypeScript SPA with Vite dev server and Nginx production build
  • SQLAlchemy ORM with PostgreSQL, connection pooling, and pre-ping health checks
  • Redis-backed rate limiting that scales across multiple backend instances
  • OpenAI integration for document analysis with explicit error propagation
  • Docker Compose orchestrates all services (Postgres, Redis, Backend, Frontend)
  • Nginx reverse proxy with security headers, static caching, and HTTPS-ready config

Visual Showcase

Add screenshots and demo GIFs under docs/media/ to make this project faster to evaluate for recruiters.

πŸ“‹ Features Implemented

πŸ€– AI-Powered Analysis

  • Document summarization, date/cost/task extraction, category classification via OpenAI GPT-4o-mini
  • AI-generated action items with priority levels, cost tracking, and due date detection
  • Explicit error propagation (no silent mock fallback) with content truncation for token management

πŸ” Authentication & Security

  • JWT access tokens (30 min) + refresh tokens (7 days) with frontend auto-refresh and request queuing
  • Fail-fast config β€” app refuses to start without required secrets; non-root Docker user
  • Security headers (CSP, HSTS, X-Frame-Options, nosniff, XSS-Protection), generic error responses
  • Redis-backed rate limiting: 60/min default, 5/min signup, 10/min login, 20/min record creation

πŸ“„ File Upload & Data Management

  • Upload PDF, TXT, MD, CSV with MIME type validation + extension allowlist (10 MB limit)
  • Automatic text extraction (PyPDF for PDFs) with file cleanup after processing
  • Soft delete with deleted_at timestamp (GDPR-aware, recoverable)
  • Full-text search, category/status filtering, pagination (max 100 per page)
  • Marshmallow schema validation + Bleach sanitization on all inputs

πŸ“Š Analytics Dashboard

  • Total records, expense tracking, category breakdown (pie charts), status distribution (bar charts)
  • Pending action items aggregation, soft-deleted records excluded from all analytics

πŸš€ Quick Start

1. Install Dependencies

# Backend
cd backend
python -m venv .venv && source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -r requirements.txt

# Frontend
cd frontend && npm install

2. Configure Environment

cp .env.example .env
# Edit .env with your secrets and database URL

3. Initialize Database

cd backend
export SECRET_KEY="dev-secret" JWT_SECRET_KEY="dev-jwt" DATABASE_URL="sqlite:///dev.db"
python -c "from app import create_app, db; app=create_app(); app.app_context().push(); db.create_all()"

4. Run the Application

# Backend (terminal 1)
python run.py                                        # β†’ http://localhost:5000

# Frontend (terminal 2)
cd frontend && VITE_API_URL=http://localhost:5000/api npm run dev  # β†’ http://localhost:5173

πŸ§ͺ Unit Testing

This project includes 36 automated tests covering all 12 API endpoints:

Running Tests

cd backend
SECRET_KEY=test JWT_SECRET_KEY=test DATABASE_URL=sqlite:///:memory: python -m pytest tests/ -v
# 36 passed βœ“

Test Breakdown by Module

  • Auth (15 tests):
    • Signup (success, duplicate, short password, missing fields, invalid email)
    • Login (success, wrong password, nonexistent user)
    • Get me (success, no token)
    • Refresh token (success, access token rejected)
  • Records (18 tests):
    • Create (text, no content, empty content, unauthenticated)
    • List (empty, with records, pagination, search, filter by status)
    • Get (success, not found, other user blocked)
    • Delete (success, not found, already deleted)
    • Update status (success, invalid)
    • Update fields (title, category, invalid category, empty title)
  • Analytics (3 tests):
    • Summary empty, summary with records, unauthenticated

πŸ“Š Database Schema

Tables

  • users β€” Email (unique), password hash, full name, role, timestamps
  • records β€” Title, content, AI outputs, metadata, deleted_at (soft delete)

Relationships

  • User β†’ Records (One-to-Many)

Indexes

  • users.email (unique)
  • records.user_id, records.category, records.status, records.deleted_at

πŸ”‘ Key API Endpoints

Authentication

  • POST /api/auth/signup β€” Create account (rate limited: 5/min)
  • POST /api/auth/login β€” Login and get access + refresh tokens
  • POST /api/auth/refresh β€” Get new access token using refresh token
  • GET /api/auth/me β€” Get current user profile (requires token)

Records

  • POST /api/records β€” Create record from text or file upload (AI analyzed)
  • GET /api/records β€” List with search, category, status filters + pagination
  • GET /api/records/:id β€” Get single record
  • PATCH /api/records/:id β€” Update title/category (Marshmallow validated)
  • PATCH /api/records/:id/status β€” Update status (processed, pending, archived)
  • DELETE /api/records/:id β€” Soft-delete record

Analytics & Health

  • GET /api/analytics/summary β€” Dashboard data (totals, categories, statuses, actions)
  • GET /api/health β€” Health check with database connectivity verification

πŸ› οΈ Technologies Used

  • React 19 β€” Frontend UI framework
  • TypeScript 6.0 β€” Type-safe frontend development
  • Vite 8 β€” Frontend build tool and dev server
  • Recharts β€” Dashboard charts and visualizations
  • Axios β€” HTTP client with interceptors for auth
  • Flask 3.1 β€” Backend web framework
  • Flask-SQLAlchemy 3.1 β€” ORM with connection pooling
  • Flask-JWT-Extended 4.7 β€” JWT access + refresh tokens
  • Flask-Limiter 3.12 β€” Redis-backed rate limiting
  • Marshmallow 3.25 β€” Request validation and serialization
  • Bleach 6.2 β€” HTML/input sanitization
  • OpenAI 1.68 β€” GPT-4o-mini integration
  • PyPDF 5.4 β€” PDF text extraction
  • Gunicorn 23 β€” Production WSGI server
  • PostgreSQL 16 β€” Production database
  • Redis 7 β€” Rate limit storage
  • Docker + Docker Compose β€” Containerization
  • Nginx β€” Reverse proxy with security headers
  • GitHub Actions β€” CI/CD pipeline
  • Pytest 8.3 β€” Backend test framework

πŸ“ Project Structure

AI-Business-Assistant/
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── ci.yml                # CI/CD: lint, test, build, deploy
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ __init__.py           # App factory, middleware, error handlers, health check
β”‚   β”‚   β”œβ”€β”€ config.py             # Fail-fast config with required env vars
β”‚   β”‚   β”œβ”€β”€ models/               # User (password hashing) + Record (soft delete)
β”‚   β”‚   β”œβ”€β”€ routes/               # auth, records (CRUD + AI), analytics
β”‚   β”‚   β”œβ”€β”€ services/ai_service.py    # OpenAI integration with error propagation
β”‚   β”‚   └── utils/file_helpers.py     # MIME validation + text extraction
β”‚   β”œβ”€β”€ tests/                    # 36 tests: auth (15), records (18), analytics (3)
β”‚   β”œβ”€β”€ Dockerfile                # Non-root user, gunicorn, worker recycling
β”‚   └── requirements.txt
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ context/AuthContext.tsx    # Auth state + refresh token management
β”‚   β”‚   β”œβ”€β”€ services/             # API client (auto-refresh), auth, records
β”‚   β”‚   β”œβ”€β”€ components/           # ErrorBoundary, Layout, ProtectedRoute
β”‚   β”‚   β”œβ”€β”€ pages/                # Dashboard, NewInput, History, Analytics, Login, Signup
β”‚   β”‚   └── types/index.ts
β”‚   β”œβ”€β”€ nginx.conf                # Security headers, caching, proxy, HTTPS-ready
β”‚   └── Dockerfile                # Multi-stage build (Node β†’ Nginx)
β”œβ”€β”€ docker-compose.yml            # Postgres + Redis + Backend + Frontend
β”œβ”€β”€ .env.example                  # All env vars documented
└── README.md

βœ… Project Checklist

Authentication & Security

  • βœ… JWT access + refresh tokens with auto-refresh and request queuing
  • βœ… Fail-fast secret validation (app won't start without env vars)
  • βœ… Security headers (CSP, HSTS, X-Frame-Options, etc.)
  • βœ… Redis-backed rate limiting with per-endpoint limits
  • βœ… CORS with explicit origin and credentials
  • βœ… Non-root Docker user

AI Integration

  • βœ… OpenAI GPT-4o-mini document analysis with structured JSON output
  • βœ… Explicit error propagation (no silent mock fallback)
  • βœ… Content truncation to manage token usage

File Upload & Data

  • βœ… MIME type validation + extension allowlist
  • βœ… Soft delete, full-text search, pagination
  • βœ… Marshmallow schema validation on all inputs

Testing & CI/CD

  • βœ… 36 automated tests (auth, records, analytics)
  • βœ… GitHub Actions CI/CD pipeline (lint, test, build, deploy)
  • βœ… Backend: Pyright + Pytest + pip-audit
  • βœ… Frontend: TypeScript check + ESLint + Vitest + npm audit

Deployment

  • βœ… Docker Compose with Postgres, Redis, Backend, Frontend
  • βœ… Gunicorn production server with worker recycling
  • βœ… Nginx reverse proxy with caching and security headers
  • βœ… HTTPS-ready config, structured JSON logging, health check

πŸš€ Production Deployment

This project is fully containerized and deployment-ready!

Quick Deploy

  1. Server: Any VPS with Docker installed (DigitalOcean, AWS EC2, etc.)
  2. Clone: git clone <repo> && cd AI-Business-Assistant
  3. Configure: cp .env.example .env && nano .env (set real secrets)
  4. Launch: docker compose up -d --build
  5. Done: App available at your server's IP/domain

CI/CD Pipeline Features

  • βœ… Lint Job: Pyright (backend) + ESLint (frontend)
  • βœ… Test Job: Pytest 36 tests + Vitest frontend tests
  • βœ… Build Job: Docker images pushed to GitHub Container Registry
  • βœ… Deploy Job: Staging environment with smoke tests
  • βœ… Trigger: On push/PR to main branch

Production Features

  • Configuration Management: Fail-fast env var validation
  • Database: PostgreSQL with connection pooling and pre-ping
  • Rate Limiting: Redis-backed, scales across instances
  • Logging: Structured JSON to stdout
  • Health Check: /api/health verifies database connectivity
  • HTTPS: Nginx config ready β€” uncomment SSL block and provide certs

πŸ”’ Security Notes

⚠️ Important: Sensitive data is managed via environment variables in production!

Secret Key Management:

  • Development: Set in .env file (not committed to git)
  • Production: Set in server environment variables
  • Generate secure key: python -c "import secrets; print(secrets.token_urlsafe(32))"

Database Credentials:

  • Never commit database passwords to version control
  • Use .env for local development (in .gitignore)
  • Use server environment variables for production

πŸ“ Additional Features

Beyond typical project requirements, this project includes:

  • Comprehensive error handling with global handlers (400/404/405/429/500)
  • JWT error handlers (expired, invalid, missing tokens)
  • Frontend error boundary with sanitized error display
  • Automatic token refresh with failed request queuing
  • Soft delete for data recovery compliance
  • Database connection pooling for production performance
  • Worker recycling in Gunicorn to prevent memory leaks

🀝 Contributing

This is a portfolio project demonstrating full-stack development with production-ready practices.

πŸ“„ License

MIT License

πŸ‘¨β€πŸ’» Author

Yousaf Zeb β€” Full-Stack Software Engineer Project completed: April 2026 Stack: React, TypeScript, Flask, PostgreSQL, Redis, Docker, OpenAI

About

Production-ready full-stack AI business operations app with React, TypeScript, Flask, PostgreSQL, Redis, Docker, and CI/CD pipeline.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors