Skip to content

Commit 7ccdf17

Browse files
Add documentation and improve readme. (#16)
* Add documentation and improve readme. * Fix port. * Fix port event. * Add missing docs pages * Update example doc. * Update doc.
1 parent 5bfb8ad commit 7ccdf17

File tree

11 files changed

+255
-25
lines changed

11 files changed

+255
-25
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
.vscode/
3535
build/
36-
docs/
3736

3837
# Cabin package build directory
3938
/cabin-out

CONTRIBUTING.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Contributing to Flow Core
2+
3+
We love your input! We want to make contributing to Flow Core as easy and transparent as possible, whether it's:
4+
5+
- Reporting a bug
6+
- Discussing the current state of the code
7+
- Submitting a fix
8+
- Proposing new features
9+
- Becoming a maintainer
10+
11+
## Development Process
12+
13+
We use GitHub to host code, to track issues and feature requests, as well as accept pull requests.
14+
15+
1. Fork the repo and create your branch from `main`
16+
2. If you've added code that should be tested, add tests
17+
3. If you've changed APIs, update the documentation
18+
4. Ensure the test suite passes
19+
5. Make sure your code follows our coding standards
20+
6. Issue that pull request!
21+
22+
## Coding Standards
23+
24+
- Use C++20 features appropriately
25+
- Follow the existing code style
26+
- Write meaningful commit messages
27+
- Document new code using Doxygen-style comments
28+
- Include unit tests for new features
29+
30+
## License
31+
32+
By contributing, you agree that your contributions will be licensed under the MIT License.
33+
34+
## Bug Reports
35+
36+
Please use the GitHub issue tracker and include:
37+
38+
- A quick summary and/or background
39+
- Steps to reproduce
40+
- Expected behavior
41+
- Actual behavior
42+
- Notes (possibly including why you think this might be happening)
43+
44+
## Pull Request Process
45+
46+
1. Update the README.md with details of changes if applicable
47+
2. Update the docs/ with relevant documentation
48+
3. The PR will be merged once you have the sign-off of at least one maintainer

README.md

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,66 @@
44
[![License: MIT](https://img.shields.io/github/license/InFlowStructure/flow-core)](https://github.com/InFlowStructure/flow-core/blob/main/LICENSE)
55
[![Language: C++20](https://img.shields.io/badge/Language-C%2B%2B20%20-blue)](https://en.cppreference.com/w/cpp/20)
66

7-
A cross-platform C++20 graph based code engine for building easily modified code flows on the fly. Intended as a Low-Code / No-Code solution.
7+
## Overview
8+
9+
Flow Core is a cross-platform C++20 graph-based code engine designed for building dynamically modifiable code flows. It serves as a foundation for Low-Code/No-Code solutions by providing a flexible and extensible graph computation system.
10+
11+
## Features
12+
13+
- Dynamic node-based computation graph
14+
- Runtime module loading system
15+
- Thread-safe execution environment
16+
- Type-safe data propagation
17+
- JSON serialization support
18+
- Cross-platform compatibility
19+
20+
## Requirements
21+
22+
- C++20 compliant compiler
23+
- CMake 3.15 or higher
24+
- Modern operating system (Windows, macOS, Linux)
25+
26+
## Dependencies
27+
28+
Flow Core relies on these open-source libraries:
29+
- [nlohmann_json](https://github.com/nlohmann/json) - Modern JSON handling
30+
- [thread-pool](https://github.com/bshoshany/thread-pool) - Efficient thread management
831

932
## Building
1033

11-
To build the project with CMake, simply run
34+
### Basic Build
1235
```bash
1336
cmake -B build
1437
cmake --build build --parallel
1538
```
1639

17-
To build tests, configure the build directory with the following
40+
### Build with Tests
1841
```bash
1942
cmake -B build -Dflow-core_BUILD_TESTS=ON
43+
cmake --build build --parallel
2044
```
2145

22-
## Installing
46+
## Installation
2347

24-
To install, configure the cmake build as follows:
48+
Configure and install:
2549
```bash
2650
cmake -B build -Dflow-core_INSTALL=ON
27-
```
28-
Then, simply build the project normally, then run one of
29-
```bash
51+
cmake --build build --parallel
3052
cmake --install build
3153
```
3254

33-
> [!TIP]
34-
> Try adding the `--config` flag with the appropriate build type.
55+
## Getting Started
3556

36-
## Dependencies
57+
Check out our [documentation](docs/getting-started.md) for:
58+
- Basic concepts and architecture
59+
- Creating your first flow
60+
- Building custom nodes
61+
- Best practices and examples
62+
63+
## License
64+
65+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
66+
67+
## Contributing
3768

38-
This project depends on the following open source projects:
39-
- [nlohmann_json](https://github.com/nlohmann/json)
40-
- [thread-pool](https://github.com/bshoshany/thread-pool)
69+
We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details on how to submit pull requests, report issues, and contribute to the project.

docs/getting-started.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Getting Started with Flow Core
2+
3+
## Basic Concepts
4+
5+
Flow Core is built around these key concepts:
6+
7+
- **Nodes**: Basic computation units
8+
- **Connections**: Data flow between nodes
9+
- **Graph**: Network of connected nodes
10+
- **Flow**: Complete execution sequence
11+
12+
## Creating Your First Flow
13+
14+
### 1. Basic Setup
15+
16+
```cpp
17+
#include <flow/core/Env.hpp>
18+
#include <flow/core/Graph.hpp>
19+
#include <flow/core/NodeFactory.hpp>
20+
21+
int main() {
22+
auto factory = std::make_shared<flow::NodeFactory>();
23+
auto env = flow::Env::Create(factory);
24+
auto graph = std::make_shared<flow::Graph>("MyGraph", env);
25+
26+
// ...
27+
28+
return 0;
29+
}
30+
```
31+
32+
### 2. Creating Nodes
33+
34+
```cpp
35+
// Create nodes via factory
36+
auto source_node = factory->CreateNode(flow::TypeName_v<NumberSourceNode>, UUID{}, "Source", env);
37+
auto processing_node = factory->CreateNode(flow::TypeName_v<MultiplyNode>, UUID{}, "Multiply", env);
38+
auto output_node = factory->CreateNode(flow::TypeName_v<PrintNode>, UUID{}, "Output", env);
39+
40+
// Add nodes to graph
41+
graph->AddNode(source_node);
42+
graph->AddNode(processing_node);
43+
graph->AddNode(output_node);
44+
```
45+
46+
### 3. Connecting Nodes
47+
48+
```cpp
49+
// Connect nodes to create a flow
50+
graph->ConnectNodes(source_node->ID(), "output", processing_node->ID(), "input");
51+
graph->ConnectNodes(processing_node->ID(), "output", output_node->ID(), "input");
52+
53+
// Start the flow
54+
graph->Run();
55+
```
56+
57+
## Building Custom Nodes
58+
59+
### 1. Define Node Class
60+
61+
```cpp
62+
// filepath: custom_node.hpp
63+
64+
class CustomNode : public flow::Node
65+
{
66+
public:
67+
CustomNode(const UUID& uuid, std::string_view class_name, std::string_view name, std::shared_ptr<Env> env)
68+
: Node(uuid, class_name, name, std::move(env))
69+
{
70+
// Add inputs and outputs
71+
}
72+
73+
virtual ~CustomNode() = default;
74+
75+
void Compute() override
76+
{
77+
// Your computation logic
78+
}
79+
};
80+
```
81+
82+
### 2. Register Node
83+
84+
```cpp
85+
factory->RegisterNodeClass<CustomNode>("Custom Category", "Custom Node");
86+
```
87+
88+
## Best Practices
89+
90+
1. **Type Safety**
91+
92+
- Always use proper type checking
93+
- Validate inputs before processing
94+
95+
2. **Performance**
96+
97+
- Minimize allocations in Compute() methods
98+
- Use thread-safe operations when needed
99+
100+
3. **Testing**
101+
- Write unit tests for custom nodes
102+
- Test edge cases and error conditions

include/flow/core/Connection.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ using SharedConnection = std::shared_ptr<class Connection>;
3131
class Connection
3232
{
3333
public:
34-
Connection() = delete;
34+
/**
35+
* @brief Deleted default constructor.
36+
* @note Connections must be constructed with valid node and port information.
37+
*/
38+
Connection() = delete;
39+
40+
/**
41+
* @brief Default destructor.
42+
*/
3543
~Connection() = default;
3644

3745
/**

include/flow/core/Graph.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,18 @@ class Graph
194194
return node && _nodes.contains(node->ID());
195195
}
196196

197+
/**
198+
* @brief Convert graph state to JSON.
199+
* @param j JSON object to store state in.
200+
* @param g Graph to serialize.
201+
*/
197202
friend void to_json(json& j, const Graph& g);
203+
204+
/**
205+
* @brief Restore graph state from JSON.
206+
* @param j JSON object containing serialized state.
207+
* @param g Graph to restore state into.
208+
*/
198209
friend void from_json(const json& j, Graph& g);
199210

200211
public:

include/flow/core/IndexableName.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,23 @@ class IndexableName
9595
constexpr IndexableName& operator=(const IndexableName&) = default;
9696
constexpr IndexableName& operator=(IndexableName&&) = default;
9797

98+
/**
99+
* @brief Three-way comparison operator.
100+
* @param other IndexableName to compare against.
101+
* @returns Strong ordering based on hash value.
102+
*/
98103
constexpr auto operator<=>(const IndexableName& other) const { return _value <=> other._value; };
99104

105+
/**
106+
* @brief Convert to size_t hash value.
107+
* @returns The hash value of this IndexableName.
108+
*/
100109
constexpr operator std::size_t() const { return _value; }
110+
111+
/**
112+
* @brief Convert to string view.
113+
* @returns String view of the original name.
114+
*/
101115
constexpr operator std::string_view() const { return _name; }
102116

103117
/// Get the hash value

include/flow/core/Port.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include "Core.hpp"
7+
#include "Event.hpp"
78
#include "IndexableName.hpp"
89
#include "NodeData.hpp"
910

@@ -114,6 +115,14 @@ class Port
114115
*/
115116
void SetCaption(std::string new_caption);
116117

118+
/**
119+
* @brief Event triggered when port data is modified.
120+
* @param key The port's unique key.
121+
* @param data The new data set on the port.
122+
* @param output Flag indicating if this change should propagate.
123+
*/
124+
Event<const IndexableName&, const SharedNodeData&, bool> OnSetData;
125+
117126
private:
118127
std::shared_ptr<INodeData> _data;
119128

include/flow/core/TypeConversion.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,13 @@ class TypeRegistry
7676
void RegisterUnidirectionalConversion(const ConversionFunc& converter = Convert<From, To>);
7777

7878
/**
79-
* @brief Register conversions in both directions between two types.
79+
* @brief Register conversions between two types with custom converters.
8080
*
81-
* @details Registers both T->U and U->T conversions. For same-type conversions,
82-
* automatically handles reference and const variations through
83-
* RegisterUnidirectionalConversion.
81+
* @tparam T First type to convert between.
82+
* @tparam U Second type to convert between.
8483
*
85-
* @tparam T First type in the conversion pair
86-
* @tparam U Second type in the conversion pair
87-
*
88-
* @param from_to_converter Conversion function from T to U
89-
* @param to_from_converter Conversion function from U to T
84+
* @param from_to_converter Custom conversion function from T to U.
85+
* @param to_from_converter Custom conversion function from U to T.
9086
*/
9187
template<typename T, typename U>
9288
void RegisterBidirectionalConversion(const ConversionFunc& from_to_converter = Convert<T, U>,

include/flow/core/UUID.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,17 @@ class UUID
3535
UUID& operator=(const UUID&) = default;
3636
UUID& operator=(UUID&&) = default;
3737

38+
/**
39+
* @brief Convert UUID to string representation.
40+
* @returns String representation of the UUID in standard format.
41+
*/
3842
operator std::string() const;
3943

44+
/**
45+
* @brief Three-way comparison operator.
46+
* @param other UUID to compare against.
47+
* @returns Strong ordering based on internal byte representation.
48+
*/
4049
constexpr auto operator<=>(const UUID& other) const = default;
4150

4251
/**

0 commit comments

Comments
 (0)