Develop Recreation Resources with Ease: A Guide to BC Gov Tools
Are you looking to contribute to the BC government's Recreation Resource Services project? This guide simplifies the setup and development process, providing actionable steps to get you started. Learn how to leverage these essential tools for effective recreation resource management.
Streamline Project Setup: Your Development Environment Awaits
Setting up your local environment is the first step. Follow these instructions to get your development environment ready.
Prerequisites: Essential Software for Development
Before diving into the project, ensure you have the following installed:
- Node.js: A JavaScript runtime environment.
- npm: Node Package Manager.
- Docker or PostgreSQL 16: Choose Docker for containerization or install PostgreSQL 16 directly.
- Flyway: For database schema migrations.
Quick Start with Docker Compose
Simplify the setup with Docker Compose.
- Clone the project:
git clone [email protected]:bcgov/nr-rec-resources.git
- Navigate to the project directory:
cd nr-rec-resources
- Start the application:
docker-compose up
Access the application in your browser at http://localhost:3000
.
Local Installation: A Step-by-Step Guide
Alternatively, set up the application locally.
- Install project dependencies:
npm install
in the base directory. - Install PostgreSQL 16 and Flyway.
Database Management: Setting up PostgreSQL and Flyway
Efficiently manage your database schemas with Flyway.
Setup Database and Run Migrations
-
Create a
.env
file in thebackend
directory usingbackend/.env.example
as a template. -
Run the following commands:
make create_db
make migrate
make load_fixtures
-
To reset the database, use
make migrate
.
Backend and Frontend Development: Jump into Coding
With your environment set up, it's time to start backend and frontend development.
Backend Setup: Running the Server
- Navigate to the backend directory:
cd backend
- Install dependencies:
npm install
- Generate Prisma client:
npx prisma generate
- Start the development server:
npm run dev
Frontend Setup: Launch the Application
- Navigate to the frontend directory:
cd frontend
- Create a
.env
file usingfrontend/.env.example
as a template. - Install dependencies:
npm install
- Start the development server:
npm run dev
- Access the application at
http://localhost:3000
.
API Client Library: Generate TypeScript Axios Client
Generate the TypeScript client library from your OpenAPI specification.
Generate API Client: Simplifying API Interactions
Run npm run install-client-sdk
from the project root folder. This command:
- Generates TypeScript client code using Axios.
- Uses the OpenAPI spec from your local NestJS server (port 8000).
- Outputs the code to
src/service/recreation-resource
directory.
Prisma Schema and Client: Keeping Your Database in Sync
Keep your Prisma schema and client up-to-date with database changes.
Update Prisma: Sync with Database Changes
- Navigate to the backend directory:
cd backend
- Pull the latest schema from the database:
npx prisma db pull
- Generate the Prisma client:
npx prisma generate
- View the updated schema in
backend/prisma/schema.prisma
.
Ensure Code Quality using Pre-commit Hooks
Maintain code quality through automated pre-commit checks.
Install and Use Pre-commit Hooks
- Install Pre-commit.
- Run
pre-commit install
in the root directory.
Pre-commit will now run on your staged files before each commit.
Skipping or Running All Pre-commit Checks
- Skip hooks:
git commit -m "Your commit message" --no-verify
- Run on all files:
pre-commit run --all-files
API Metrics: Monitoring Performance
Understand how to use API metrics for your recreation resource services to monitor latency, status codes, and error counts
Setting Up API Metrics
This application uses AWS CloudWatch Embedded Metric Format (EMF) to capture key performance and usage metrics.
- Interceptor: The
MetricsInterceptor
measures request latency and gathers data. - Data Collection: Collects HTTP method, status code, path, client IP, and user agent.
Viewing Metrics
Metrics can be viewed in AWS CloudWatch under the RecreationSitesAndTrailsBCAPI
namespace. Filter by Operation, Method, or StatusCode dimensions. Understand the status of your Recreation resource services.