config-and-di

Rules for configuring an ArchiPy application and wiring dependency injection, a way to provide services and settings to code instead of constructing them everywhere.

In plain words
What is it for?
Use them to define application settings, configure FastAPI and its server, set environment-variable overrides, and make configuration available throughout the app.
Why use it?
They centralize environment settings, server options, and shared configuration while keeping secrets out of source control.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/syntaxarc/archipy-plugin/config-and-di
Clone the repo
git clone --depth 1 https://github.com/SyntaxArc/archipy-plugin
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 651 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00651
Opus 5 $0.00000 $0.00326
Sonnet 5 $0.00000 $0.00130
Haiku 4.5 $0.00000 $0.00065

Measured 2d ago against content hash 91fa45cfc6b7, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

config-and-di scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/config-and-di.mdc · 75 lines

How it starts

The opening of the file, as written. The whole thing — 75 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Config and Dependency Injection

BaseConfig

import logging

from archipy.configs.base_config import BaseConfig
from archipy.configs.environment_type import EnvironmentType

logger = logging.getLogger(__name__)


class AppConfig(BaseConfig):
    """Application configuration. Inherits ArchiPy sections (REDIS, FASTAPI, GRPC, ...)."""

    def customize(self) -> None:
        """Apply service-specific defaults after sources load."""
        super().customize()
        self.FASTAPI.PROJECT_NAME = "my-service"
        self.FASTAPI.RELOAD = self.ENVIRONMENT == EnvironmentType.LOCAL


config = AppConfig()
BaseConfig.set_global(config)
logger.info("Config loaded for environment: %s", config.ENVIRONMENT)
  • Call BaseConfig.set_global(config) once at bootstrap (typically importing app_config from the DI container).
  • Read elsewhere via BaseConfig.global_config().
  • Document required env vars in .env.example; never commit secrets.
  • Env overrides use nested delimiter: FASTAPI__PROJECT_NAME, FASTAPI__SERVE_PORT, …

FastAPIConfig (config.FASTAPI)

Drives both AppUtils.create_fastapi_app and uvicorn in manage.py:

Area Fields
Serve SERVE_HOST, SERVE_PORT, RELOAD, WORKERS_COUNT
Proxy PROXY_HEADERS, FORWARDED_ALLOW_IPS
App / docs PROJECT_NAME, OPENAPI_URL, DOCS_URL, RE_DOC_URL, …
Middleware flags GZIP_MIDDLEWARE_IS_ENABLED, TRUSTED_HOST_MIDDLEWARE_*, HTTPS_REDIRECT_MIDDLEWARE_IS_ENABLED, CORS fields

Set defaults in customize(); never hardcode host/port/reload for production paths.

gRPC bind (parallel): config.GRPC.SERVE_HOST, config.GRPC.SERVE_PORT.

Dependency Injection

uv add "archipy[dependency-injection]"
  • Wire in configs/containers.py as providers: ports → adapters → repositories → logics → services.
  • Depend on ports in business code; override providers in tests with mocks.
  • Import app_config inside the container module so set_global runs before wiring.

Read the full file on GitHub · 75 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 75 lines · 651 tokens per session scan A 91fa45cfc6b7

Subscribe to this mod's changes

config-and-di is a cursor rule published in the GitHub repository SyntaxArc/archipy-plugin (2 stars, last pushed 9d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 651 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.