Overview
KiCad’s architecture is built on a foundation of specialized libraries that provide reusable functionality across all applications. These libraries are organized in a dependency hierarchy, with lower-level libraries having no dependencies on higher-level code.Library Dependency Hierarchy
Foundation Libraries (libs/)
libs/core
Purpose: Foundation library with no external KiCad dependencies
Description: Provides basic utilities and extensions to standard libraries. This is the lowest-level library and should never depend on any KiCad-specific code.
Components:
base64.cpp: Base64 encoding and decoding for binary data serializationutf8.cpp: UTF-8 string handling and conversion utilitiesobservable.cpp: Observer pattern implementation for event notificationprofile.cpp: Performance profiling and timing utilitiesversion_compare.cpp: Semantic version parsing and comparisonwx_stl_compat.cpp: Compatibility layer between wxWidgets and STL
- String encoding for file I/O
- Performance measurement
- Event-driven architecture
- Version management
libs/kimath
Purpose: Mathematical and geometric algorithms
Description: Provides computational geometry, vector math, and algorithms used throughout KiCad for design calculations.
Key components:
-
Geometry primitives:
VECTOR2<T>- 2D vector with templated precisionBOX2<T>- Axis-aligned bounding boxSEG- Line segment with intersection algorithmsSHAPE- Base class for geometric shapes
-
Shape classes:
SHAPE_LINE_CHAIN- Polyline with arcsSHAPE_POLY_SET- Complex polygon with holes using Clipper librarySHAPE_CIRCLE- Circle primitiveSHAPE_ARC- Circular arc segmentSHAPE_RECT- RectangleSHAPE_COMPOUND- Composite of multiple shapes
-
Algorithms:
- Polygon intersection and union (via Clipper2)
- Point-in-polygon testing
- Distance calculations
- Convex hull computation
- Polygon offsetting (clearance zones)
- Boolean operations
- Bezier curve evaluation
- Copper pour calculations
- Collision detection
- Clearance validation
- Design rule checking
- Keepout zone management
libs/kiplatform
Purpose: Operating system abstraction layer
Description: Provides platform-specific functionality with a unified API, isolating OS differences.
Platform support:
- Linux (GTK3/Wayland/X11)
- Windows
- macOS
-
Application integration:
- Window manager hints
- Desktop environment integration
- System tray/dock support
- File association handling
-
Hardware access:
- GPU detection and capabilities
- Display scaling (HiDPI)
- 3D mouse support (SpaceMouse)
- Keyboard layout detection
-
File system:
- Path normalization
- Temporary directory management
- System directory locations
- Permission handling
-
Security:
- Sandboxing support
- Privilege escalation (when needed)
- Certificate validation
libs/sexpr
Purpose: S-expression parser and serializer
Description: Fast, lightweight S-expression handling used for KiCad’s native file formats.
Features:
- Recursive descent parser
- Streaming support for large files
- Efficient memory usage
- Error reporting with line numbers
.kicad_sch files):
- Schematic files (
.kicad_sch) - PCB files (
.kicad_pcb) - Symbol libraries (
.kicad_sym) - Footprint files (
.kicad_mod)
libs/kinng
Purpose: NNG (nanomsg) wrapper for IPC
Description: Message queue implementation for the KiCad IPC API, enabling external tool communication.
Features:
- Request/response patterns
- Publish/subscribe messaging
- Pipeline communication
- Survey/respondent patterns
- External automation tools
- CI/CD integration
- Custom scripting environments
- Third-party plugin communication
KICAD_IPC_API is enabled.
Common Library (common/)
Overview
Thecommon library provides the application framework shared by all KiCad applications. It’s significantly larger than the foundation libraries and contains most of the EDA-specific functionality.
Tool Framework (common/tool/)
Purpose: Event-driven interactive tool architecture
Key classes:
TOOL_MANAGER
Manages tool lifecycle and event dispatch:
TOOL_ACTION
Defines discrete user actions:
TOOL_EVENT
Represents user input events:
- Mouse events (click, drag, move)
- Keyboard events
- Action triggers
- Tool-specific events
TOOL_DISPATCHER
Routes OS events to tools:
- Converts wxWidgets events to
TOOL_EVENT - Manages event queue
- Handles event propagation
- Decoupled tool implementation
- Testable without UI
- Keyboard shortcut management
- Context-sensitive actions
Graphics Abstraction Layer (common/gal/)
Purpose: Hardware-accelerated 2D rendering
Backends:
OpenGL
- GPU-accelerated rendering
- Vertex buffer objects (VBO)
- Shader-based pipeline
- Best performance for large designs
Cairo
- Software fallback
- Print output
- PDF/SVG generation
- Consistent output across platforms
- Layer compositing
- Anti-aliasing
- Grid rendering
- Cursor management
- Pick-and-place optimization
- Bitmap caching for static elements
View System (common/view/)
Purpose: Canvas and viewport management
Key classes:
VIEW
Manages visible items and layers:
VIEW_ITEM
Base class for renderable objects:
PAINTER
Rendering strategy:
- Spatial indexing (R-tree)
- Dirty region tracking
- Layer visibility control
- Z-order management
- Viewport clipping
I/O Framework (common/io/)
Purpose: File format parsers and writers
Supported formats:
Native KiCad
- S-expression based (
.kicad_*) - Legacy formats (older versions)
Import formats
- Altium:
.PcbDoc,.SchDoc - EAGLE:
.brd,.sch - EasyEDA: JSON-based
- CADSTAR: Archive formats
- PADS:
.asc,.dra - Gerber: RS-274X
- DXF/DWG: CAD exchange
- IDF: Board outlines
Settings Management (common/settings/)
Purpose: Configuration persistence and migration
Key components:
JSON_SETTINGS
Base settings class:
Settings types
- Application settings: Per-application preferences
- Project settings: Per-project configuration
- Color themes: Rendering preferences
- Library tables: Symbol/footprint paths
Migration
- Version tracking
- Automatic upgrades
- Backwards compatibility
Font Rendering (common/font/)
Font types:
Stroke Font
- Vector-based (lines and arcs)
- Compact representation
- Fast rendering
- Used for default text
Outline Font
- TrueType/OpenType support
- HarfBuzz shaping
- FreeType rendering
- Better typography
- Font selection
- Text shaping (HarfBuzz)
- Glyph rasterization (FreeType)
- GAL drawing commands
Plotters (common/plotters/)
Purpose: Manufacturing output generation
Formats:
- Gerber (RS-274X): PCB fabrication
- PDF: Documentation
- SVG: Web and documentation
- DXF: CAD exchange
- HPGL: Legacy plotting
- PostScript: Printing
KIWAY Architecture
Purpose
KIWAY is KiCad’s inter-module communication system, enabling separate DSOs (Dynamic Shared Objects) to communicate within a single process.Key Concepts
KIFACE (KiCad Interface)
KIWAY (Communication Bus)
- Loose coupling between modules
- Dynamic loading of DSOs
- Python integration per module
- Separate compilation units
- Memory isolation
Message Passing
ExpressMail: Send commands between modules- Opening files across applications
- Synchronizing project state
- Cross-probing (schematic ↔ PCB)
- Updating netlists
See Also
- Codebase Structure - Directory organization
- Plugin System - Extending KiCad
- File Formats - Data formats