Skip to content

Employee Management - Full Stack Application (Node.js + React) πŸ“Œ Project Description A full-stack web application for managing employee information, featuring: Backend: REST API built with Node.js and Express Frontend: React.js interface with organized employee display Database: Data persistence using PostgreSQL

Notifications You must be signed in to change notification settings

FrancoRivero2025/Freelance_test_exercise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ Employee Management System

A full-stack application for managing employee data, featuring a React frontend, Node.js/Express backend, and PostgreSQL database, all containerized with Docker.

🌐 System Overview

System Architecture Diagram

πŸ› οΈ Technical Stack

Component Technology Port
Frontend React.js + Nginx 4000
Backend Node.js + Express 3000
Database PostgreSQL 16 5432

πŸš€ Getting Started

Prerequisites

Installation & Execution

  1. Start the application:
    docker-compose up -d --build
  2. Load sample data (after services are running):
    ./scripts/load_employees.sh
    

Project structure

.
β”œβ”€β”€ 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)

πŸ”Œ Accessing Services

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/employees

πŸ““ Technical Notes

This document compiles comments, best practices, and important clarifications about the application and its deployment using Docker Compose.


πŸ” Structure & Services

  • 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.

πŸ’‘ Clarifications

  1. Data Persistence

    • The postgres_data volume ensures that database information is not lost when restarting containers.
    • If you need a clean database, remove the volume:
      docker-compose down -v
  2. Database Initialization

    • The init.sql file 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.
  3. Service Dependencies & Startup Order

    • The depends_on directive in docker-compose.yml ensures:
      • 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.
  4. 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.
  5. React Optimization

    • The EmployeeCard component can be optimized with React.memo and PropTypes to avoid unnecessary re-renders and improve maintainability.
    • If using TypeScript, prefer strict type definitions instead of PropTypes.
  6. 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

πŸ“ Improvement Roadmap

  1. 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.
  2. 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.
  3. 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.

βš™οΈ Maintenance Commands

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)

About

Employee Management - Full Stack Application (Node.js + React) πŸ“Œ Project Description A full-stack web application for managing employee information, featuring: Backend: REST API built with Node.js and Express Frontend: React.js interface with organized employee display Database: Data persistence using PostgreSQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published