SanderMertens/flecs logo

SanderMertens/flecs

Free

A fast entity component system (ECS) for C & C++

FreeFree tier
Type
Open Source

About SanderMertens/flecs

Flecs is a fast and lightweight Entity Component System (ECS) for C & C++ designed for building games and simulations with millions of entities. It provides a portable, zero-dependency C99 API and a modern type-safe C++17 API that avoids STL containers. Notable features include full support for Entity Relationships (first among open-source ECS), fast native hierarchies and prefabs, cache-friendly archetype/SoA storage, automatic component registration across shared libraries, and a lockless scheduler for multi-core performance. Flecs integrates a reflection framework with JSON serialization, runtime component support, unit annotations for components, a powerful query language with joins and inheritance, and a statistics addon for profiling. It also offers a web-based UI for monitoring and controlling applications. The codebase builds in under 5 seconds and runs in the browser via Emscripten. Flecs is verified on all major compilers and platforms, with over 13,000 tests in CI.

Key Features

Fast and portable zero-dependency C99 API
Modern type-safe C++17 API without STL containers
First open source ECS with full support for Entity Relationships
Fast native support for hierarchies and prefabs
Cache-friendly archetype/SoA storage for millions of entities per frame
Automatic component registration across shared libraries/DLLs
Write free functions with queries or run code automatically in systems
Fast lockless scheduler for multi-core execution
Integrated reflection framework with JSON serializer and runtime components
Powerful query language with joins and inheritance

Pros & Cons

Pros
  • Zero dependency, portable across platforms and compilers
  • Very fast build times (less than 5 seconds)
  • Runs in browser via Emscripten without modifications
  • Extensive testing with over 13,000 CI tests
  • Strong support for ECS relationships and hierarchies
  • Reflection and serialization included out of the box
  • Multi-core lockless scheduler for performance

Best For

Game development with millions of entitiesReal-time simulations (e.g., physics, AI)Entity-based applications requiring high performanceData-oriented design projects

FAQ

What is an Entity Component System?
ECS is a way of organizing code and data that lets you build games that are larger, more complex and easier to extend. It has entities (unique IDs), components (datatypes added to entities), and systems (functions that run for all entities matching a component query).
How do I use Flecs in C or C++?
Flecs provides both a C99 API and a modern C++17 API. In C you define components with ECS_COMPONENT, write system functions that iterate over components, and create entities with ecs_insert. The C++ API uses lambda-based systems with automatic component registration, e.g., ecs.system<Position, const Velocity>().each([](...){...}).