A multi-channel digital payment platform for cooperatives to collect, track, and manage rent-related payments — all integrated with local payment gateways and IremboPay.
# Copay Backend Server
A production-grade NestJS backend for the Cooperative Payment System (Copay) built with Domain-Driven Design (DDD) and Clean Architecture principles.
## 🚀 Features
- **Multi-tenancy**: Each cooperative operates as an isolated tenant
- **Role-based Access Control**: Super Admin, Organization Admin, and Tenant roles
- **JWT Authentication**: Secure phone number + 4-digit PIN authentication
- **Fastify**: High-performance web framework
- **MongoDB with Prisma**: Modern database ORM with type safety
- **Swagger Documentation**: Auto-generated API documentation
- **Rate Limiting**: Built-in throttling protection
- **Caching**: Redis-based caching for improved performance
- **Validation**: Comprehensive input validation with DTOs
- **Clean Architecture**: DDD modules with separation of concerns
## 🏗️ Architecture
```
src/
├── config/ # Configuration files and validation
├── modules/ # Feature modules (DDD structure)
│ ├── auth/ # Authentication & JWT
│ ├── user/ # User management & RBAC
│ └── ... # Other business modules
├── shared/ # Shared utilities, guards, decorators
├── prisma/ # Database service and configuration
└── main.ts # Application bootstrap with Fastify
```
## 📋 Prerequisites
- Node.js (v18+)
- MongoDB database
- Redis (optional, for caching)
## 🛠️ Installation
1. **Clone the repository**
```bash
git clone
cd copay-backend-server
```
2. **Install dependencies**
```bash
npm install
```
3. **Setup environment variables**
```bash
cp .env.example .env
```
Update the `.env` file with your database URL and configuration:
```env
DATABASE_URL="mongodb+srv://username:password@
cluster.mongodb.net"
JWT_SECRET="your-super-secret-jwt-key"
# ... other configuration
```
4. **Generate Prisma client**
```bash
npm run prisma:generate
```
5. **Seed the database** (optional)
```bash
npm run prisma:seed
```
## 🚀 Running the Application
```bash
# D …