Comprehensive Developer Guide

Your step-by-step instructions to get the project environment fully operational, from database setup to production launch.

0. Prerequisites

Before you begin, please ensure you have the following software installed and configured on your system. These tools are essential for the development and deployment of this project.

  • Node.js: Version 18.x or higher. (Check with node -v)
  • npm: Version 9.x or higher, usually comes with Node.js. (Check with npm -v)
  • Docker: Latest stable version for running containerized services like PostgreSQL. (Check with docker --version)
  • Git: For version control and cloning the repository. (Check with git --version)

If you're missing any of these, please install them from their official websites. Ensure Docker Desktop is running before proceeding with database setup.

1. Start Postgres Database

This project utilizes a PostgreSQL database managed via Docker. Docker ensures a consistent and isolated database environment across different machines. The following steps will guide you through starting the database container.

First, navigate into the 'docker' directory located at the root of your project. This directory contains the 'docker-compose.yml' file, which defines the configuration for our PostgreSQL service, including image, ports, and volumes.

Command
cd docker

Expected Outcome:

Your terminal prompt should now reflect that you are inside the 'docker' directory.

Execute this command to build (if it's the first time or if changes were made to the Dockerfile/image) and start the PostgreSQL service defined in 'docker-compose.yml'. The '-d' (detached) flag runs the container in the background, so your terminal remains free.

Command
docker compose up -d

Note: If you omit the '-d' flag (i.e., 'docker compose up'), the container logs will stream directly to your terminal. You can stop it with Ctrl+C. To check if the container is running in detached mode, use 'docker ps'.

Expected Outcome:

You should see messages indicating that the Postgres container is being created/started. If successful, 'docker ps' will list 'ned-tech-web-db-1' (or similar) as running.

2. Run Database Migrations

Once the database container is running, you need to apply the database schema migrations. Migrations are version-controlled changes to your database structure, ensuring it aligns with the application's data models.

Return to the root directory of your project. This command executes the development database migration script defined in your 'package.json'. It typically uses an ORM tool (like Drizzle ORM) to apply pending migration files to the database schema, creating tables and columns as needed.

Command
npm run db:dev-migrate

Note: Ensure you are in the project's root directory (you might need to 'cd ..' if you are still in the 'docker' directory). Also, verify that your '.env' file has the correct database connection string (DB_URL). Migrations might fail if the database is not accessible or if there are errors in the migration files.

Expected Outcome:

The terminal should output logs from the migration tool, indicating which migration files are being applied. A success message usually appears at the end, confirming that the database schema is up to date.

3. Start Development Server

With the database prepared, you can now start the local development server. This server allows you to view your application in a browser, and it typically includes features like hot module replacement (HMR) for a fast development feedback loop.

This command, executed from the project root, starts the Next.js development server. It compiles the application, watches for file changes, and serves the content, usually on port 3000.

Command
npm run dev

Note: The terminal will display the local URL (e.g., http://localhost:3000) where the application is accessible. Any changes you make to the frontend or backend code (that Next.js handles) should automatically trigger a recompilation and browser refresh.

Expected Outcome:

You will see output in the terminal indicating that the server has started successfully, often including the local address (e.g., 'ready - started server on 0.0.0.0:3000, url: http://localhost:3000'). Opening this URL in your browser should display the application.

4. Build & Run for Production

When you are ready to deploy your application to a live environment, you must first create an optimized production build. This build is then served by a production-ready server.

This command, run from the project root, triggers the Next.js production build process. It compiles your application into highly optimized static assets (HTML, CSS, JavaScript) and server-side code. The output is typically placed in the '.next' directory.

Command
npm run build

Note: The build process can take some time, especially for larger applications, as it involves various optimizations like code splitting, minification, and tree-shaking. Ensure there are no build errors reported in the terminal.

Expected Outcome:

The terminal will show the build progress and, upon completion, often provides a summary of the generated page types (static, server-rendered, etc.). A '.next' folder will be created or updated in your project root.

After a successful build, this command starts the Next.js production server. This server is designed for performance and stability, serving the optimized assets generated by the build process.

Command
npm run start

Note: This command should be used in your deployment environment (e.g., on a server or PaaS). It typically runs on a specific port (often 3000 by default, but configurable). Unlike the development server, it does not watch for file changes.

Expected Outcome:

The terminal will indicate that the production server has started, along with the URL it's listening on. The application should now be accessible via this URL, running in its optimized production mode.