How coatisoftware/sourcetrail works
Project Type & Purpose
• Sourcetrail is a cross-platform desktop application (C++/Qt) for exploring source code.
• It comprises a GUI front-end, a core application engine, and optional language indexer back-ends (C/C++, Java, Python).
High-Level File-Structure Analysis
• Top level:
• CMakeLists.txt & cmake/ – build orchestration
• src/app – application entrypoint (main.cpp)
• src/lib – core engine libraries (messaging, storage, data model, project management, settings)
• src/lib_gui – Qt-based UI layer (views, controllers, widgets, project wizard)
• src/lib_cxx, src/lib_java, src/lib_python – language-specific indexers and project support modules
• src/indexer – main dispatcher for external indexer processes
• src/external – bundled third-party libraries (Catch2, SQLite, TinyXML)
• deployment/, setup/, script/ – packaging, installation, CI scripts
• src/test, bin/test – automated tests and test data (Catch2 suites)
Core Architecture Components
a. Front-end GUI (src/lib_gui + src/app)
• Qt application, windows, views, controllers
• Implements MVC: controllers handle input/messages, views render data
b. Core Engine (src/lib)
• Messaging bus (inter-module events)
• Task scheduler (indexing, parsing, storage tasks)
• Data model & graph storage (SQLite via storage/sqlite)
• Project management (source group detection, custom commands)
• Settings & migration
c. Language Indexers
• In-process or child processes spawned via src/indexer
• C/C++: uses lib_cxx (Clang AST, compile database)
• Java: uses lib_java (JNI + Gradle tooling API)
• Python: uses prebuilt indexer (downloadable via script)
d. Storage Layer
• Intermediate shared memory (interprocess)
• Persistent SQLite database (SourcetrailDB schema)
• Full-text search index
e. External Dependencies
• Boost (filesystem, IPC), Qt (GUI & process launching), Clang, JDK/Maven, Python indexer
Components & Data Flow
1. User launches GUI (Qt) → core engine initializes
2. User opens a project → core bus broadcasts MessageLoadProject
3. Core engine schedules indexing tasks → indexer process(es) start via src/indexer
4. Indexer(s) parse source → emit SharedIndexerCommand via IPC into IntermediateStorage
5. Core engine polls IPC queue → merges data into persistent SQLite storage
6. UI controllers subscribe to data change messages → query storage layer
7. Views update: code view, graph view, search view, history, bookmarks, etc.
Architectural Patterns & Principles
• Modular layered architecture: separation of GUI, core, indexers, storage
• MVC/MVP in UI (controllers ↔ views ↔ data)
• Plugin-style language packages loaded by LanguagePackageManager
• Messaging / event-driven communication internally (MessageQueue)
• Build & deployment abstractions via CMake & scripts