Skip to content
GitHubDiscord

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.


Lexigram supports two primary project structures. Choose the one that fits your team’s size and complexity.

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/ # Controllers

Best for large platforms or micro-services.

my-platform/
β”œβ”€β”€ pyproject.toml
└── src/
└── my_platform/
β”œβ”€β”€ app.py
└── modules/
β”œβ”€β”€ auth/ # Self-contained module
β”œβ”€β”€ billing/
└── core/

We recommend using uv for high-performance dependency management and environment isolation.

Terminal window
uv sync
Terminal window
uv run lexigram dev

[!NOTE] The dev and run commands automatically load configuration based on the LEXIGRAM_PROFILE environment variable. See YAML Configuration for more on profile handling.


A production-ready Dockerfile for Lexigram should focus on size and security.

# Use a slim Python base
FROM python:3.12-slim-bookworm AS builder
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Set working directory
WORKDIR /app
# Install dependencies
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev
# Final stage
FROM python:3.12-slim-bookworm
WORKDIR /app
# Copy environment and source
COPY --from=builder /app/.venv /app/.venv
COPY . .
# Set environment variables
ENV PATH="/app/.venv/bin:$PATH"
ENV LEXIGRAM_PROFILE=production
# Run with Gunicorn/Uvicorn
CMD ["lexigram", "run", "--host", "0.0.0.0", "--port", "8000"]

Using uv in a multi-stage Docker build significantly reduces image size and build times by leveraging a cached virtual environment.


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