A containerized n8n workflow automation setup with PostgreSQL and Python ORM support.
# 1. Clone and enter the project
git clone <repo-url>
cd n8n-template
# 2. Create environment file
cp .env.example .env
# Edit .env with your values (all fields required)
# 3. Start containers
just up
# 4. Create database tables
just db-update
# 5. Import default workflows
just import-flows
# 6. Open n8n
open http://localhost:5678- Create an account when prompted
- Go to Settings > API and generate an API key
- Add the key to
.envasN8N_API_KEY(for MCP integration) - Create a Postgres credential:
- Host:
postgres - Database: value of
POSTGRES_DBfrom.env - User: value of
POSTGRES_USERfrom.env - Password: value of
POSTGRES_PASSWORDfrom.env
- Host:
- Update the default workflow's Postgres node to use your credential
- Activate the workflow
| Command | Description |
|---|---|
just up |
Start n8n and PostgreSQL containers |
just down |
Stop all containers |
just export-flows |
Export workflows to data/n8n/workflows/ |
just import-flows |
Import workflows from JSON files |
just db-update |
Create tables from SQLModel definitions |
just db-shell |
Open PostgreSQL console |
.
├── data/n8n/workflows/ # Workflow JSON files (version controlled)
├── db/dummy-db/ # Database models and migrations
├── scripts/ # Utility scripts
├── docker-compose.yaml # Container configuration
├── Justfile # Command definitions
└── .env # Environment variables (DO NOT COMMIT)
Workflows are stored as JSON in data/n8n/workflows/. Before committing:
just export-flows
git add data/n8n/workflows/
git commit -m "update workflows"- Edit
db/dummy-db/models.py:
from sqlmodel import Field, SQLModel
class MyTable(SQLModel, table=True):
id: int = Field(primary_key=True)
name: str- Create the table:
just db-updateSee CLAUDE.md for detailed technical documentation.
MIT