A robust, scalable transaction management microservice built with NestJS, TypeScript, Prisma, PostgreSQL, Docker and Swagger. This service provides comprehensive transaction lifecycle management with real-time status tracking, validation, and API documentation.
- NestJS - Progressive Node.js framework for building efficient and scalable server-side applications
- TypeScript - Strongly typed JavaScript for enhanced developer experience and code reliability
- PostgreSQL - Robust, open-source relational database system
- Prisma - Next-generation ORM with type-safe database access and migrations
- pgAdmin - Web-based PostgreSQL administration and development platform
- Swagger/OpenAPI - Interactive API documentation and testing interface
- class-validator - Decorator-based validation for DTOs
- Jest - Comprehensive testing framework with coverage reporting
- ESLint - Code linting and formatting
- Prettier - Code formatting and style consistency
- Docker - Containerization for consistent development and deployment
- Transaction Management: Create, read, and manage transaction records
- Status Tracking: Real-time transaction status monitoring (PENDING, COMPLETED, FAILED)
- Data Validation: Comprehensive input validation using decorators
- API Documentation: Interactive Swagger UI for API exploration
- Database Migrations: Version-controlled database schema management
- Type Safety: Full TypeScript support with Prisma-generated types
- Testing Suite: Unit and E2E testing with Jest
- Docker Support: Containerized development and deployment
src/
├── main.ts # Application bootstrap and Swagger setup
├── prisma/
│ ├── prisma.module.ts # Prisma module configuration
│ └── prisma.service.ts # Database service wrapper
└── transaction/
├── dto/
│ └── create-transaction.dto.ts # Data transfer objects
├── entities/
│ └── transaction.entity.ts # Domain entities
├── transaction.controller.ts # REST API endpoints
├── transaction.service.ts # Business logic
└── transaction.module.ts # Module configuration
- Node.js (v18 or higher)
- Docker and Docker Compose
- npm or yarn package manager
-
Clone the repository
git clone `https://github.com/asabahebwa/transaction-microservice.git` cd transactionservice
-
Install dependencies
npm install
-
Environment Setup Create a
.envfile in the root directory:# Database Configuration DATABASE_URL="postgresql://username:password@localhost:5432/transactiondb" POSTGRES_USER=username POSTGRES_PASSWORD=password POSTGRES_DB=transactiondb POSTGRES_PORT=5432 # pgAdmin Configuration PGADMIN_DEFAULT_EMAIL=admin@example.com PGADMIN_DEFAULT_PASSWORD=admin PGADMIN_PORT=5050
-
Start the database
docker-compose up -d
-
Run database migrations
npx prisma migrate dev
-
Generate Prisma client
npx prisma generate
# Start development server with hot reload
npm run start:dev
# Start in debug mode
npm run start:debug
# Build for production
npm run build
# Start production server
npm run start:prodOnce the application is running, access the interactive API documentation at:
- Swagger UI: http://localhost:3000/api
- pgAdmin: http://localhost:5050 (Database administration)
POST /transaction- Create a new transactionGET /transaction- Retrieve all transactionsGET /transaction/:id- Retrieve a specific transaction
The service uses the following database schema:
model Transaction {
id Int @id @default(autoincrement())
status Status
accountId String @default(uuid())
description String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
enum Status {
PENDING
COMPLETED
FAILED
}The service includes Docker Compose configuration for easy deployment:
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Check the NestJS Documentation
- Visit the Prisma Documentation
Built with ❤️ using NestJS, Prisma, and PostgreSQL