Getting Started
This guide will help you set up and run the AMT Backend application locally.
Prerequisites
- Node.js (>=14.0.0)
- MySQL 5.7 or higher
- Redis server
- npm or yarn package manager
- Git
Installation
1. Clone the Repository
git clone [repository-url]
cd amt-backend
2. Install Dependencies
npm install
3. Environment Configuration
Create a .env file in the root directory with the following variables:
# Application
NODE_ENV=development
PORT=8080
API_PREFIX=/api
# Database
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=amt_development
DB_PORT=3306
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
# JWT
APP_SECRET=your-secret-key
JWT_EXPIRES_IN=7d
# AWS (optional for local dev)
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your-key
AWS_SECRET_ACCESS_KEY=your-secret
# Kafka
KAFKA_BROKERS=localhost:9092
# API Keys (as needed)
SGMAIL_APIKEY=your-sendgrid-key
SENTRY_DSN=your-sentry-dsn
4. Database Setup
Run database migrations:
npm run migrate
Seed initial data (if available):
npm run seed
Running the Application
Development Mode
npm run dev
This starts the application with nodemon for automatic reloading on file changes.
Production Mode
Build the application:
npm run build
Start the production server:
npm start
Using PM2
For production deployment with PM2:
npm run startProd
Testing
Run the test suite:
npm test
Run tests with coverage:
npm run test:coverage
Code Quality
Linting
Check code style:
npm run lint
Fix linting issues:
npm run lint:fix
Type Checking
Verify TypeScript types:
npx tsc --noEmit
API Documentation
Once the application is running, access the Swagger documentation at:
http://localhost:8080/api-docs
Common Development Tasks
Creating a New Feature Module
- Create a new directory under
server/features/ - Add the following structure:
feature-name/
├── controllers/
├── services/
├── models/
├── dto/
├── interfaces/
└── events/
Adding a New Model
- Create model file in
server/models/ - Register it in
server/databases/index.ts - Create a migration if needed
Creating a Migration
npx sequelize-cli migration:generate --name migration-name
Debugging
Using VS Code
Add this configuration to .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug TypeScript",
"program": "${workspaceFolder}/server/index.ts",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"env": {
"NODE_ENV": "development"
}
}
]
}
Logging
The application uses Winston for logging. Logs are stored in:
- Development: Console output
- Production:
logs/directory
Troubleshooting
Database Connection Issues
- Verify MySQL is running
- Check database credentials in
.env - Ensure database exists
Redis Connection Issues
- Verify Redis server is running
- Check Redis configuration
- Test connection:
redis-cli ping
Port Already in Use
Change the port in .env or kill the process:
lsof -i :8080
kill -9 [PID]
Next Steps
- Review the Architecture Documentation
- Explore the API Reference
- Learn about Database Schema
- Read the Deployment Guide