Introduction

Configuration management is one of the most overlooked yet most critical parts of application architecture. Poor config design leads to security risks, deployment friction, and production instability.

This article explains where to store configuration files, how to structure them, and what to use in different scenarios—especially for modern Python and AI-based systems.

First Principle: Separate Code from Configuration

Never hardcode:

DATABASE_URL = "postgres://admin:password@localhost:5432/app"
API_KEY = "123456"

Configuration should be:

Types of Configurations

Before deciding where to store config, classify it:

TypeExampleShould Be Version Controlled?Should Be Secret?
Application ConfigPort, debug modeYesNo
Infrastructure ConfigDockerYesNo
SecretsAPI keys, DB passwordNoYes
Runtime EnvironmentProduction vs DevNoNo

Each type should be stored differently.

Where to Store Configuration Files

A. Inside the Project (Version Controlled)

Best for:

Example structure:

project/
│
├── config/
│   ├── config.toml
│   ├── config.dev.toml
│   └── config.prod.toml
│
├── app/
│   └── main.py

Recommended format for application config:

TOML is widely used in modern Python ecosystems such as:

Environment Variables (.env File)

Best for:

Example. env:

DATABASE_URL=postgres://user:pass@localhost:5432/app
API_KEY=abc123
ENVIRONMENT=production

Used heavily with:

Important rule:
.env files should NOT be committed to Git.

Add to .gitignore.

Infrastructure Configuration

Infrastructure config should live:

infra/
│
├── docker-compose.yaml
├── k8s/
│   ├── deployment.yaml
│   └── service.yaml

Used in:

These should always be version controlled.

Cloud Secret Managers (Production)

For enterprise systems, secrets should NOT live in:

Use:

Secrets should be injected at runtime.

Recommended Structure for Modern Python

For an AI or MCP server:

mcp-server/
│
├── app/
│   ├── main.py
│   ├── settings.py
│
├── config/
│   ├── config.toml
│   ├── config.dev.toml
│   └── config.prod.toml
│
├── infra/
│   ├── docker-compose.yaml
│   └── k8s/
│
├── .env
├── .gitignore

Configuration Strategy by Environment

Development

Staging

Production

What NOT to Do

Example: Clean Enterprise Setup

config.toml

[app]
name = "finance-mcp"
environment = "production"

[server]
port = 8000

[llm]
model = "llama3"
temperature = 0.2

.env

DATABASE_URL=postgres://...
OPENAI_API_KEY=...

settings.py

This separation:

When to Store Config Outside the Project

In microservices or enterprise deployments:

Used when:

Quick Decision Guide

SituationStore Where
App settingsTOML/YAML inside project
SecretsEnvironment variables / secret manager
Docker configdocker-compose.yaml
KubernetesYAML inside infra folder
CI/CD variablesPipeline environment variables
Feature flagsConfig file or remote config service

Final Architecture Recommendation

Use a layered approach

This gives:

Final Thought

Configuration storage is not about file format.
It is about:

Good configuration design prevents 80% of production issues before they happen.