Skip to content

Architecture generation: docker-compose.yml and Dockerfiles have dev/prod conflicts that prevent startup #426

@jiaminc-cmu

Description

@jiaminc-cmu

Bug Description

When generating a full-stack architecture (Next.js frontend + FastAPI backend + PostgreSQL), the generated docker-compose.yml and Dockerfiles have multiple conflicts that prevent containers from starting successfully. The Dockerfiles are built for production but docker-compose is configured for development (volume mounts, --reload, npm run dev), causing several failures.

Issues Found

1. Frontend: next: not found on startup

Files: frontend/Dockerfile + docker-compose.yml

The Dockerfile builds a production-optimized standalone Next.js app. But docker-compose mounts ./frontend:/app which overwrites the container's /app directory (including node_modules), then runs npm run dev. The anonymous volume /app/node_modules is empty on first run since the Dockerfile's production build uses standalone output, not a dev-ready node_modules.

Error: sh: next: not found

2. Backend: Permission denied on uvicorn

Files: backend/Dockerfile + docker-compose.yml

The Dockerfile installs packages to /root/.local (line 13: pip install --user) then switches to a non-root appuser (line 29: USER appuser). But docker-compose mounts ./backend:/app and overrides the command with uvicorn .... Since the user is appuser, it can't access /root/.local/bin/uvicorn.

Error: /usr/local/bin/python3.11: can't open file '/root/.local/bin/uvicorn': [Errno 13] Permission denied

3. Frontend: Stale .next build artifacts cause 500 error

Files: docker-compose.yml

The anonymous volume - /app/.next in docker-compose preserves production build artifacts from the Dockerfile build, which conflict with the dev server. Next.js dev mode expects to build .next from scratch but finds incompatible production artifacts, leading to missing fallback-build-manifest.json.

Error: ENOENT: no such file or directory, open '/app/.next/fallback-build-manifest.json'

4. Backend: Wrong import paths (backend.app.x instead of app.x)

Files: All Python files under backend/app/

All generated Python files use from backend.app.config import ... style imports. Inside the Docker container (and when running natively from the backend/ directory), the working directory is /app so the correct import path is from app.config import .... This affected 16 files.

Error: ModuleNotFoundError: No module named 'backend'

5. Backend: Missing email-validator dependency

File: backend/requirements.txt

The generated code uses Pydantic's EmailStr type but requirements.txt specifies pydantic>=2.5.0 instead of pydantic[email]>=2.5.0, so email-validator is not installed.

Error: ImportError: email-validator is not installed, run 'pip install pydantic[email]'

Root Cause

The generated architecture produces Dockerfiles designed for production (multi-stage builds, standalone output, non-root users) but a docker-compose.yml designed for development (source volume mounts, --reload, npm run dev). These two approaches are fundamentally incompatible without additional configuration.

Suggested Fix

Option A (Recommended): Generate separate Dockerfile (production) and Dockerfile.dev (development) for each service. Have docker-compose reference Dockerfile.dev which would:

  • Frontend: Use a simple node:20-alpine image, install deps, and run npm run dev
  • Backend: Use python:3.11-slim, install deps as root, and run uvicorn with --reload

Option B: Remove the dev-mode overrides from docker-compose (volume mounts, command overrides) so it uses the production Dockerfiles as intended.

Also fix:

  • Use from app.x imports instead of from backend.app.x in all generated Python files
  • Use pydantic[email] instead of pydantic in requirements.txt when EmailStr is used

Environment

  • Project type: Full-stack (Next.js 14.1.0 frontend + FastAPI backend + PostgreSQL)
  • Generated files: frontend/Dockerfile, backend/Dockerfile, docker-compose.yml

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions