Kode is a learning JavaScript runtime built with modern C++ and libuv, designed to demonstrate how Node.js works internally. The project is organized into modular components for better maintainability and understanding.
kode/
βββ src/ # Source code (organized by feature)
β βββ main.cc # Main entry point
β βββ core/ # Core runtime engine
β β βββ runtime.h # Runtime class definition
β β βββ runtime.cc # Runtime implementation
β βββ parser/ # JavaScript parser
β β βββ parser.h # Advanced parser interface
β β βββ parser.cc # Production-ready parser
β βββ filesystem/ # File system operations
β β βββ fs.h # Legacy FS API
β β βββ fs.cc # Legacy FS implementation
β β βββ modern_fs.h # Modern FS API
β β βββ modern_fs.cc # Modern FS implementation
β βββ examples/ # Example programs
β β βββ simple-test.cpp # Basic V8 test
β βββ tests/ # Test files and demos
βββ bin/ # Compiled binaries
βββ libuv/ # libuv library
βββ v8/ # V8 JavaScript engine
βββ Makefile # Build configuration
βββ README.md # Project documentation
Purpose: Main JavaScript runtime engine Key Features:
- Event loop management (libuv integration)
- Built-in functions (console, timers)
- Module loading and execution
- Memory management
Files:
runtime.h- Class definitions and interfacesruntime.cc- Implementation of runtime logic
Purpose: Advanced JavaScript syntax analysis Key Features:
- AST-like statement representation
- Modern JS syntax support (ES6+, async/await)
- Error recovery and reporting
- Performance monitoring
- 25+ statement types
Files:
parser.h- Parser interface and data structuresparser.cc- Production-ready parsing engine
Purpose: File I/O operations with modern and legacy APIs Key Features:
- Legacy callback-style API (Node.js compatible)
- Modern structured result API (next-generation)
- Async operations with libuv thread pool
- Rich metadata (MIME types, file stats)
- Automatic directory creation
Files:
fs.h/fs.cc- Legacy file system APImodern_fs.h/modern_fs.cc- Next-generation file system API
Purpose: Application entry point and CLI handling Key Features:
- Command-line argument processing
- Demo mode for learning
- Version information
- Usage help
Each component is self-contained with clear interfaces:
#include "core/runtime.h" // Core engine
#include "parser/parser.h" // JavaScript parsing
#include "filesystem/fs.h" // File operations- Extensive comments explaining Node.js concepts
- Demo mode showing different features
- Clear separation of concerns
- Production-ready patterns
- RAII for resource management
- Smart pointers where appropriate
- Exception safety
- STL containers and algorithms
- libuv event loop for async operations
- Thread pool for I/O operations
- Parse time measurement
- Memory-efficient data structures
# Source files organized by component
APP = src/main.cc src/core/runtime.cc src/filesystem/fs.cc \
src/filesystem/modern_fs.cc src/parser/parser.cc
# Dependencies
- libuv (event loop, async I/O)
- V8 (future JavaScript engine integration)make build- Build the main runtimemake clean- Clean build artifactsmake examples- Build example programs
# Run a JavaScript file
./bin/kode script.js
# Execute code directly
./bin/kode -e "console.log('Hello World')"
# Demo mode (shows all features)
./bin/kode// Modern file system API
fs.readFile('data.txt'); // Returns rich metadata
fs.writeFile('out.txt', 'data'); // Auto-creates directories
// Async operations
setTimeout(); // Event loop integration
// Module system
const fs = require('fs'); // CommonJS support- Create appropriate directory under
src/ - Define interface in
.hfile - Implement in
.ccfile - Update
MakefileAPP definition - Add tests/examples
- Update documentation
- Headers: Interface definitions, forward declarations
- Implementation: Logic, error handling, performance code
- Separation: Each component handles one responsibility
- Documentation: Explain the "why" not just the "what"
src/network/- HTTP server implementationsrc/crypto/- Cryptographic functionssrc/streams/- Stream processingsrc/cluster/- Multi-process support
- V8 JavaScript engine (when architecture issues resolved)
- Native module loading
- Debugger protocol
- Performance profiling
This modular architecture makes Kode both educational and extensible, demonstrating professional software organization while teaching Node.js internals.