Here’s a documentation template for running a Next.js project with GraphQL for data fetching:
-
How to Run the Project Locally
- Prerequisites
- Environment Setup
- Running the Project
- Common Issues
-
How to Promote a Branch to STG (Staging)
- Branching Strategy
- Promotion Steps
- Verification
-
How to Promote a Branch to PRD (Production)
- Release Preparation
- Release Process
- Post-Release
Before starting, ensure the following software is installed:
- npm (depending on your package manager)
-
Clone the Repository:
git clone https://github.com/Up-Brasil-Opal/opal-hr-dashboard.git cd opal-hr-dashboard -
Install Dependencies: Install all required packages:
npm install
-
Set Up Environment Variables:
-
Copy the
.env.examplefile to.env.local:cp .env.example .env.local
-
Fill in the environment variables:
NEXT_PUBLIC_API_ROOT_URL: Base URL for API requests.NEXT_PUBLIC_SOCKET_URL: WebSocket URL for real-time notifications.
NEXT_PUBLIC_ENCRYPTION_KEY: Key for encrypting/decrypting sensitive data.NEXT_PUBLIC_BENEFIT_ID: ID for a specific benefit configuration.
NEXT_PUBLIC_SENTRY_DSN: Sentry URL for error tracking.NEXT_PUBLIC_SENTRY_ENV: Environment for Sentry (e.g., development, production).
NEXT_PUBLIC_DD_CLIENT_TOKEN: Client token for Datadog analytics.NEXT_PUBLIC_DD_APPLICATION_KEY: Application key for Datadog.NEXT_PUBLIC_DD_SERVICE: Name of the service monitored by Datadog.NEXT_PUBLIC_DD_VERSION: Current version of the app for Datadog.NEXT_PUBLIC_DD_SITE: Datadog site region (e.g.,datadoghq.com).NEXT_PUBLIC_DD_SESSION_SAMPLE_RATE: Percentage of sessions to sample (e.g.,100for all).NEXT_PUBLIC_DD_SESSION_REPLAY_SAMPLE_RATE: Percentage of sessions to capture for replay (e.g.,20).
-
To start the Next.js application:
-
Development Server: Run the development server:
npm run dev
The app will be available at
http://localhost:3000. -
Build and Start in Production Mode:
npm run build npm start
The app will now be running in production mode at
http://localhost:3000.
-
Environment Variables Not Loaded:
- Ensure you have properly created and filled in
.env.local. - Restart the development server after changing environment variables.
- Ensure you have properly created and filled in
-
GraphQL API Connectivity:
- Verify the
NEXT_PUBLIC_API_ROOT_URLis reachable. - Check if you need to authenticate the API by providing a token in headers.
- Verify the
The project uses a well-structured branching strategy:
feature > dev > staging > main > release
- feature: Individual branches for new features or bug fixes.
- dev: Consolidates all feature branches after review.
- staging: Pre-production environment for thorough testing.
- main: Represents the production environment, ready for release.
- release: Prepares and manages production releases.
-
Ensure the Feature Branch is Complete:
- Feature should pass tests and review.
git checkout <feature-branch> git commit -m "<feature-branch>:work" git push origin <feature-branch>
-
Merge the Feature Branch into DEV:
git checkout dev git merge <feature-branch> git push origin dev
-
Promote to STAGING: After verifying the
devbranch, merge intostaging:git checkout staging git merge dev git push origin staging
- Deployment Check: Verify the app is live on the staging environment.
- Testing: Conduct thorough testing in the staging environment.
Before releasing:
-
Run Tests: Ensure all tests pass before deployment:
npm run test -
Code Freeze: Ensure no further changes are made.
-
Merge to Main:
- Merge
stagingintomainafter final verification:git checkout main git merge staging git push origin main
- Merge
-
Deploy to Production: Follow your deployment procedure (e.g., Vercel, Netlify, custom server).
- Validation: Check production status and monitor performance.
- Monitoring: Use tools like Sentry, LogRocket, or Datadog to track errors.
- Rollback: If necessary, revert to a stable release.
Ensure you’ve correctly set the Sentry DSN for error logging:
In .env.production, add:
SENTRY_DSN=<your_sentry_dsn>This configuration ensures Sentry is capturing errors in the production environment for proactive monitoring.