Skip to content

imtiaj-007/docugenie-backend

Repository files navigation


Docugenie Banner
python fastapi postgresql docker gemini

Your AI genie for PDFs and documents - A FastAPI backend service for intelligent document assistant.

  1. πŸ€– Introduction
  2. βš™οΈ Tech Stack
  3. πŸ”‹ Features
  4. πŸ› οΈ Architecture
  5. 🀸 Getting Started
  6. πŸ“‚ Project Structure
  7. πŸš€ Miscellaneous

Checkout the frontend code: Docugenie Frontend

DocuGenie is an AI-powered chat assistant that helps you extract insights, summarize content, analyze PDF documents and other file formats, generate diagrams and visualizations, create comprehensive plans, perform agentic tasks, and generate AI-powered documents. It provides intelligent document processing capabilities including text extraction, content analysis, automated summarization, diagram generation, planning assistance, and AI document creation.

Frontend

  • Next.js - React framework for server-side rendering and routing
  • React.js - Component-based UI library
  • Tailwind CSS - Utility-first CSS framework for styling
  • shadcn/ui - Accessible UI component library

Backend

  • Python >=3.10 - Programming language
  • FastAPI - Modern web framework with async support
  • Pydantic - Data validation and settings management
  • SQLAlchemy - Database ORM and management
  • Alembic - Database migrations
  • PostgreSQL - Primary database system
  • FAISS - Vector similarity search and clustering
  • LangChain - AI model integration and RAG pipelines

AI/ML

  • Google Gemini - Primary LLM for text generation
  • HuggingFace - Embedding models and transformers
  • OpenAI - Alternative LLM provider

Infrastructure

  • Docker - Containerization
  • Poetry - Python dependency management
  • pnpm - JavaScript/TypeScript package manager
  • Prettier - Code formatter for frontend codebase
  • ESLint - JavaScript/TypeScript linting
  • Jest - JavaScript/TypeScript testing framework
  • Pytest - Python testing framework
  • Ruff - Python code linting and formatting

Document Processing

  • πŸ“„ Multi-format document support (PDF, DOCX, TXT)
  • πŸ” Intelligent text extraction and parsing
  • 🧠 AI-powered content analysis and summarization
  • πŸ“Š Automated diagram and visualization generation (Coming Soon...)

Chat & AI Capabilities

  • πŸ’¬ Context-aware document conversations
  • πŸ” Semantic search across document collections
  • πŸ“ AI-powered document creation and editing (Coming Soon...)
  • 🎯 Agentic task execution (Coming Soon...)

Technical Features

Backend

  • πŸ—„οΈ PostgreSQL with SQLAlchemy ORM
  • πŸ”„ Alembic database migrations
  • πŸš€ FastAPI with high-performance endpoints
  • πŸ“‹ Pydantic models for robust data validation
  • πŸ” FAISS vector database for efficient similarity search

Frontend

  • ⚑ Next.js for fast server-side rendering and routing
  • βš›οΈ Modular component architecture with React.js
  • πŸ’Ž shadcn/ui for accessible, modern UI components
  • 🎨 Tailwind CSS for utility-first, customizable styling
  • πŸ› οΈ TypeScript support for type-safe frontend development
  • ♻️ pnpm for efficient JavaScript/TypeScript package management
  • πŸ§ͺ Jest for robust frontend testing
  • ✨ Prettier & ESLint for consistent code style and linting

The system leverages LangChain AI models, FAISS vector database, and RAG (Retrieval-Augmented Generation) pipeline to provide intelligent document analysis and conversational interactions.

Document Processing Pipeline:

The document processing pipeline transforms raw documents into searchable, intelligent knowledge bases:

Document Processing Pipeline

Key Components:

  • Parser & Tokenizer: Extracts text content and breaks it into manageable chunks
  • LangChain AI Models: Generates embeddings using state-of-the-art language models
  • FAISS Vector Database: Stores and indexes vectors for efficient similarity search
  • Metadata Database: Maintains document metadata, chunk references, and user sessions

Chat & RAG Pipeline:

The chat system provides intelligent, context-aware responses using retrieved document knowledge:

Document Processing Pipeline

Key Components:

  • Chat Orchestrator: Manages conversation flow, session context, and query understanding
  • RAG Pipeline: Retrieves relevant document chunks using vector similarity search
  • FAISS Vector DB: Provides fast and accurate semantic search capabilities
  • Prompt Manager: Optimizes prompts with context injection and formatting guidelines
  • LangChain AI: Generates intelligent responses using retrieved context

Prerequisites

  • Python - >=v3.10
  • PostgreSQL - >=v16
  • Poetry - >=v2.2.0 (recommended) or pip
  1. Clone the repository
git clone https://github.com/imtiaj-007/docugenie-backend.git

cd docugenie-backend
  1. Setup virtual environment
# Using Poetry (recommended):
poetry shell

# Using virtualenv (alternative):
python -m venv venv
source venv/bin/activate  # On Linux/MacOS
venv\Scripts\activate     # On Windows

You can use the project in 2 ways -

  • Using Poetry (recommended): Poetry is a modern python package manager similar to npm, it helps to add, install and manage dependencies and running scripts on our application.

    Along with poetry you can utilize the Poe the Poet commands such as -

    poetry run poe dev
    poetry run poe test
    poetry run poe lint
    poetry run poe format

    or alternatively use the MakeFile commands:

    make dev
    make test
    make lint
    make format

    refer to Available Commands section for detailed overview of available commands for this project

  • Using Pip: pip is the default python package installer used to install and manage software packages.

  1. Install dependencies
# Using Poetry
poetry install

# Traditional Way
pip install -r requirements.txt        # Install production dependencies
pip install -r requirements-dev.txt    # Install with dev dependencies
  1. Run the application
# Using Poetry
poetry run docugenie
poetry run test

# Using Make commands
make dev
make test

# Traditional Way
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
pytest tests/ -v --cov=app --cov-report=html
docugenie-backend/
β”œβ”€β”€ .github/                 # GitHub Actions and CI/CD workflows
β”‚   └── workflows
β”œβ”€β”€ .vscode/                 # VSCode editor configuration
β”‚   β”œβ”€β”€ settings.json
β”‚   └── extensions.json
β”œβ”€β”€ public                   # Public assets (e.g., images, logos)
β”œβ”€β”€ app/                     # Main backend application code
β”‚   β”œβ”€β”€ ai                   # Modules for AI and LLM integrations
β”‚   β”œβ”€β”€ api                  # API route definitions and endpoints
β”‚   β”œβ”€β”€ aws                  # AWS utilities and integrations
β”‚   β”œβ”€β”€ core                 # Core application logic and utility functions
β”‚   β”œβ”€β”€ db                   # Database models and initialization
β”‚   β”œβ”€β”€ middlewares          # FastAPI middleware definitions
β”‚   β”œβ”€β”€ services             # Business logic and service layers
β”‚   β”œβ”€β”€ schemas              # Pydantic schemas (request/response validation)
β”‚   β”œβ”€β”€ repositories         # Database repositories and CRUD operations
β”‚   └── main.py              # Main entry point for FastAPI app
β”œβ”€β”€ tests                    # Unit and integration tests
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .dockerignore
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.yaml
β”œβ”€β”€ .pre-commit-config.yaml  # Pre-commit hook configuration
β”œβ”€β”€ pyproject.toml           # Python dependencies and configuration
β”œβ”€β”€ poetry.lock              # Poetry lockfile for deterministic installs
β”œβ”€β”€ README.md                # Project documentation
└── LICENSE                  # License information

Available Poetry Commands

[tool.poetry.scripts]
docugenie = "app.main:run_server"

[tool.poe.tasks]
format = "black app tests"
format-check = "black --check app tests"
lint = "ruff check app tests"
lint-fix = "ruff check --fix app tests"
typecheck = "mypy app"

[tool.poe.tasks.check-all]
sequence = ["format-check", "lint", "typecheck"]
ignore_fail = false

Or, run these from shell:

poetry run poe format         # Format code (black)
poetry run poe format-check   # Check formatting (black)
poetry run poe lint           # Lint code (ruff + mypy)
poetry run poe lint-fix       # Fix lint errors (ruff autofix)
poetry run poe typecheck      # Type checks (mypy)
poetry run poe check-all      # Run format check, lint, typecheck in sequence
poetry run docugenie          # Start the FastAPI server

For full config, see pyproject.toml.

Available Make Commands

.PHONY: install dev test lint format clean

install:
	poetry install

dev:
	poetry run uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

test:
	poetry run pytest tests/ -v --cov=app --cov-report=html

test-watch:
	poetry run ptw tests/ -- -v

lint:
	poetry run ruff check .
	poetry run mypy app/

format:
	poetry run black .
	poetry run ruff check --fix .

migrate:
	poetry run alembic upgrade head

migrate-create:
	poetry run alembic revision --autogenerate -m "$(msg)"

clean:
	find . -type d -name __pycache__ -exec rm -rf {} +
	find . -type f -name "*.pyc" -delete
	rm -rf .pytest_cache .coverage htmlcov

docker-up:
	docker-compose up -d

docker-down:
	docker-compose down

CI Pipeline


πŸ“š API Documentation

Once the application is running, access the interactive API docs:

πŸ‘₯ Contributing

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

πŸ“ƒ License

CC BY-NC-SA 4.0 β€” Non-commercial use only. Credit required. Derivatives must be shared alike. Check Details here.

About

Your AI genie for PDFs and documents - A FastAPI backend service for intelligent document assistant.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages