Skip to content

Commit 75dca9a

Browse files
Add CLAUDE.md with build instructions and architecture overview
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent fddb0a9 commit 75dca9a

1 file changed

Lines changed: 144 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
**mod_tile** is a high-performance tile serving system with two components:
8+
- **mod_tile**: Apache 2 HTTP module that serves map tiles
9+
- **renderd**: Daemon that renders tiles using Mapnik
10+
11+
## Build System
12+
13+
CMake is the primary build system (Autotools is the alternative). The project requires C99 and C++11 (C++17 for Mapnik 4+).
14+
15+
### Ubuntu dependencies
16+
17+
```sh
18+
sudo apt --no-install-recommends --yes install \
19+
apache2 apache2-dev cmake curl g++ gcc git \
20+
libcairo2-dev libcurl4-openssl-dev libglib2.0-dev \
21+
libiniparser-dev libmapnik-dev libmemcached-dev librados-dev
22+
```
23+
24+
### CMake Build (recommended)
25+
26+
```sh
27+
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)
28+
29+
cmake -B /tmp/mod_tile_build -S . \
30+
-DCMAKE_BUILD_TYPE=Release \
31+
-DCMAKE_INSTALL_LOCALSTATEDIR=/var \
32+
-DCMAKE_INSTALL_PREFIX=/usr \
33+
-DCMAKE_INSTALL_RUNSTATEDIR=/run \
34+
-DCMAKE_INSTALL_SYSCONFDIR=/etc \
35+
-DENABLE_TESTS=ON
36+
37+
cmake --build /tmp/mod_tile_build
38+
39+
# Run all tests
40+
cd /tmp/mod_tile_build && ctest
41+
42+
# Run a single test by name
43+
cd /tmp/mod_tile_build && ctest -R <test_name> --output-on-failure
44+
45+
# Install
46+
sudo cmake --install /tmp/mod_tile_build --strip
47+
```
48+
49+
### Autotools Build
50+
51+
```sh
52+
./autogen.sh
53+
./configure
54+
make
55+
sudo make install
56+
```
57+
58+
### Key CMake Options
59+
60+
| Option | Default | Description |
61+
|--------|---------|-------------|
62+
| `ENABLE_TESTS` | OFF | Build test suite (Catch2) |
63+
| `USE_CAIRO` | ON | Cairo composite backend |
64+
| `USE_CURL` | ON | HTTP proxy storage backend |
65+
| `USE_MEMCACHED` | ON | Memcached storage backend |
66+
| `USE_RADOS` | ON | Ceph RADOS storage backend |
67+
| `MALLOC_LIB` | libc | Memory allocator: libc/jemalloc/mimalloc/tcmalloc |
68+
69+
### Linting / Static Analysis
70+
71+
CI runs `flawfinder` for security scanning (`.github/workflows/flawfinder-analysis.yml`) and a lint workflow (`.github/workflows/lint.yml`).
72+
73+
## Architecture
74+
75+
### Communication Flow
76+
77+
```
78+
HTTP Client → mod_tile (Apache module)
79+
├── Storage backends (tile cache hit) → Response
80+
└── Unix socket → renderd daemon
81+
└── Request queue (5 priority levels)
82+
└── Thread pool → Mapnik → Metatile storage
83+
```
84+
85+
### Key Components
86+
87+
**`src/mod_tile.c`** — Apache module: request handling, cache expiry heuristics, delay pool rate limiting, statistics. Config structures: `tile_config_rec` (per-directory), `tile_server_conf` (server-wide).
88+
89+
**`src/renderd.c`** — Rendering daemon main loop; manages worker threads and Unix socket listener.
90+
91+
**`src/gen_tile.cpp`** — Mapnik tile generation. Called by renderd worker threads.
92+
93+
**`src/request_queue.c`** — Priority queue with hash-indexed deduplication. 5 levels: Normal, Priority, Low, Bulk, Dirty.
94+
95+
**`src/renderd_config.c`** — Parses `renderd.conf` (INI format) into `renderd_config` / `xmlconfigitem` structs.
96+
97+
**Storage backends** (pluggable via `includes/store.h` function-pointer interface):
98+
- `store_file.c` — filesystem (default), stores 8×8 metatiles
99+
- `store_memcached.c` — Memcached
100+
- `store_rados.c` — Ceph RADOS
101+
- `store_ro_http_proxy.c` — HTTP proxy (read-only)
102+
- `store_ro_composite.c` — composite read-only (requires Cairo)
103+
- `store_null.c` — no-op
104+
105+
### Protocol
106+
107+
mod_tile and renderd communicate over a Unix socket (default: `/run/renderd/renderd.sock`, TCP fallback: `localhost:7654`) using the protocol defined in `includes/protocol.h`. Protocol version is v3. Commands: `cmdRender`, `cmdDirty`, `cmdRenderPrio`, `cmdRenderLow`, `cmdRenderBulk`, `cmdDone`, `cmdNotDone`.
108+
109+
### Metatile Format
110+
111+
Tiles are stored in 8×8 metatile bundles (`METATILE = 8`) in a hashed directory structure. File format: `"META"` magic header + index of per-tile offsets/sizes. `includes/metatile.h` defines the layout; `src/metatile.cpp` is the C++ wrapper.
112+
113+
### Important Constants (`includes/render_config.h`, `includes/mod_tile.h`)
114+
115+
- `MAX_ZOOM = 20`
116+
- `HASHIDX_SIZE = 2213` (request deduplication hash)
117+
- Default tile directory: `/var/cache/renderd/tiles`
118+
- `MAX_LOAD_OLD = 16`, `MAX_LOAD_MISSING = 50` — re-render thresholds
119+
120+
## Tests
121+
122+
Tests use **Catch2** (v2.13.9) and live in `tests/`. The main suites:
123+
124+
- `gen_tile_test.cpp` — Mapnik rendering pipeline (largest suite)
125+
- `renderd_config_test.cpp` — configuration parsing
126+
- `renderd_test.cpp` — daemon core
127+
- `render_expired_test.cpp`, `render_list_test.cpp`, `render_old_test.cpp` — utility programs
128+
- `render_speedtest_test.cpp` — performance tool
129+
130+
Test infrastructure uses `tests/httpd.conf.in` and `tests/renderd.conf.in` templates to spin up live Apache + renderd for integration tests. `tests/tiles.sha256sum` holds expected checksums for tile output validation.
131+
132+
## Repository Layout
133+
134+
```
135+
includes/ — public headers (protocol, store interface, config structs)
136+
src/ — C/C++ source for mod_tile, renderd, storage backends, utilities
137+
tests/ — Catch2 test suites + fixtures
138+
cmake/ — custom Find*.cmake modules
139+
docs/build/ — per-distro build instructions
140+
docs/man/ — man pages
141+
etc/ — example Apache and renderd config files
142+
utils/ — example map data
143+
.github/ — CI workflows (build-and-test, lint, flawfinder, docker)
144+
```

0 commit comments

Comments
 (0)