Skip to content

Conversation

Copy link

Copilot AI commented Oct 29, 2025

Initializes a production-ready REST API foundation using TypeScript, Fastify, and Prisma with clean architecture principles.

Structure

  • src/common/ - Shared infrastructure

    • config/ - Environment-based configuration with explicit .env path resolution
    • middleware/ - Centralized error handler with structured logging
    • types/ - API response interfaces and pagination types
    • utils/ - Prisma client singleton, Pino logger setup
  • src/controllers/ - Request/response handlers

  • src/services/ - Business logic layer

  • src/routes/ - Fastify route definitions with schema validation

Implementation

Health check endpoint demonstrating the pattern:

// Service layer
export class HealthService {
  async checkHealth(): Promise<HealthStatus> {
    const databaseConnected = await this.checkDatabase();
    return { status: databaseConnected ? 'healthy' : 'unhealthy', ... };
  }
}

// Controller layer
export class HealthController {
  async getHealth(_request: FastifyRequest, reply: FastifyReply) {
    const health = await healthService.checkHealth();
    const response: ApiResponse = { success: true, data: health };
    reply.status(health.status === 'healthy' ? 200 : 503).send(response);
  }
}

// Route registration
await fastify.register(healthRoutes, { prefix: '/api/v1' });

Configuration

  • TypeScript strict mode with ES2022 target
  • ESLint 9 flat config with TypeScript parser
  • Fastify with Helmet (security headers) and CORS
  • Prisma with PostgreSQL, includes example schema
  • Graceful shutdown handlers for SIGINT/SIGTERM

Scripts

  • npm run dev - Hot reload with tsx
  • npm run build - TypeScript compilation
  • npm run lint - ESLint with Prettier integration
  • npm run prisma:generate - Generate Prisma Client
  • npm run prisma:migrate - Run migrations

Endpoints: GET / (info), GET /api/v1/health (health check with DB connectivity)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /usr/local/bin/node /home/REDACTED/work/ldacapi/ldacapi/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.18.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2025-10-29T01:24:05Z&#34;,&#34;project_hash&#34;:&#34;811b365c&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/ldacapi/ldacapi/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;fc09e426&#34;,&#34;endpoint&#34;:&#34;REDACTED&#34;,&#34;disable&#34;:false,&#34;arch&#34;:&#34;x64&#34;,&#34;os&#34;:&#34;linux&#34;,&#34;node_version&#34;:&#34;v20.19.5&#34;,&#34;ci&#34;:true,&#34;ci_name&#34;:&#34;GitHub Actions&#34;,&#34;command&#34;:&#34;generate --postinstall \&#34;UNABLE_TO_FIND_POSTINSTALL_TRIGGER__ENVAR_MISSING\&#34;&#34;,&#34;schema_providers&#34;:[&#34;postgresql&#34;],&#34;schema_preview_features&#34;:[],&#34;schema_generators_providers&#34;:[&#34;prisma-client-js&#34;],&#34;cache_file&#34;:&#34;/home/REDACTED/.cache/checkpoint-nodejs/prisma-fc09e426&#34;,&#34;cache_duration&#34;:43200000,&#34;remind_duration&#34;:172800000,&#34;force&#34;:false,&#34;timeout&#34;:5000,&#34;unref&#34;:true,&#34;child_path&#34;:&#34;/home/REDACTED/work/ldacapi/ldacapi/node_modules/prisma/build/child&#34;,&#34;client_event_id&#34;:&#34;&#34;,&#34;previous_client_event_id&#34;:&#34;&#34;,&#34;check_if_update_available&#34;:true} (dns block)
    • Triggering command: /usr/local/bin/node /home/REDACTED/work/ldacapi/ldacapi/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;6.18.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2025-10-29T01:25:28Z&#34;,&#34;project_hash&#34;:&#34;811b365c&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/ldacapi/ldacapi/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;fc09e426&#34;,&#34;endpoint&#34;:&#34;REDACTED&#34;,&#34;disable&#34;:false,&#34;arch&#34;:&#34;x64&#34;,&#34;os&#34;:&#34;linux&#34;,&#34;node_version&#34;:&#34;v20.19.5&#34;,&#34;ci&#34;:true,&#34;ci_name&#34;:&#34;GitHub Actions&#34;,&#34;command&#34;:&#34;generate&#34;,&#34;schema_providers&#34;:[&#34;postgresql&#34;],&#34;schema_preview_features&#34;:[],&#34;schema_generators_providers&#34;:[&#34;prisma-client-js&#34;],&#34;cache_file&#34;:&#34;/home/REDACTED/.cache/checkpoint-nodejs/prisma-fc09e426&#34;,&#34;cache_duration&#34;:43200000,&#34;remind_duration&#34;:172800000,&#34;force&#34;:false,&#34;timeout&#34;:5000,&#34;unref&#34;:true,&#34;child_path&#34;:&#34;/home/REDACTED/work/ldacapi/ldacapi/node_modules/prisma/build/child&#34;,&#34;client_event_id&#34;:&#34;&#34;,&#34;previous_client_event_id&#34;:&#34;&#34;,&#34;check_if_update_available&#34;:true} (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

bootstrap code using typescript, fastify and prisma for Node.js 24. This project is rest API only. Create a common folder that uses best practices for the routes, services and others.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 29, 2025 01:28
- Set up project structure with Node.js 24 configuration
- Configure TypeScript, ESLint, and Prettier
- Implement Fastify web framework with security plugins
- Set up Prisma ORM with example schema
- Create common folder with best practices:
  - config/ for app and database configuration
  - middleware/ for error handling
  - utils/ for database client and logger
  - types/ for shared TypeScript types
- Implement health check endpoint with database connectivity check
- Add proper folder structure: routes, services, controllers
- Configure development and production scripts
- Update README with comprehensive documentation

Co-authored-by: alvinsw <[email protected]>
Copilot AI changed the title [WIP] Create a common folder for best practices in routes and services Bootstrap REST API with TypeScript, Fastify, and Prisma for Node.js 24 Oct 29, 2025
Copilot AI requested a review from alvinsw October 29, 2025 01:33
Copilot finished work on behalf of alvinsw October 29, 2025 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants