🌿

NutriTrack β€” Northflank IaC

Infrastructure as Code Β· SaaS B2B para nutricionistas Β· Entorno de producciΓ³n

βœ” IaC Completo Northflank v2 europe-west
6
Servicios desplegados
2
Instancias API (HA)
2
Jobs configurados
4
Secretos gestionados
10 GB
Storage PostgreSQL
πŸš€ Servicios desplegados
πŸ”—
nutritrack-api
DeploymentService Β· Node.js 20 + Express
2 instancias nf-compute-20 :4000 api.nutritrack.es HTTPS GET /health
⚑
nutritrack-frontend
DeploymentService Β· Next.js 14 App Router
1 instancia nf-compute-20 :3000 app.nutritrack.es Nixpacks
🐘
main-db
Addon Β· PostgreSQL 16
nf-compute-20 10 GB SSD backup 03:00 UTC nutritrack_db
⚑
session-cache
Addon Β· Redis 7
nf-compute-10 2 GB RAM 1 GB SSD AOF
πŸ“Š
daily-report-job
CronJob Β· Informes PDF
0 6 * * * node scripts/reports.js nf-compute-10 timeout 30min
πŸ”§
db-migrate-job
ManualJob Β· Prisma migrations
manual trigger npx prisma migrate deploy nf-compute-10
πŸ”„ Pipeline CI/CD
πŸ™
GitHub Push
main / PR branch
β†’
πŸ”¨
Build
Nixpacks + cache
β†’
πŸ§ͺ
Test Runner
Jest + Playwright
β†’
πŸ‘οΈ
Preview Env
pr-123.nutritrack.es
β†’
βœ…
ProducciΓ³n
merge to main
πŸ“„ northflank.json β€” Infrastructure as Code
northflank.json
preview-template.json
Copiar
{
  

"apiVersion"

: "v1",

"spec"

: {

"kind"

: "Workflow",

"spec"

: {

"type"

: "sequential",

"steps"

: [ // ── 1. BUILD API ───────────────────────────────────────── {

"kind"

: "BuildService",

"spec"

: {

"name"

: "api-build",

"billing"

: {

"deploymentPlan"

: "nf-compute-20" },

"vcsData"

: {

"projectUrl"

: "https://github.com/nutritrack-org/api",

"projectType"

: "github",

"projectBranch"

: "main" },

"buildpack"

: {

"builder"

: "NIXPACKS" } } }, // ── 2. DEPLOY API (2 instancias, HA) ───────────────────── {

"kind"

: "DeploymentService",

"spec"

: {

"name"

: "nutritrack-api",

"billing"

: {

"deploymentPlan"

: "nf-compute-20" },

"deployment"

: {

"instances"

: 2,

"internal"

: {

"id"

: "api-build",

"branch"

: "main",

"buildSHA"

: "latest" } },

"ports"

: [{

"name"

: "http",

"internalPort"

: 4000,

"public"

: true,

"protocol"

: "HTTP",

"domains"

: ["api.nutritrack.es"] }],

"healthChecks"

: [{

"protocol"

: "HTTP",

"path"

: "/health",

"port"

: 4000,

"initialDelaySeconds"

: 15,

"periodSeconds"

: 30 }],

"runtimeEnvironment"

: {

"NODE_ENV"

: "production",

"DATABASE_URL"

: "${main-db.HOST}",

"REDIS_URL"

: "${session-cache.HOST}" } } }, // ── 3. POSTGRESQL 16 + backups ─────────────────────────── {

"kind"

: "Addon",

"spec"

: {

"name"

: "main-db",

"type"

: "postgresql",

"version"

: "16",

"billing"

: {

"deploymentPlan"

: "nf-compute-20",

"storageClass"

: "ssd",

"storage"

: 10240 },

"backups"

: {

"enabled"

: true,

"schedule"

: "0 3 * * *" } } }, // ── 4. REDIS 7 para sesiones ───────────────────────────── {

"kind"

: "Addon",

"spec"

: {

"name"

: "session-cache",

"type"

: "redis",

"version"

: "7",

"billing"

: {

"deploymentPlan"

: "nf-compute-10",

"storageClass"

: "ssd",

"storage"

: 1024 } } }, // ── 5. CRON JOB β€” informes diarios ────────────────────── {

"kind"

: "CronJob",

"spec"

: {

"name"

: "daily-report-job",

"billing"

: {

"deploymentPlan"

: "nf-compute-10" },

"runOnSourceChange"

: "never",

"schedule"

: "0 6 * * *",

"activeDeadlineSeconds"

: 1800,

"backoffLimit"

: 2,

"vcsData"

: {

"projectUrl"

: "https://github.com/nutritrack-org/api",

"projectBranch"

: "main" },

"runCommand"

: "node scripts/reports.js" } }, // ── 6. MANUAL JOB β€” migraciones Prisma ────────────────── {

"kind"

: "ManualJob",

"spec"

: {

"name"

: "db-migrate-job",

"billing"

: {

"deploymentPlan"

: "nf-compute-10" },

"runCommand"

: "npx prisma migrate deploy",

"runtimeEnvironment"

: {

"DATABASE_URL"

: "${main-db.HOST}" } } } ] } } }
πŸ” GestiΓ³n de secretos β€” grupo nutritrack-secrets
Variable Valor (enmascarado) Servicios que la usan Grupo Estado
OPENAI_API_KEY sk-β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’4f9a nutritrack-api, daily-report-job ai-services βœ” activo
STRIPE_SECRET_KEY sk_live_β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’7b2c nutritrack-api billing βœ” activo
JWT_SECRET β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’ nutritrack-api, nutritrack-frontend auth βœ” activo
SENDGRID_API_KEY SG.β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’3e1d nutritrack-api, daily-report-job notifications βœ” activo
πŸ’» CLI Quickstart β€” despliegue en 30 minutos
# 1. Instalar CLI y autenticar
$npm install -g @northflank/cli
$northflank login

# 2. Crear proyecto en regiΓ³n europea
$northflank create project nutritrack --region europe-west

# 3. Desplegar toda la infraestructura desde IaC
$northflank apply -f northflank.json --project nutritrack

# 4. Inyectar secretos
$northflank create secret nutritrack/nutritrack-secrets \
--data '{"OPENAI_API_KEY":"sk-...","STRIPE_SECRET_KEY":"sk_live_...","JWT_SECRET":"...","SENDGRID_API_KEY":"SG...."}'
$northflank link secret nutritrack/nutritrack-api --secret-group nutritrack-secrets

# 5. Ejecutar migraciΓ³n inicial
$northflank trigger job nutritrack/db-migrate-job

# 6. Verificar estado de servicios
$northflank get services --project nutritrack
$northflank logs nutritrack/nutritrack-api --follow

# 7. Escalar API si hay pico de trΓ‘fico
$northflank scale nutritrack/nutritrack-api --instances 5
πŸ“‹ Buenas prΓ‘cticas aplicadas
01
IaC versionado
northflank.json en el repo. Cualquier cambio de infra pasa por PR y code review.
02
Addons managed
PostgreSQL y Redis como addons Northflank. Backups automΓ‘ticos, no autogestiΓ³n.
03
Secret groups
Secretos agrupados por dominio (ai-services, billing, auth). Cero hardcoding.
04
Preview per PR
Cada PR despliega entorno de preview con URL propia. QA antes de merge.
05
Health checks
GET /health en la API. Reinicio automΓ‘tico y zero-downtime deployments.
06
Build cache
Nixpacks cachea capas Docker y deps de node_modules. Builds 3Γ— mΓ‘s rΓ‘pidos.
07
Jobs para migraciones
Prisma migrate deploy como ManualJob, no en startup. Rollback controlado.
08
HA en producciΓ³n
API con 2 instancias por defecto. Load balancer automΓ‘tico de Northflank.