Skip to content

Latest commit

Β 

History

41 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FastAPI Python PostgreSQL Modal

πŸ₯ Kliniq API

Backend API for AI-Powered Multilingual Healthcare Platform

Powering intelligent healthcare with N-ATLaS β€” our custom multilingual AI model for Nigerian languages and medical contexts.


🌟 Overview

Kliniq API is a production-ready FastAPI backend that powers the Kliniq healthcare platform. It provides secure, scalable APIs for:

  • πŸ€– AI-powered symptom triage with N-ATLaS multilingual model
  • 🎀 Voice transcription and translation across 4 Nigerian languages
  • πŸ‘₯ Patient and clinician management with role-based access
  • πŸ₯ Hospital integration and appointment scheduling
  • πŸ“Š Real-time health analytics and medical records

🧠 N-ATLaS: The AI Engine

At the heart of Kliniq is N-ATLaS (Nigerian-Adapted Translation and Language System), a custom AI model deployed on Modal cloud infrastructure:

Capabilities

Feature Description
πŸ—£οΈ Multilingual Chat Fluent in English, Hausa, Igbo, and Yoruba
🩺 Medical Triage Symptom assessment with urgency classification
πŸ”§ Tool Calling Structured function calls for appointments and triage creation
πŸ“ Context Awareness Incorporates patient history, doctor notes, and appointments
πŸ”„ Translation Seamless translation between all supported languages

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Kliniq Frontend                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       Kliniq API (FastAPI)                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Dashboard  β”‚  β”‚  Clinician  β”‚  β”‚   Messages Module   β”‚  β”‚
β”‚  β”‚   Module    β”‚  β”‚   Module    β”‚  β”‚   (Voice + Text)    β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚         β”‚                β”‚                     β”‚             β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚
β”‚                          β–Ό                                   β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                       β”‚
β”‚              β”‚     LLM Service       β”‚                       β”‚
β”‚              β”‚  (N-ATLaS Interface)  β”‚                       β”‚
β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                           β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚   Modal Cloud GPU     β”‚
              β”‚   (N-ATLaS Model)     β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”— API Modules

πŸ” Authentication (/auth)

  • JWT-based authentication with refresh tokens
  • Email verification and password reset
  • Role-based access control (Patient, Nurse, Doctor)

πŸ“Š Patient Dashboard (/dashboard)

  • Personal health dashboard data
  • AI chat with conversation history
  • Hospital linking via codes
  • Medical notes and vitals tracking

πŸ‘©β€βš•οΈ Clinician Portal (/clinician)

  • Nurse/Doctor dashboard with statistics
  • Patient list with triage status
  • Detailed patient profiles with AI analysis
  • Appointment request management
  • Gamification with points system

πŸ’¬ Messages (/messages)

  • Real-time messaging between patients and clinicians
  • Voice message support with transcription
  • Multi-language translation

πŸ₯ Appointments (/appointments)

  • Appointment scheduling and management
  • Calendar integration
  • Automated reminders

πŸ› οΈ Tech Stack

Category Technology
Framework FastAPI 0.115
Database PostgreSQL 15 + SQLAlchemy 2.0
Async asyncpg, aiohttp
Authentication PyJWT, bcrypt, passlib
AI/LLM Modal (GPU cloud), Custom N-ATLaS model
Validation Pydantic 2.10
Migrations Alembic
Email aiosmtplib

πŸš€ Getting Started

Prerequisites

  • Python 3.11+
  • PostgreSQL 15+
  • Modal account (for AI features)

Installation

# Clone the repository
git clone https://github.com/your-repo/kliniq-api.git
cd kliniq-api

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

Environment Configuration

Create a .env file:

# Database
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/kliniq

# JWT Authentication
SECRET_KEY=your-secret-key-here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7

# Email (optional)
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
MAIL_FROM=noreply@kliniq.com
MAIL_SERVER=smtp.gmail.com
MAIL_PORT=587

# Modal AI Endpoint
MODAL_ENDPOINT_URL=https://your-modal-endpoint.modal.run/generate

Database Setup

# Create database
createdb kliniq

# Run migrations
alembic upgrade head

# Seed test data (optional)
python -m scripts.seed_test_data

Run Development Server

uvicorn src.main:app --reload --port 8001

API documentation available at:


πŸ“‚ Project Structure

kliniq-api/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.py              # FastAPI application entry
β”‚   β”œβ”€β”€ auth/                # Authentication module
β”‚   β”‚   β”œβ”€β”€ dependencies.py  # Auth dependencies
β”‚   β”‚   └── auth_controller.py
β”‚   β”œβ”€β”€ common/
β”‚   β”‚   β”œβ”€β”€ database/        # Database configuration
β”‚   β”‚   └── llm/             # N-ATLaS LLM service
β”‚   β”‚       β”œβ”€β”€ llm_service.py
β”‚   β”‚       β”œβ”€β”€ modal_app.py # Modal deployment
β”‚   β”‚       └── tool_executor.py
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── models.py        # SQLAlchemy models
β”‚   β”œβ”€β”€ modules/
β”‚   β”‚   β”œβ”€β”€ dashboard/       # Patient dashboard
β”‚   β”‚   β”œβ”€β”€ clinician/       # Clinician portal
β”‚   β”‚   β”œβ”€β”€ messages/        # Messaging system
β”‚   β”‚   └── appointments/    # Appointment management
β”‚   └── router/
β”‚       └── routers.py       # API router aggregation
β”œβ”€β”€ alembic/                 # Database migrations
β”œβ”€β”€ scripts/                 # Utility scripts
└── requirements.txt

πŸ”‘ Key Endpoints

Authentication

Method Endpoint Description
POST /auth/register Register new user
POST /auth/login Login and get tokens
POST /auth/refresh Refresh access token
GET /auth/me Get current user

Patient Dashboard

Method Endpoint Description
GET /dashboard Get dashboard data
POST /dashboard/chat Send AI chat message
GET /dashboard/chat/history Get chat history
POST /dashboard/hospitals/link Link to hospital

Clinician Portal

Method Endpoint Description
GET /clinician Get clinician dashboard
GET /clinician/patients List patients
GET /clinician/patient/{id} Patient detail with AI analysis
GET /clinician/requests Get appointment requests
POST /clinician/requests/{id}/approve Approve request
GET /clinician/doctors/{hospital_id} Get doctors by hospital

πŸ§ͺ Testing

# Run tests
pytest

# With coverage
pytest --cov=src

πŸ† Hackathon Highlights

This API was built for Awarri Developer Challenge 2025 demonstrating:

  1. AI Innovation β€” Custom N-ATLaS model for Nigerian healthcare
  2. Production Quality β€” Async architecture, proper error handling, migrations
  3. Security β€” JWT auth, role-based access, input validation
  4. Scalability β€” Modular design, cloud AI deployment on Modal
  5. Real Impact β€” Solving language barriers in Nigerian healthcare

πŸ“„ License

MIT License - See LICENSE for details.


Built with ❀️ for Nigerian Healthcare

About

Multilingual clinical triage API. Serves N-ATLaS on Modal GPUs with vLLM, and adds a tool-calling protocol the model has no native support for.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages