Deployment & Infrastructure
Lexigram applications are designed for modern cloud environments. This guide covers the best practices for structuring, packaging, and deploying your application.
For the command reference used throughout this guide, see the Lexigram CLI Overview.
1. Project Layouts
Section titled β1. Project LayoutsβLexigram supports two primary project structures. Choose the one that fits your teamβs size and complexity.
Standard Layout (Single Package)
Section titled βStandard Layout (Single Package)βBest for small to medium applications.
my-app/βββ pyproject.tomlβββ lexigram.yamlβββ src/ βββ my_app/ βββ app.py # Composition Root βββ domain/ # Entities & Services βββ infrastructure/ # Repositories & Adapters βββ web/ # ControllersModular Layout (Multi-Package)
Section titled βModular Layout (Multi-Package)βBest for large platforms or micro-services.
my-platform/βββ pyproject.tomlβββ src/ βββ my_platform/ βββ app.py βββ modules/ βββ auth/ # Self-contained module βββ billing/ βββ core/2. Environment Management (UV)
Section titled β2. Environment Management (UV)βWe recommend using uv for high-performance dependency management and environment isolation.
Installation
Section titled βInstallationβuv syncRunning the App
Section titled βRunning the Appβuv run lexigram dev[!NOTE] The
devandruncommands automatically load configuration based on theLEXIGRAM_PROFILEenvironment variable. See YAML Configuration for more on profile handling.
3. Production Dockerization
Section titled β3. Production DockerizationβA production-ready Dockerfile for Lexigram should focus on size and security.
# Use a slim Python baseFROM python:3.12-slim-bookworm AS builder
# Install uvCOPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Set working directoryWORKDIR /app
# Install dependenciesCOPY pyproject.toml uv.lock ./RUN uv sync --frozen --no-dev
# Final stageFROM python:3.12-slim-bookwormWORKDIR /app
# Copy environment and sourceCOPY --from=builder /app/.venv /app/.venvCOPY . .
# Set environment variablesENV PATH="/app/.venv/bin:$PATH"ENV LEXIGRAM_PROFILE=production
# Run with Gunicorn/UvicornCMD ["lexigram", "run", "--host", "0.0.0.0", "--port", "8000"]Build Optimization
Section titled βBuild OptimizationβUsing uv in a multi-stage Docker build significantly reduces image size and build times by leveraging a cached virtual environment.
4. Docker Compose (Local Dev)
Section titled β4. Docker Compose (Local Dev)βservices: api: build: . ports: - "8000:8000" environment: - LEXIGRAM_PROFILE=dev volumes: - .:/app depends_on: - db
db: image: postgres:16 environment: POSTGRES_DB: app_db POSTGRES_PASSWORD: secret_pass