# Enterprise ERP Backend

An enterprise-grade ERP backend application built with Node.js, Express, TypeScript, and PostgreSQL.

## Features

- **Modern TypeScript Architecture**: Strongly-typed codebase with classes, interfaces, and proper separation of concerns.
- **Complete Security Stack**: Authentication, authorization, input validation, SQL injection protection, rate limiting, and more.
- **Comprehensive Logging**: Structured logging with request tracking and correlation IDs.
- **Performance Monitoring**: Prometheus metrics for tracking application performance.
- **Database Integration**: TypeORM integration with PostgreSQL for safe, type-safe database operations.
- **Middleware Stack**: Request/response handling, error handling, security policies, and more.
- **Clean API Structure**: Organized routes, controllers, and services pattern.

## Getting Started

### Prerequisites

- Node.js 16+
- PostgreSQL 13+

### Installation

1. Clone the repository
2. Install dependencies:

```bash
npm install
```

3. Copy the example environment file:

```bash
cp .env.example .env
```

4. Update the environment variables in the `.env` file.

5. Start the development server:

```bash
npm run dev
```

## Project Structure

```
src/
├── config/         # Configuration files
├── controllers/    # Request handlers
├── entities/       # Database entities
├── middleware/     # Express middleware
├── migrations/     # Database migrations
├── routes/         # API routes
├── services/       # Business logic
├── utils/          # Utility functions
└── validators/     # Request validation schemas
```

## API Endpoints

### Authentication

- `POST /api/v1/auth/register` - Register a new user
- `POST /api/v1/auth/login` - Login a user
- `POST /api/v1/auth/logout` - Logout a user
- `GET /api/v1/auth/me` - Get current user
- `POST /api/v1/auth/refresh-token` - Refresh authentication token

### Users

- `GET /api/v1/users` - Get all users (admin only)
- `GET /api/v1/users/:id` - Get user by ID
- `POST /api/v1/users` - Create a new user (admin only)
- `PUT /api/v1/users/:id` - Update a user
- `DELETE /api/v1/users/:id` - Delete a user (admin only)

### Health Checks

- `GET /health` - Check application health
- `GET /readiness` - Check if the application is ready to serve traffic
- `GET /liveness` - Check if the application is alive

### Metrics

- `GET /metrics` - Get application metrics

## License

This project is licensed under the MIT License - see the LICENSE file for details.