A full-stack application for managing employee data, featuring a React frontend, Node.js/Express backend, and PostgreSQL database, all containerized with Docker.
| Component | Technology | Port |
|---|---|---|
| Frontend | React.js + Nginx | 4000 |
| Backend | Node.js + Express | 3000 |
| Database | PostgreSQL 16 | 5432 |
- Docker (v20.10+)
- Docker Compose (v2.0+)
- Start the application:
docker-compose up -d --build
- Load sample data (after services are running):
./scripts/load_employees.sh
.
βββ backend/ # Backend (Node.js + Express + PostgreSQL)
β βββ database/ # Database configuration and scripts
β β βββ init.sql # SQL initialization script
β β
β βββ src/ # Backend source code
β β βββ db.js # Database connection setup
β β βββ index.js # Application entry point (Express server)
β β β
β β βββ models/ # Data access layer (queries to DB)
β β β βββ employeeModel.js # Employee-related SQL queries
β β β
β β βββ controllers/ # Business logic layer
β β β βββ employeeController.js # Handles requests & responses
β β β
β β βββ routes/ # API endpoint definitions
β β βββ employeeRoutes.js # Employee-related routes
β β
β βββ Dockerfile # Docker configuration for backend
β βββ package.json # Backend dependencies and scripts
β
βββ frontend/ # Frontend (React + Nginx)
β βββ public/ # Public assets
β β βββ index.html # Main HTML template
β β
β βββ src/ # Frontend source code
β β βββ components/ # React UI components
β β β βββ App.js # Root component
β β β βββ AreaSection.jsx # Area section component
β β β βββ EmployeeCard.jsx # Employee card component
β β β βββ EmployeeDetailsModal.jsx # Employee details modal
β β β
β β βββ services/ # API service layer
β β β βββ api.js # Axios/fetch setup for backend calls
β β β
β β βββ app.css # Global styles (could use Tailwind/Bootstrap)
β β βββ index.js # React entry point
β β βββ reportWebVitals.js # Performance metrics
β β
β βββ Dockerfile # Docker configuration for frontend
β βββ nginx.conf # Nginx web server configuration
β βββ package.json # Frontend dependencies and scripts
β βββ package-lock.json # Exact dependency versions
β
βββ scripts/ # Utility scripts
β βββ load_employees.sh # Initial employee data loading script
β
βββ docker-compose.yml # Multi-container orchestration (frontend + backend + db)| Component | URL | Access Method |
|---|---|---|
| Frontend | http://localhost:4000 | Web browser |
| Backend | http://localhost:3000 | REST client |
| Database | localhost:5432 | PostgreSQL client |
Example API request:
curl http://localhost:3000/employeesThis document compiles comments, best practices, and important clarifications about the application and its deployment using Docker Compose.
- Frontend: Built with React.js and served by Nginx on port
4000. - Backend: Implemented in Node.js with Express, exposed on port
3000.
Contains the business logic and connects to PostgreSQL. - Database: PostgreSQL 16, automatically initialized using
init.sql. - Data loading script (
load_employees.sh): Facilitates inserting initial employee data into the backend via HTTP POST requests.
-
Data Persistence
- The
postgres_datavolume ensures that database information is not lost when restarting containers. - If you need a clean database, remove the volume:
docker-compose down -v
- The
-
Database Initialization
- The
init.sqlfile runs only the first time the PostgreSQL container is created. - If you need to modify the schema later, you must do it manually or run migration scripts.
- The
-
Service Dependencies & Startup Order
- The
depends_ondirective indocker-compose.ymlensures:- The backend waits for the database to start.
- The frontend waits for the backend to start.
- However, this does not fully guarantee the service is ready to accept connections.
For production environments, a healthcheck script is recommended.
- The
-
Running
load_employees.sh- This script must be run after all containers are up and running.
- If the backend is not ready yet, the script will fail.
- It can be adapted to retry until the backend becomes available.
-
React Optimization
- The
EmployeeCardcomponent can be optimized withReact.memoandPropTypesto avoid unnecessary re-renders and improve maintainability. - If using TypeScript, prefer strict type definitions instead of PropTypes.
- The
-
Development Best Practices
- In development, mapping the backend and frontend source code as volumes avoids rebuilding images for every change.
- Example for the backend in
docker-compose.override.yml:volumes: - ./backend/src:/app/src
-
Incomplete Frontend CRUD Implementation
- Login page
- Currently, the frontend only supports requested functionality.
- The remaining CRUD operations (Create, Read, Update, Delete) need to be implemented to match the backend API capabilities.
-
Lack of Automated Testing
- Due to time constraints, automated tests (unit, integration, and end-to-end) have not been implemented.
- It is recommended to add:
- Unit tests for React components and backend business logic.
- Integration tests for API endpoints.
- E2E tests to validate the complete user flow.
-
Authentication & Role Management
- For a more complete application, user authentication and role-based access control could be added.
- Example:
- Admin role: Full CRUD permissions.
- Regular user: Read-only access.
- This would also require adapting the backend endpoints to enforce access restrictions.
| Command | Description |
|---|---|
| docker-compose logs -f <some_service> | View service logs |
| docker-compose restart <some_service> | Restart services |
| docker-compose down --volumes | Full cleanup (including data) |
