# 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:** ```bash python -m pytest tests/ ``` --- ## ๐Ÿ”ง Configuration Files ### pyproject.toml Package metadata and dependencies: ```toml [project] name = "smartkdb" version = "5.0.0" dependencies = ["fastapi", "uvicorn", ...] ``` ### pyrightconfig.json IDE type checking settings: ```json { "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 1. **Modularity**: Each component is independent 2. **Extensibility**: Plugin system for custom features 3. **Type Safety**: Full type hints for IDE support 4. **Documentation**: Every public API is documented 5. **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](CONTRIBUTING.md)