@@ -4,27 +4,34 @@ Purpose
44AWS Lambda event gateway that receives messages via API Gateway and dispatches them to Kafka, EventBridge, and PostgreSQL.
55
66Structure
7- - Entry point: ` src/event_gate_lambda.py `
8- - Handlers: ` src/handlers/ ` (HandlerApi, HandlerToken, HandlerTopic, HandlerHealth)
7+ - Main lambda (event ingestion): ` src/event_gate_lambda.py `
8+ - Stats lambda (read-only queries): ` src/event_stats_lambda.py `
9+ - Shared config loading: ` src/utils/config_loader.py `
10+ - Handlers: ` src/handlers/ ` (HandlerApi, HandlerToken, HandlerTopic, HandlerHealth, HandlerStats)
911- Writers: ` src/writers/ ` (inherit from ` Writer ` base class)
12+ - Readers: ` src/readers/ ` (read-only database access for stats)
1013- Config: ` conf/config.json ` , ` conf/access.json ` , ` conf/topic_schemas/*.json `
1114- Production Terraform scripts are not part of this repository; ` terraform_examples/ ` for reference configurations only
1215
1316Python style
1417- Python 3.13
1518- Type hints for public functions and classes
19+ - Use built-in generics for type hints
1620- Use ` logging.getLogger(__name__) ` , not print
1721- Lazy % formatting in logging: ` logger.info("msg %s", var) `
1822- F-strings in exceptions: ` raise ValueError(f"Error {var}") `
1923- All imports at top of file (never inside functions)
2024- Apache 2.0 license header in every .py file (including ` __init__.py ` )
2125- Docstrings must start with a short summary line
26+ - No blank lines between docstring sections (summary, Args, Returns, Raises)
27+ - Use single backticks in docstrings (` value ` ), never double backticks (`` `` value`` `` )
28+ - Do not use ` # ----------- ` separator comments to divide sections
2229- End all log messages with a period: ` logger.info("Message.") `
2330
2431Patterns
2532- ` __init__ ` methods must not raise exceptions; defer validation and connection to first use (lazy init)
2633- Writers: inherit from ` Writer(ABC) ` , implement ` write(topic, message) -> (bool, str|None) ` and ` check_health() -> (bool, str) `
27- - Route dispatch via ` ROUTE_MAP ` dict mapping routes to handler functions in ` event_gate_lambda.py `
34+ - Route dispatch via ` ROUTE_MAP ` dict mapping routes to handler functions in ` event_gate_lambda.py ` and ` event_stats_lambda.py `
2835- Separate business logic from environment access (env vars, file I/O, network calls)
2936- No duplicate validation; centralize parsing in one layer where practical
3037- Preserve existing formatting and conventions
@@ -33,14 +40,13 @@ Patterns
3340
3441Testing
3542- Mirror src structure: ` src/handlers/ ` -> ` tests/unit/handlers/ `
43+ - Test modules (` test_*.py ` ) must not have module-level docstrings
3644- Unit tests: mock external services via ` conftest.py ` (Kafka, EventBridge, PostgreSQL, S3)
3745- Integration tests: call ` lambda_handler ` directly with real containers (testcontainers-python for Kafka, PostgreSQL, LocalStack)
3846- No real API/DB calls in unit tests
3947- Use ` mocker.patch("module.dependency") ` or ` mocker.patch.object(Class, "method") `
4048- Assert pattern: ` assert expected == actual `
4149
4250Quality gates (run after changes, fix only if below threshold)
43- - black .
44- - mypy .
45- - pylint $(git ls-files '* .py') >= 9.5
46- - pytest tests/ >= 80% coverage
51+ - Run all quality gates at once: ` make qa `
52+ - Once a quality gate passes, do not re-run it in different scenarios
0 commit comments