First off, thanks for taking the time to contribute!
The following is a set of guidelines for contributing to this project. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
This project and everyone participating in it is governed by our Code of Conduct. By participating, you are expected to uphold this code.
- Fork the repository
- Clone your fork:
git clone https://github.com/your-username/KeepAI.git - Create a feature branch:
git checkout -b feature/amazing-feature - Set up your local environment (see below)
- Make your changes
- Run tests and linting
- Commit and push
- Open a pull request
- Python 3.11+
- Docker & Docker Compose v2+ (recommended)
- PostgreSQL 15 (if running without Docker)
- Ollama (running locally or in Docker)
- Node.js 20+ (for frontend development)
cd backend
# Create virtual environment
python -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Copy and configure environment
cp .env.example .env
# Edit .env with your local settings
# Run migrations
alembic upgrade head
# Start the server
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000cd frontend
# Install dependencies
npm install
# Start dev server (proxies /api to localhost:8000)
npm run devdocker compose -f docker/docker-compose.yml up --buildThe project is a monorepo with two main directories:
KeepAI/
+-- backend/ # Python FastAPI backend
| +-- src/
| | +-- main.py # FastAPI app entrypoint
| | +-- core/ # Core domain and interfaces
| | | +-- config.py # Pydantic settings
| | | +-- database.py # DB session management
| | | +-- middleware.py # Request ID middleware
| | | +-- rate_limit.py # Slowapi rate limiter
| | | +-- interfaces/ # Abstract interfaces (ports)
| | | +-- llm_interface.py
| | +-- infrastructure/ # Adapters
| | | +-- llm/
| | | +-- ollama_client.py
| | +-- modules/ # Feature modules
| | +-- admin/ # Admin endpoints
| | +-- analytics/ # Usage analytics
| | +-- api_keys/ # API key management
| | +-- auth/ # Authentication
| | +-- conversations/ # Conversation threads
| | +-- documents/ # Document RAG
| | +-- models/ # Model management
| | +-- prompts/ # Prompt CRUD
| | +-- rag/ # RAG (stub)
| | +-- ws/ # WebSocket chat
| +-- tests/ # Backend tests
| +-- alembic/ # Database migrations
+-- frontend/ # React TypeScript frontend
| +-- src/
| +-- main.tsx # React entry
| +-- App.tsx # Routes and layout
| +-- context/ # Auth context
| +-- api/ # API client functions
| +-- pages/ # Page components
| +-- components/ # Shared components
| +-- types/ # TypeScript interfaces
+-- docker/ # Docker configs
| +-- docker-compose.yml
| +-- backend/Dockerfile
| +-- frontend/Dockerfile
| +-- frontend/nginx.conf
+-- docs/ # Documentation
Each feature module follows Clean Architecture:
src/modules/{feature}/
+-- __init__.py
+-- models.py # SQLAlchemy ORM models
+-- schemas.py # Pydantic request/response schemas
+-- service.py # Business logic
+-- router.py # FastAPI route definitions
+-- utils.py # Helper functions (optional)
+-- agents/
+-- {agent}.py # Domain-specific LLM agents
We use Ruff for linting and formatting. Configuration is in backend/pyproject.toml.
cd backend
ruff check src/ tests/
ruff format src/ tests/- Line length: 120 characters
- Quotes: Double quotes (
") - Imports: isort-style (stdlib, third-party, local) with blank lines between groups
- Type hints: Required for all function signatures
- Async: Use async/await for I/O operations (DB, HTTP calls)
- Naming:
snake_casefor variables/functions,PascalCasefor classes,UPPER_CASEfor constants - Docstrings: Use docstrings for public modules, classes, and functions
- Strict mode enabled in
tsconfig.json - Naming:
camelCasefor variables/functions,PascalCasefor components/types/interfaces - Imports: Use named exports, group by external/internal
- Interface segregation: Depend on abstractions, not concretions
- Dependency injection: Pass dependencies through constructors or function parameters
- Separation of concerns: Each module has router, service, schemas, models
- Testability: Write tests for all services with mocked dependencies
cd backend
# Run all tests
python -m pytest
# Run with coverage
python -m pytest --cov=src
# Run specific test file
python -m pytest tests/api/test_auth.py
# Run tests matching a pattern
python -m pytest -k "invoice"cd frontend
# TypeScript type check
npx tsc --noEmit
# Build (smoke test)
npm run build- Write tests for services with mocked LLM and database
- Write tests for API endpoints with mocked dependencies
- Use pytest fixtures from
tests/conftest.pyfor common setup - Tests should be fast — mock external services
- Name test files with
test_prefix
- Ensure all tests pass:
python -m pytest(backend) +npm run build(frontend) - Ensure linting passes:
ruff check .(Python) - Update documentation if you change APIs
- Add tests for new features
- Update the Changelog with your changes
- PRs require at least one review before merging
- Squash commits before merging
<type>: <short description>
Types: feat, fix, docs, style, refactor, test, chore, ci
Example: feat: add streaming response support
Bugs are tracked as GitHub Issues.
Before submitting:
- Check if the bug has already been reported
- Check if it exists in the latest version
- Include detailed steps to reproduce
- Include logs, screenshots, and environment details
Feature suggestions are welcome! Please:
- Check existing issues for similar requests
- Describe the problem you're solving
- Explain the proposed solution
- Include any alternative approaches considered
- Getting Started — Project overview
- Architecture — System design
- API Reference — Full API reference
- Deployment Guide — Production deployment
- Next Steps — Planned improvements
Thank you for contributing! Every issue, feature request, and pull request makes this project better for everyone.