A modern, enterprise-grade backend framework written in pure C99.
CM gives you the elegance of Express.js, the performance of raw C, and the safety of a built-in garbage collector โ all in one lightweight library.
| Module | Description |
|---|---|
| ๐ง Memory / GC | Automatic garbage collection with ref-counting, mark-and-sweep, and live stats |
| ๐ Thread Safety | OS-agnostic CMMutex and CMThread โ wraps Win32 & POSIX transparently |
| ๐ HTTP Server | Express.js-style router with cm_app_get() / cm_app_post() |
| ๐ File I/O | GC-tracked file reading and writing via cm_file_read() / cm_file_write() |
| ๐บ๏ธ Hash Maps | High-performance cm_map_t with automatic resizing and load-factor control |
| ๐ค Dynamic Strings | Safe unicode-aware cm_string_t with full formatting and slicing API |
| ๐ฆ JSON | Full JSON parse + stringify โ no third-party dependencies |
| ๐พ Map Persistence | Serialize / deserialize maps to JSON files in one line |
| ๐ Unicode / UTF-8 | Native emoji and international character support on all platforms |
CM/
โโโ include/cm/ # Public headers
โ โโโ core.h # Version, base types, macros
โ โโโ memory.h # GC allocator API
โ โโโ string.h # Dynamic string API
โ โโโ array.h # Dynamic array API
โ โโโ map.h # Hash map API + JSON persistence
โ โโโ json.h # JSON parse & stringify
โ โโโ http.h # HTTP server & router
โ โโโ file.h # File I/O API
โ โโโ thread.h # OS-agnostic threading API
โ โโโ error.h # Error handling & signal detection
โโโ src/ # Module implementations
โโโ tests/ # Unit test suite (CTest)
โโโ public_html/ # Static frontend (HTML/CSS/JS)
โ โโโ index.html # Login + Calculator SPA
โ โโโ style.css # Glassmorphism dark UI
โ โโโ script.js # Calculator frontend logic
โโโ main.c # Example server entry point
โโโ CMakeLists.txt # Build system
Requirements: CMake 3.10+, GCC / MinGW-w64
cmake -B build
cmake --build buildcd build
./cm_server.exe # Windows
./cm_server # LinuxThen open http://localhost:8080 in your browser.
Login with admin / 1234 to access the live Calculator.
cd build
ctest --output-on-failurecm_gc_init(); // Initialize GC (call once on startup)
void* p = cm_alloc(size, "T"); // Allocate GC-tracked memory
cm_free(p); // Decrement ref count / free
cm_retain(p); // Increment ref count
cm_gc_collect(); // Manually trigger sweep
cm_gc_stats(); // Print memory statistics to console
cm_gc_shutdown(); // Final sweep + shutdowncm_string_t* s = cm_string_new("Hello!");
cm_string_t* f = cm_string_format("v%s", "5.0.0");
cm_string_length(s); // UTF-8 aware length
cm_string_free(s);cm_map_t* m = cm_map_new();
cm_map_set(m, "key", "value", 6);
char* v = (char*)cm_map_get(m, "key");
cm_map_save_to_json(m, "config.json"); // Persist to disk
cm_map_t* m2 = cm_map_load_from_json("config.json"); // Load from disk
cm_map_free(m);void home(CMHttpRequest* req, CMHttpResponse* res) {
cm_res_send(res, "Hello from CM!");
}
void api_data(CMHttpRequest* req, CMHttpResponse* res) {
struct CMJsonNode* node = cm_json_parse("{\"ok\":true}");
cm_res_json(res, node);
CMJsonNode_delete(node);
}
int main() {
cm_gc_init();
cm_app_get("/", home);
cm_app_get("/style.css", serve_css);
cm_app_post("/api/data", api_data);
cm_app_listen(8080);
cm_gc_shutdown();
}cm_file_write("out.txt", "Hello, CM!");
cm_string_t* content = cm_file_read("out.txt");
printf("%s\n", content->data);
cm_string_free(content);void* my_worker(void* arg) {
printf("Running in thread!\n");
return NULL;
}
CMThread t = cm_thread_create(my_worker, NULL);
cm_thread_join(t);
CMMutex lock = cm_mutex_init();
cm_mutex_lock(lock);
// ... critical section ...
cm_mutex_unlock(lock);struct CMJsonNode* root = cm_json_parse("{\"name\":\"CM\",\"version\":5}");
cm_string_t* str = cm_json_stringify(root);
printf("%s\n", str->data);
cm_string_free(str);
CMJsonNode_delete(root);CM ships with a glassmorphism dark-mode web app served entirely from C:
- ๐ Login Screen โ JWT-free session with backend auth via
POST /api/login - ๐งฎ Calculator UI โ Fully functional, logs every calculation to the server
- ๐ Live GC Stats โ Memory stats printed to console on every calculation
Request โโ TCP Socket โโ HTTP Parser โโ Router
โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโ
โผ โผ โผ
Static File JSON API Log + GC Stats
(File I/O) (Map/JSON) (cm_gc_stats)
The CM GC ensures zero unbounded leaks under normal usage:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
GARBAGE COLLECTOR STATISTICS
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Total objects โ 39
Total memory โ 1524 bytes
Peak memory โ 13058 bytes
Allocations โ 214
Frees โ 175
Collections โ 5
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- HTTPS / TLS support via
cm_tls.h - WebSocket upgrade protocol
- Route middleware / pipeline hooks
- JWT authentication helper
- Database adapter interface
MIT License โ Copyright ยฉ 2026 Adham Hossam