Backend Documentation Index
Welcome to the Yappa Knowledge Hub backend documentation. This documentation provides comprehensive coverage of the Symfony 7.2 backend architecture, APIs, and database design.
Documentation Structure
1. Backend Overview
Complete overview of the backend architecture, technology stack, and design patterns.
Topics Covered:
- Technology stack (Symfony 7.2, PHP 8.2, Doctrine, API Platform)
- Architecture overview (dual-storage pattern with SQLite + Notion)
- Directory structure
- Key components (Controllers, Services, Entities, Repositories)
- Design patterns (Repository, Service Layer, Data Mapper, Dependency Injection)
- Configuration and environment variables
- Performance considerations
- Security best practices
2. Controllers Documentation
Detailed documentation of all 8 HTTP controllers with request/response examples.
Controllers Documented:
- KnowledgeController - Main CRUD operations with Notion sync
- LocalKnowledgeController - SQLite-only read operations
- CategoryController - Category management with auto-sync
- SummaryController - AI summary management
- NotionSyncController - Manual sync operations
- NotionWebhookController - Notion webhook handling
- DigestController - Digest generation
- NotionDigestController - Notion digest operations
Each controller includes:
- Route definitions
- Request/response formats
- Example cURL commands
- Error handling
3. Services Documentation
Complete documentation of all business logic services and external integrations.
Services Documented:
Notion Services:
- NotionClient - Low-level HTTP client for Notion API
- NotionKnowledgeService - Knowledge item operations
- NotionCategoryService - Category operations with emoji support
- NotionSyncService - Bidirectional sync between SQLite and Notion
- NotionPropertyMapper - Property mapping utilities
- NotionDatabaseService - Database-level operations
- NotionDigestService - Digest operations
Application Services:
- OpenAiService - AI completion generation with retry logic and mock mode
- SummaryService - Summary generation and management
- TargetGroupService - Target group management
- SlackHomeRefreshService - Slack integration
Each service includes:
- Constructor parameters
- Method signatures
- Usage examples
- Configuration details
4. Entities Documentation
Comprehensive documentation of all 6 Doctrine entities with ER diagram.
Entities Documented:
- Knowledge - Main knowledge items with Notion sync
- Category - Knowledge categories with target groups
- Resource - External resources (URLs, PDFs, etc.)
- ResourceContent - Content extracted from resources
- Summary - AI-generated summaries
- Tag - Tags for resources
Includes:
- Entity relationship diagram (Mermaid)
- Property definitions with types
- Relationship mappings
- Method documentation
- Usage examples
- Repository patterns
5. Database Documentation
Complete database setup, migration, and management guide.
Topics Covered:
- SQLite configuration
- Database schema (8 tables)
- Migrations guide (creating, running, rolling back)
- Seeding data (fixtures and console commands)
- Querying (Doctrine ORM, DQL, native SQL)
- Backup and restore procedures
- Performance optimization
- Troubleshooting
- Production considerations
6. API Reference
Complete REST API reference with examples in multiple languages.
API Endpoints Documented:
Knowledge Endpoints:
POST /api/knowledge- Create knowledge itemGET /api/knowledge- List/search knowledge itemsGET /api/knowledge/{id}- Get knowledge itemPUT /api/knowledge/{id}- Update knowledge itemDELETE /api/knowledge/{id}- Archive knowledge itemPOST /api/knowledge/search- Search knowledge items
Local Endpoints:
GET /api/local/knowledge- List from SQLiteGET /api/local/categories- List categories from SQLite
Category Endpoints:
POST /api/categories- Create categoryGET /api/categories- List categoriesGET /api/categories/{id}- Get categoryPUT /api/categories/{id}- Update categoryPOST /api/categories/sync- Sync from Notion
Includes:
- Request/response formats
- HTTP status codes
- Error handling
- Client examples (JavaScript, PHP, Python)
- Testing with cURL, HTTPie, Postman
Quick Start
Prerequisites
- PHP 8.2 or higher
- Composer
- SQLite3
Installation
# Navigate to backend directory
cd backend
# Install dependencies
composer install
# Configure environment
cp .env .env.local
# Edit .env.local with your Notion API keys
# Create database
php bin/console doctrine:database:create
# Run migrations
php bin/console doctrine:migrations:migrate
# Load sample data (optional)
php bin/console doctrine:fixtures:load
# Start development server
symfony server:start
# or
php -S localhost:8000 -t publicTesting the API
# List knowledge items
curl http://localhost:8000/api/knowledge
# Create knowledge item
curl -X POST http://localhost:8000/api/knowledge \
-H "Content-Type: application/json" \
-d '{"title": "Test", "content": "Test content"}'Key Features
Dual-Storage Architecture
The backend implements a unique dual-storage pattern:
- SQLite Database - Local persistent storage for fast queries
- Notion API - Cloud-based knowledge management with rich UI
Benefits:
- Fast local queries without network latency
- Rich collaborative features from Notion
- Automatic bidirectional synchronization
- Resilience (works even if Notion is unavailable)
Notion Integration
Full integration with Notion API:
- Create, read, update pages
- Query databases with filters and sorting
- Automatic pagination for large datasets
- Property mapping between Notion and PHP
- Emoji icon support (Slack format Unicode)
- Webhook support for real-time updates
AI Summaries
OpenAI integration for generating summaries:
- Automatic retry logic with exponential backoff
- Mock mode for development/testing
- Configurable model and parameters
- Target group-aware summaries
RESTful API
Clean RESTful JSON API:
- Standard HTTP methods (GET, POST, PUT, DELETE)
- JSON request/response format
- Proper HTTP status codes
- Comprehensive error handling
Architecture Highlights
Design Patterns
- Repository Pattern - Clean data access abstraction
- Service Layer Pattern - Business logic encapsulation
- Data Mapper Pattern - Notion API response mapping
- Dependency Injection - Managed by Symfony container
- Dual-Storage Pattern - Custom pattern for SQLite + Notion
Technology Stack
- Framework: Symfony 7.2
- PHP: 8.2+ with modern features (enums, attributes, typed properties)
- ORM: Doctrine 3.6+ with migrations
- API: API Platform 4.1+ for REST capabilities
- Database: SQLite for local storage
- HTTP Client: Symfony HTTP Client + Guzzle
- Testing: PHPUnit 11.5+
Environment Variables
Required environment variables:
# Database
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# Notion API
NOTION_API_KEY="secret_xxx"
NOTION_KNOWLEDGE_DATABASE_ID="xxx"
NOTION_CATEGORIES_DATABASE_ID="xxx"
# OpenAI API
OPENAI_API_KEY="sk-xxx"
OPENAI_MODEL="gpt-4"
OPENAI_MOCK_MODE="false"Common Tasks
Create a New Entity
php bin/console make:entityGenerate Migration
php bin/console make:migrationRun Migrations
php bin/console doctrine:migrations:migrateCreate Controller
php bin/console make:controllerRun Tests
composer testClear Cache
php bin/console cache:clearTroubleshooting
Database Issues
See Database Documentation for:
- Database locked errors
- Schema out of sync
- Migration failures
- Database corruption
Notion API Issues
Common issues:
- Invalid API key: Check
NOTION_API_KEYin.env.local - Invalid database ID: Verify
NOTION_KNOWLEDGE_DATABASE_ID - Rate limiting: Notion API has rate limits
- Property validation: Ensure properties match Notion schema
Performance Issues
Optimization tips:
- Use local endpoints (
/api/local/*) for read operations - Enable query result caching
- Add indexes to frequently queried columns
- Use pagination for large datasets
Contributing
Code Style
Follow Symfony coding standards:
# Check code style
vendor/bin/php-cs-fixer fix --dry-run
# Fix code style
vendor/bin/php-cs-fixer fixTesting
Write tests for new features:
# Run all tests
composer test
# Run specific test
vendor/bin/phpunit tests/Service/OpenAiServiceTest.php
# Generate coverage report
composer test:coverageAdditional Resources
Symfony Documentation
Notion API
OpenAI API
Support
For questions or issues:
- Check the relevant documentation section
- Review the troubleshooting guides
- Check Symfony/Doctrine/Notion API documentation
- Contact the development team
License
Proprietary - All rights reserved
Changelog
Version 1.0.0 (2026-02-19)
- Initial documentation release
- Complete coverage of all controllers, services, and entities
- Database schema and migration guide
- Comprehensive API reference
- Architecture overview and design patterns
Last Updated: 2026-02-19
Documentation Version: 1.0.0
Backend Version: Symfony 7.2, PHP 8.2