SmartKDB Project Structure๏
This document explains the organization of the SmartKDB v5 codebase.
๐ Root Directory๏
smartkdb/
โโโ smartkdb/ # Main package (the library code)
โโโ docs/ # Documentation
โโโ examples/ # Usage examples
โโโ tests/ # Unit tests
โโโ README.md # Main documentation
โโโ LICENSE # MIT License
โโโ pyproject.toml # Package configuration
โโโ pyrightconfig.json # Type checking config
โโโ smartkdb.pyi # Type stubs for IDEs
โโโ QUICK_REFERENCE.md # Quick API reference
โโโ .gitignore # Git ignore rules
๐ฆ smartkdb/ (Main Package)๏
smartkdb/
โโโ __init__.py # Package exports
โโโ core/ # Core database engine
โ โโโ engine.py # SmartKDB, KTable, QueryBuilder
โ โโโ storage.py # BlockStorage (append-only)
โ โโโ index.py # Primary & secondary indexes
โ โโโ transaction.py # ACID transaction manager
โ โโโ versioning.py # Time-travel & history
โ โโโ distributed.py # Clustering & sync
โ
โโโ ai/ # AI & Intelligence layer
โ โโโ brain.py # Query learning & optimization
โ โโโ trainer.py # Dataset quality tools
โ โโโ llm_connectors.py # LLM integration
โ
โโโ gui/ # Web dashboard
โ โโโ backend.py # FastAPI server
โ โโโ frontend/ # HTML/JS interface
โ โโโ index.html
โ
โโโ plugins/ # Plugin system
โโโ manager.py # Plugin loader
๐ docs/๏
docs/
โโโ USER_GUIDE.md # Beginner tutorial
โโโ DEVELOPER_GUIDE.md # Advanced API guide
โโโ ARCHITECTURE.md # Technical internals
โโโ API_REFERENCE.md # Complete API docs
โโโ INSTALLATION.md # Install instructions
โโโ PUBLISHING_GUIDE.md # How to publish to PyPI
โโโ CHANGELOG.md # Version history
โโโ SECURITY.md # Security policy
โโโ CONTRIBUTING.md # Contribution guide
โโโ INTELLISENSE_UPGRADE.md # IDE setup
๐ก examples/๏
examples/
โโโ quickstart.py # 5-minute interactive tutorial
โโโ transactions.py # ACID transactions demo
โโโ ai_features.py # AI Brain & time-travel
โโโ intellisense_test.py # Test IDE autocomplete
โโโ v5_demo.py # Complete feature showcase
๐งช tests/๏
tests/
โโโ test_core.py # Core functionality tests
To run tests:
python -m pytest tests/
๐ง Configuration Files๏
pyproject.toml๏
Package metadata and dependencies:
[project]
name = "smartkdb"
version = "5.0.0"
dependencies = ["fastapi", "uvicorn", ...]
pyrightconfig.json๏
IDE type checking settings:
{
"typeCheckingMode": "basic",
"pythonVersion": "3.8"
}
smartkdb.pyi๏
Type stubs for IntelliSense - helps IDEs understand the API.
๐๏ธ Data Storage Structure๏
When you create a database, SmartKDB creates this structure:
mydb.kdb/
โโโ tables/
โ โโโ users/
โ โ โโโ data.bin # Actual records
โ โ โโโ pk.idx # Primary key index
โ โ โโโ email.idx # Secondary indexes
โ โโโ products/
โ โโโ ...
โโโ history/ # Version history
โ โโโ users_user123.json
โโโ kdb_brain.json # AI Brain stats
โโโ meta.json # Database metadata
๐ฏ Key Design Principles๏
Modularity: Each component is independent
Extensibility: Plugin system for custom features
Type Safety: Full type hints for IDE support
Documentation: Every public API is documented
Simplicity: Easy to understand, easy to use
๐ Data Flow๏
Write Operation๏
User Code
โ
SmartKDB.create_table()
โ
KTable.__init__()
โ
Storage + Indexes initialized
Insert Operation๏
table.insert(data)
โ
Transaction logging (if tx_id provided)
โ
BlockStorage.write_record()
โ
Update indexes
โ
VersionManager.archive_record()
โ
NodeManager.broadcast_update() (if clustered)
Query Operation๏
table.query().where(...).execute()
โ
QueryBuilder collects filters
โ
Iterate over index
โ
Filter results
โ
Return matches
๐ Adding New Features๏
1. Core Feature๏
Add to smartkdb/core/
2. AI Feature๏
Add to smartkdb/ai/
3. Plugin๏
Add to smartkdb/plugins/
4. Documentation๏
Update relevant files in docs/
5. Example๏
Add demo to examples/
6. Tests๏
Add tests to tests/
Questions? See CONTRIBUTING.md