Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

314 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ุจูŽุญู’ุฑ (BAHR) - Arabic Poetry Analysis Platform

BAHR Logo

ู†ุธุงู… ุฐูƒูŠ ู„ุชุญู„ูŠู„ ุงู„ุดุนุฑ ุงู„ุนุฑุจูŠ
Intelligent Arabic Poetry Analysis System

License: MIT Backend CI Frontend CI Deploy

Next.js FastAPI TypeScript Python Tailwind CSS

English | ุงู„ุนุฑุจูŠุฉ


๐ŸŒŸ Overview

BAHR (ุจูŽุญู’ุฑ, meaning "sea" or "meter" in Arabic) is a comprehensive platform for analyzing and understanding Arabic classical poetry through advanced NLP techniques and prosodic analysis.

๐Ÿš€ Live Demo

โœจ The platform is LIVE in production!

Production Stats:

  • โœ… 98.1% meter detection accuracy
  • โœ… 16 classical Arabic meters supported
  • โœ… Redis caching (5-10x speedup)
  • โœ… 220 passing tests, 99% coverage

โœจ Key Features

  • ๐ŸŽผ Meter Detection - Automatic identification of Arabic poetic meters (ุงู„ุจุญูˆุฑ)
  • ๐Ÿ“Š Syllable Segmentation - Precise prosodic analysis using CAMeL Tools
  • โœจ Rhyme Analysis - Pattern extraction and validation
  • ๐ŸŒ RTL-First UI - Beautiful Arabic-first interface with Next.js 16
  • ๐Ÿ” Real-time Analysis - Instant feedback on poetry structure
  • ๐Ÿ“š Golden Dataset - 52 annotated classical verses for testing

๐Ÿš€ Quick Start

Frontend (Next.js 16)

cd src/frontend
npm install
npm run dev

Visit: http://localhost:3000

Backend (FastAPI)

cd src/backend

# Install as editable package (recommended)
pip install -e .

# Or install dependencies directly
pip install -r requirements.txt

# Start server
uvicorn app.main:app --reload

Visit: http://localhost:8000/docs


๐Ÿ—๏ธ Tech Stack

Frontend

  • Framework: Next.js 16.0.1 with App Router
  • Language: TypeScript (strict mode)
  • Styling: Tailwind CSS v4
  • Components: shadcn/ui (New York style)
  • Fonts: Cairo (UI) + Amiri (poetry) via next/font/google
  • RTL: Native dir="rtl" support

Backend

  • Framework: FastAPI 0.115+
  • Language: Python 3.11+
  • NLP: CAMeL Tools for Arabic processing
  • Database: PostgreSQL 15+ with SQLAlchemy
  • Cache: Redis 7+
  • Migration: Alembic

DevOps

  • Containerization: Docker + Docker Compose
  • CI/CD: GitHub Actions
  • Deployment: Railway (backend) + Vercel (frontend)

๐Ÿ“‚ Project Structure

BAHR/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ backend/           # FastAPI backend
โ”‚   โ”‚   โ”œโ”€โ”€ app/          # Application code
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ api/      # API routes
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ core/     # Core prosody engine
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ml/       # ML models & training
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ db/       # Database models
โ”‚   โ”‚   โ”œโ”€โ”€ alembic/      # Database migrations
โ”‚   โ”‚   โ””โ”€โ”€ tests/        # Backend unit tests
โ”‚   โ””โ”€โ”€ frontend/          # Next.js 16 frontend
โ”‚       โ”œโ”€โ”€ src/
โ”‚       โ”‚   โ”œโ”€โ”€ app/      # App Router pages
โ”‚       โ”‚   โ””โ”€โ”€ components/ # React components
โ”‚       โ””โ”€โ”€ public/        # Static assets
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ raw/              # Raw ML datasets (158 JSONL files)
โ”‚   โ”œโ”€โ”€ processed/        # Processed datasets & golden set
โ”‚   โ””โ”€โ”€ interim/          # Intermediate processing files
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ api/              # API documentation
โ”‚   โ”œโ”€โ”€ research/         # Research documentation
โ”‚   โ”œโ”€โ”€ technical/        # Technical specs
โ”‚   โ”œโ”€โ”€ deployment/       # Deployment guides
โ”‚   โ”œโ”€โ”€ refactor/         # Refactoring documentation
โ”‚   โ””โ”€โ”€ releases/         # Release notes
โ”œโ”€โ”€ results/
โ”‚   โ”œโ”€โ”€ ml/               # ML training results
โ”‚   โ”œโ”€โ”€ evaluations/      # Model evaluations
โ”‚   โ””โ”€โ”€ diagnostics/      # Analysis outputs
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ integration/      # Integration tests
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ ml/               # ML training scripts
โ”‚   โ”œโ”€โ”€ ml_pipeline/      # ML pipeline & training
โ”‚   โ”œโ”€โ”€ tools/            # Development tools
โ”‚   โ”œโ”€โ”€ data_processing/  # Data processing scripts
โ”‚   โ”œโ”€โ”€ setup/            # Environment setup
โ”‚   โ””โ”€โ”€ refactor/         # Migration scripts
โ”œโ”€โ”€ models/                # Trained ML models
โ”œโ”€โ”€ infrastructure/        # Docker & deployment
โ””โ”€โ”€ archive/               # Historical documentation
    โ”œโ”€โ”€ phases/           # Phase reports
    โ””โ”€โ”€ sessions/         # Session summaries

Note: Repository was refactored on November 14, 2025 for production readiness. Backward compatibility symlinks removed after successful migration. See docs/refactor/ for details.


๐Ÿ“– Documentation

๐ŸŽฏ Essential Guides

๐Ÿ“‚ Documentation Structure

๐Ÿ“‹ November 14, 2025 Update: Repository refactored for production readiness.
See docs/refactor/Repo_Refactor_Plan.md for complete details.


๐ŸŽฏ Current Status

๐ŸŽ‰ PHASE 1 COMPLETE - LIVE IN PRODUCTION!

Phase: All of Phase 1 (Weeks 1-8) โœ… COMPLETE Progress: 100% of MVP - DEPLOYED TO PRODUCTION Launch Date: November 10, 2025

โœ… Completed

  • Complete technical documentation (40+ files)
  • Next.js 16 frontend with RTL + Arabic fonts
  • Golden dataset v0.20 (52 annotated verses)
  • FastAPI backend with CORS middleware
  • Docker Compose configuration (PostgreSQL + Redis)
  • CI/CD workflows (GitHub Actions)
  • Prosody Engine Core (Week 1-2)
    • Text normalization with CAMeL Tools
    • Phonetic analysis (CV pattern extraction)
    • Taqti3 algorithm (syllable segmentation)
    • Bahr detection (4 meters: ุงู„ุทูˆูŠู„ุŒ ุงู„ูƒุงู…ู„ุŒ ุงู„ุฑู…ู„ุŒ ุงู„ูˆุงูุฑ)
    • 98.1% accuracy on test dataset โœ… (exceeds 90% target)
  • Database & Infrastructure
    • Alembic migrations with 8 performance indexes
    • 16 Arabic meters + 8 prosodic feet seeded
    • PostgreSQL 15 running in Docker
  • Testing & Quality
    • 220 passing tests
    • 99% code coverage
    • Accuracy test suite with golden dataset
  • Production Readiness (Week 0)
    • Railway CLI installed
    • CORS policy configured
    • Database indexes documented (ADR-002)

๏ฟฝ In Progress

  • Railway project setup (CLI ready, need to create project)
  • API endpoints implementation (Week 2)
  • Frontend-Backend integration

๐Ÿ“… Upcoming

  • Production deployment to Railway + Vercel
  • Authentication & user management
  • Performance optimization

๐Ÿ› ๏ธ Developer Productivity

Shell Aliases (Optional but Recommended)

BAHR includes a comprehensive set of shell aliases for common development tasks. To use them:

# Add to your ~/.zshrc
source /Users/YOUR_USERNAME/Desktop/Personal/BAHR/.bahr_aliases.sh

# Reload shell
source ~/.zshrc

Available commands:

  • bahr-help - Show all available commands
  • bahr-setup - Complete environment setup
  • bahr-start/stop/restart - Manage Docker services
  • bahr-migrate - Run database migrations
  • bahr-test - Run tests with coverage
  • bahr-backend/frontend - Start development servers
  • Plus 30+ more utilities for navigation, testing, and database management

See the full command list by running bahr-help after sourcing the aliases file.


๐Ÿค Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Development Workflow

# 1. Fork and clone
git clone https://github.com/YOUR_USERNAME/BAHR.git
cd BAHR

# 2. Create feature branch
git checkout -b feature/your-feature-name

# 3. Make changes and test
npm test          # Frontend tests
pytest            # Backend tests

# 4. Commit and push
git commit -m "feat: add your feature"
git push origin feature/your-feature-name

# 5. Create Pull Request

๐Ÿ“Š Dataset

The project includes a Golden Dataset of 42 manually annotated classical Arabic verses:

  • โœ… Schema-validated JSONL format
  • โœ… Prosodic annotations (meters, feet, rhymes)
  • โœ… Metadata (poet, era, source)
  • โœ… Quality assurance reports

See dataset/evaluation/README.md


๐Ÿ” Security

  • ๐Ÿ”’ JWT-based authentication
  • ๐Ÿ›ก๏ธ OWASP Top 10 compliance
  • ๐Ÿ” Secrets management via Railway/Vercel
  • ๐Ÿšซ Rate limiting & DDoS protection

See docs/technical/SECURITY.md


๐Ÿ“„ License

This project is licensed under the MIT License - see LICENSE file for details.


๐Ÿ™ Acknowledgments

  • CAMeL Tools - Arabic NLP toolkit
  • shadcn/ui - Beautiful UI components
  • Next.js Team - Amazing React framework
  • FastAPI - High-performance Python framework

๐Ÿ“ž Contact & Support


Built with โค๏ธ for Arabic Poetry Enthusiasts

โญ Star us on GitHub | ๐Ÿ“– Read the Docs | ๐Ÿ› Report Bug


๐Ÿ‡ธ๐Ÿ‡ฆ ุงู„ู†ุณุฎุฉ ุงู„ุนุฑุจูŠุฉ

ู†ุธุฑุฉ ุนุงู…ุฉ

ุจูŽุญู’ุฑ ู‡ูˆ ู…ู†ุตุฉ ุดุงู…ู„ุฉ ู„ุชุญู„ูŠู„ ูˆูู‡ู… ุงู„ุดุนุฑ ุงู„ุนุฑุจูŠ ุงู„ูƒู„ุงุณูŠูƒูŠ ู…ู† ุฎู„ุงู„ ุชู‚ู†ูŠุงุช ู…ุนุงู„ุฌุฉ ุงู„ู„ุบุงุช ุงู„ุทุจูŠุนูŠุฉ ุงู„ู…ุชู‚ุฏู…ุฉ ูˆุงู„ุชุญู„ูŠู„ ุงู„ุนุฑูˆุถูŠ.

ุงู„ู…ู…ูŠุฒุงุช ุงู„ุฑุฆูŠุณูŠุฉ

  • ๐ŸŽผ ูƒุดู ุงู„ุจุญูˆุฑ ุงู„ุดุนุฑูŠุฉ - ุชุญุฏูŠุฏ ุชู„ู‚ุงุฆูŠ ู„ู„ุฃูˆุฒุงู† ุงู„ุนุฑูˆุถูŠุฉ
  • ๐Ÿ“Š ุงู„ุชู‚ุทูŠุน ุงู„ุนุฑูˆุถูŠ - ุชุญู„ูŠู„ ุฏู‚ูŠู‚ ู„ู„ู…ู‚ุงุทุน ุงู„ุตูˆุชูŠุฉ
  • โœจ ุชุญู„ูŠู„ ุงู„ู‚ูˆุงููŠ - ุงุณุชุฎุฑุงุฌ ูˆุงู„ุชุญู‚ู‚ ู…ู† ุฃู†ู…ุงุท ุงู„ู‚ุงููŠุฉ
  • ๐ŸŒ ูˆุงุฌู‡ุฉ ุนุฑุจูŠุฉ ุฃุตูŠู„ุฉ - ุชุตู…ูŠู… ุฌู…ูŠู„ ูŠุฏุนู… ุงู„ุนุฑุจูŠุฉ ุจุงู„ูƒุงู…ู„
  • ๐Ÿ” ุชุญู„ูŠู„ ููˆุฑูŠ - ุฑุฏูˆุฏ ูุนู„ ู…ุจุงุดุฑุฉ ุนู„ู‰ ุจู†ูŠุฉ ุงู„ู‚ุตูŠุฏุฉ
  • ๐Ÿ“š ู…ุฌู…ูˆุนุฉ ุจูŠุงู†ุงุช ุฐู‡ุจูŠุฉ - 42 ุจูŠุชู‹ุง ูƒู„ุงุณูŠูƒูŠู‹ุง ู…ูุดูŽุฑูŽู‘ุญู‹ุง

ุงู„ุจุฏุก ุงู„ุณุฑูŠุน

# ุงู„ูˆุงุฌู‡ุฉ ุงู„ุฃู…ุงู…ูŠุฉ
cd frontend && npm install && npm run dev

# ุงู„ุฎู„ููŠุฉ (ู‚ุฑูŠุจู‹ุง)
cd backend && pip install -r requirements.txt

ุงู„ุญุงู„ุฉ ุงู„ุญุงู„ูŠุฉ

ุงู„ู…ุฑุญู„ุฉ: ุงู„ู…ุฑุญู„ุฉ 0 ู…ูƒุชู…ู„ุฉ โœ…
ุงู„ุชู‚ุฏู…: 60%

  • โœ… ุงู„ุชูˆุซูŠู‚ ุงู„ูƒุงู…ู„
  • โœ… ุงู„ูˆุงุฌู‡ุฉ ุงู„ุฃู…ุงู…ูŠุฉ (Next.js 16)
  • โœ… ู…ุฌู…ูˆุนุฉ ุงู„ุจูŠุงู†ุงุช ุงู„ุฐู‡ุจูŠุฉ
  • ๐Ÿ”„ ุชุทูˆูŠุฑ ุงู„ุฎู„ููŠุฉ (ุงู„ุฃุณุจูˆุน 1)

ุตูู†ุน ุจุญุจ โค๏ธ ู„ุนุดุงู‚ ุงู„ุดุนุฑ ุงู„ุนุฑุจูŠ

Releases

Packages

Contributors

Languages