Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/docs/public/openapi/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
{
"url": "/openapi/cyclist-profile.json",
"title": "Cyclist Profile API"
},
{
"url": "/openapi/emergency-calls.json",
"title": "Emergency Calls API"
},
{
"url": "/openapi/traffic-crashes.json",
"title": "Traffic Crashes API"
}
]
25 changes: 25 additions & 0 deletions apps/emergency-calls/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Environment Configuration

# Node Environment
NODE_ENV=development

# Logging
LOG_LEVEL=info

# Server
PORT=3010

# Database
DATABASE_URL=postgres://postgres:postgres@localhost:5432/atlas_dev

# Or use individual settings:
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=atlas_dev

# SSL Configuration
# Path to SSL CA certificate for production databases (e.g., Digital Ocean)
# When set, SSL will be automatically enabled
# DATABASE_SSL_CA=/path/to/ca-certificate.crt
86 changes: 86 additions & 0 deletions apps/emergency-calls/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Prune stage - Use turbo to create a subset of the monorepo with only the packages needed
FROM node:22.15.0-slim AS pruner

# Set working directory
WORKDIR /app

# Install pnpm and turbo
RUN corepack enable && corepack prepare pnpm@10.10.0 --activate && \
npm install -g turbo

# Copy repo configuration
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml turbo.json ./

# Copy the source code needed for turbo prune
COPY apps/emergency-calls/package.json ./apps/emergency-calls/package.json
COPY packages/typescript-config/package.json ./packages/typescript-config/package.json
COPY packages/database/package.json ./packages/database/package.json

# Use turbo to prune the monorepo to only the emergency-calls app and its dependencies
RUN turbo prune --scope=@atlas/emergency-calls --docker

# Build stage - Use the pruned repo to build the app
FROM node:22.15.0-slim AS builder

# Set working directory
WORKDIR /app

# Install pnpm
RUN corepack enable && corepack prepare pnpm@10.10.0 --activate

# Copy pruned lockfile and package.json files
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml

# Install dependencies
RUN pnpm install --frozen-lockfile

# Copy source files from pruned repo
COPY --from=pruner /app/out/full/ .

# Copy the rest of the source code
COPY apps/emergency-calls ./apps/emergency-calls
COPY packages/typescript-config ./packages/typescript-config
COPY packages/database ./packages/database
COPY turbo.json ./turbo.json

# Build database package first (required dependency)
RUN pnpm --filter @atlas/database build

# Build the emergency-calls app
RUN pnpm --filter @atlas/emergency-calls build

# Production stage
FROM node:22.15.0-slim AS production

# Set working directory
WORKDIR /app

# Install pnpm
RUN corepack enable && corepack prepare pnpm@10.10.0 --activate

# Copy pruned lockfile and package.json files
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml

# Install production dependencies only
RUN pnpm install --frozen-lockfile --prod

# Copy built files from builder stage
COPY --from=builder /app/apps/emergency-calls/dist ./apps/emergency-calls/dist
COPY --from=builder /app/packages/database/dist ./packages/database/dist
# Copy migrations folder from database package
COPY --from=builder /app/packages/database/src/migrations ./packages/database/src/migrations

# Set environment variables
ENV NODE_ENV=production
ENV LOG_LEVEL=info
ENV PORT=3010

# Expose port (can be overridden at runtime)
EXPOSE ${PORT}

# Default command to start the application
CMD ["node", "apps/emergency-calls/dist/index.js"]
215 changes: 215 additions & 0 deletions apps/emergency-calls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
# EmergencyCalls API

API service for emergency-calls

## Requirements

- Node.js 22.15.0
- pnpm 10.10.0
- PostgreSQL database

We recommend using [mise](https://mise.jdx.dev/) for managing tool versions. A `.tool-versions` file is included in the repository root.

## Getting Started

### Development with Docker

The easiest way to get started is using Docker Compose:

```bash
# Start the application and database
docker compose up -d

# Run database migrations
docker compose exec app pnpm db:migrate

# View logs
docker compose logs -f

# Stop the application
docker compose down
```

### Manual Setup

If you prefer to run the application without Docker:

```bash
# Install dependencies (from monorepo root)
pnpm install

# Start the development server
pnpm --filter @atlas/emergency-calls dev

# In another terminal, run migrations
pnpm --filter @atlas/emergency-calls db:migrate

```

The application will be available at http://localhost:3010

## Environment Variables

Create a `.env` file in the app directory (see `.env.example`):

```bash
NODE_ENV=development
LOG_LEVEL=info
PORT=3010

# Database
DATABASE_URL=postgres://postgres:postgres@localhost:5432/atlas_dev
# Or use individual settings:
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=atlas_dev
DB_SSL=false
```

## Database Management

This app uses the shared `@atlas/database` package for database management.

```bash
# Generate new migrations (from database package)
pnpm --filter @atlas/database db:generate

# Apply migrations
pnpm --filter @atlas/database db:migrate

# View database with Drizzle Studio
pnpm --filter @atlas/database db:studio

# Seed the database with sample data (if available)
pnpm --filter @atlas/database db:seed
```

## Development

```bash
# Start development server with hot reload
pnpm --filter @atlas/emergency-calls dev

# Run tests
pnpm --filter @atlas/emergency-calls test

# Run tests in watch mode
pnpm --filter @atlas/emergency-calls test:watch

# Type checking
pnpm --filter @atlas/emergency-calls check-types

# Linting
pnpm --filter @atlas/emergency-calls lint

# Format code
pnpm --filter @atlas/emergency-calls format
```

## Building

```bash
# Build the application
pnpm --filter @atlas/emergency-calls build

# Start production server
pnpm --filter @atlas/emergency-calls start
```

## API Documentation

The API documentation is automatically generated from the OpenAPI specification.

```bash
# Generate OpenAPI spec
pnpm --filter @atlas/emergency-calls generate-openapi

# View in the docs app
pnpm --filter @atlas/docs dev
# Then open http://localhost:3001
```

## Docker Deployment

The EmergencyCalls API can be deployed as a Docker container. The container image is automatically built and pushed to GitHub Container Registry (ghcr.io) when changes are merged to the main branch.

### Running with Docker

```bash
# Pull the latest image
docker pull ghcr.io/ameciclo/atlas/emergency-calls:latest

# Run the container with PostgreSQL
docker compose up -d
```

The API will be available at http://localhost:3010

### Building Locally

```bash
# From the emergency-calls app directory
docker compose up -d

# Or from the root of the monorepo
docker build -t atlas-emergency-calls -f apps/emergency-calls/Dockerfile .
docker run -p 3010:3010 --env-file .env atlas-emergency-calls
```

## Health Check

The API includes a health check endpoint:

```
GET /health
```

Response:
```json
{
"status": "ok",
"timestamp": "2023-07-01T12:34:56.789Z",
"service": "emergency-calls",
"database": "connected"
}
```

## Project Structure

```
apps/emergency-calls/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ app.ts # App configuration
β”‚ β”œβ”€β”€ index.ts # Entry point
β”‚ β”œβ”€β”€ env.ts # Environment variables
β”‚ β”œβ”€β”€ db/ # Database
β”‚ β”‚ β”œβ”€β”€ index.ts # Database connection
β”‚ β”‚ └── schema.ts # Re-exports from @atlas/database
β”‚ β”œβ”€β”€ lib/ # Shared utilities
β”‚ β”‚ β”œβ”€β”€ create-app.ts # App factory
β”‚ β”‚ β”œβ”€β”€ types.ts # TypeScript types
β”‚ β”‚ └── constants.ts # Constants
β”‚ β”œβ”€β”€ middlewares/ # Middleware
β”‚ β”‚ └── pino-logger.ts # Logger middleware
β”‚ └── routes/ # API routes
β”‚ β”œβ”€β”€ health.ts # Health check
β”‚ └── example/ # Example routes
β”œβ”€β”€ test/ # Tests
β”œβ”€β”€ Dockerfile # Docker configuration
β”œβ”€β”€ docker-compose.yml # Docker Compose configuration
β”œβ”€β”€ package.json # Dependencies and scripts
β”œβ”€β”€ tsconfig.json # TypeScript configuration
└── vitest.config.ts # Vitest configuration
```

**Note:** Database schema is defined in `packages/database/src/schemas/emergency-calls/schema.ts` and shared across the monorepo.

## Contributing

See the main [README](../../README.md) for contribution guidelines.

## License

This project is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details.
Loading