Yojaka AI: Engineering Conventions & Guidelines¶
This document outlines the core architectural principles, coding standards, and quality conventions for Yojaka AI. These guidelines keep our codebase modular, reliable, and straightforward for contributors.
๐๏ธ 1. Architectural Principles¶
-
Separation of Concerns:
- Domain Logic: RAG retrieval (
resume_rag.py), hybrid matching (job_matcher.py), and LangGraph state machines (agent/) must remain decoupled from presentation layers (Streamlit UI) and transport protocols (FastAPI / MCP). - Service Layer: High-level orchestrations spanning multiple domain boundaries belong in
src/agentic_profile_matching/services/(e.g.,IngestionService).
- Domain Logic: RAG retrieval (
-
Protocol-Driven Interfaces & Dependency Injection:
- Orchestrators depend on abstractions (
typing.Protocolorabc.ABC), not hardcoded implementations (e.g.,BaseVectorStoreinstead of directChromaDBdependencies). - Components receive clients and model references via constructor arguments or runtime config rather than instantiating them internally.
- Orchestrators depend on abstractions (
๐ก๏ธ 2. State Management & Type Safety¶
-
Strict Type Annotations:
- All functions, methods, class attributes, and module constants must use explicit Python 3.10+ type hints.
- Avoid
Anywhere possible. Use explicit generics (list[str],dict[str, float]) andOptional/Union. - Numeric match scores must be typed as
floatacross all schemas to avoid truncation.
-
Pydantic V2 for Validation & Structured LLM Extraction:
- Use Pydantic V2
BaseModelfor request/response payloads, config validation, and structured LLM tool outputs. - Parse LLM structured responses using schema-enforced methods with deterministic fallbacks.
- Use Pydantic V2
-
LangGraph State Immutability:
- Graph state schemas in
agent/state.pyuseTypedDictor Pydantic models. - Pure updates: Never mutate state dictionaries in place. Return fresh partial state dictionaries (
{**existing, "key": value}) from graph nodes so checkpoints remain deterministic.
- Graph state schemas in
๐ 3. Security & Resilience¶
-
Zero Secret Leakage in Serialized State:
- API keys, credentials, and tokens must never be written to
AgentStateor stored in serializable checkpoints. - Inject credentials dynamically via runtime context (
RunnableConfig) or environment variables. - Structured loggers sanitize sensitive values and authorization tokens.
- API keys, credentials, and tokens must never be written to
-
Input & UI Sanitization (OWASP):
- Candidate-derived content (names, experiences, education) rendered in HTML templates (such as candidate cards) must be escaped with
html.escape()to prevent cross-site scripting (XSS).
- Candidate-derived content (names, experiences, education) rendered in HTML templates (such as candidate cards) must be escaped with
-
Graceful Degradation & Error Boundaries:
- Catch specific exceptions (
FileNotFoundError,KeyError,httpx.HTTPError) rather than bareexcept Exception: pass. - Non-critical node failures (e.g., secondary tool or enrichment calls) should log structured warnings and populate state flags without crashing the primary evaluation pipeline.
- Catch specific exceptions (
๐ 4. Observability & Logging¶
-
Structured JSON Logs:
- Use
get_logger(__name__)fromagentic_profile_matching.observability. - Bare
print()calls in core/service modules are prohibited. - All log records emit structured JSON containing
timestamp,level,logger,message, and trace payloads.
- Use
-
Latency Instrumentation:
- Workflow nodes in
agent/workflow.pyand subgraphs are instrumented with@trace_node("node_name")to profile execution latency.
- Workflow nodes in
๐งช 5. Testing & Code Quality Gates¶
Before opening a pull request, verify all local quality gates:
# 1. Lint and format checks
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/
# 2. Test suite execution
uv run pytest tests/ -v
- Mock External Services: Unit tests must not make live billable LLM or external network calls; use pytest fixtures and mock responses.
- Deterministic Math: Scoring algorithms (e.g., hybrid BM25 + vector weighting, calibrated margin routing) must be covered with explicit assertions.
๐ 6. Commit & Versioning Standards¶
-
Conventional Commits:
- Format:
<type>(<scope>): <summary> - Types:
feat,fix,refactor,docs,test,chore. - Example:
feat(routing): calibrated margin routing with subgraphs (v0.18.0)
- Format:
-
Changelog & Semantic Versioning:
- Increment
versioninpyproject.tomland record changes inCHANGELOG.mdunder the corresponding version section ([MAJOR.MINOR.PATCH] - YYYY-MM-DD).
- Increment
๐จ 7. Architecture & Diagrams Maintenance Protocol¶
To ensure documentation remains accurate and publication-grade as the system evolves:
-
Diagrams as Code (
scripts/generate_diagrams.py):- Architecture diagrams are defined programmatically using Mingrammer
diagrams. Manual graphic edits or ad-hoc image uploads are prohibited. - When introducing new architectural components, subgraphs, storage engines, or routing mechanisms, update the corresponding generator function in
scripts/generate_diagrams.py.
- Architecture diagrams are defined programmatically using Mingrammer
-
Visual Standards:
- Use clean planar orientations (
direction="LR"for pipelines,"TB"for hierarchies). - Use official high-resolution brand icons from
docs/assets/icons/. - Use the centralized
cluster_attr()helper with generous padding (โฅ28pt) to eliminate node label collision.
- Use clean planar orientations (
-
Regeneration & Verification: