Architecture overview
This project implements a full-stack web application with a React frontend and Express backend, containerized using a multi-stage Docker build process. The architecture is designed for production deployment with optimized build steps and minimal container size.System components
The application consists of three main components:- React frontend - A client-side application built with React 19.2.0
- Express backend - A Node.js API server using Express 5.1.0
- Docker container - Multi-stage build process for optimized production deployment
Component interaction
The system follows a traditional client-server architecture:Multi-stage Docker build process
The application uses a three-stage Docker build to optimize the final production image:Stage 1: Frontend build
- Uses Node.js 18 Alpine for a lightweight base image
- Installs dependencies from
client/package.json - Runs
npm run buildto create production-optimized static files - Outputs built files to
client/builddirectory
Stage 2: Backend build
- Prepares the Express server with production dependencies
- Installs only the packages needed for runtime (express, cors)
- Copies the server source code
Stage 3: Production image
- Combines artifacts from both build stages
- Places the built React app in
server/client/build - Exposes port 5000 for the Express server
- Starts the application with a single command:
node server/index.js
The multi-stage build ensures the final image only contains production dependencies and compiled code, significantly reducing the image size and attack surface.
Port configuration
The application runs on port 5000 by default:- Configurable via the
PORTenvironment variable - Falls back to port 5000 if not specified
- Exposed in the Dockerfile for container networking
Container structure
In the production container, the file structure is:Deployment benefits
Optimized size
Multi-stage builds eliminate build tools and source files from the final image
Single container
Both frontend and backend run in one container, simplifying deployment
Consistent environment
Node.js 18 Alpine provides a stable, lightweight runtime
Fast builds
Separate build stages allow Docker to cache layers efficiently
Next steps
Frontend architecture
Learn about the React application structure
Backend architecture
Explore the Express server implementation