A scalable, production-ready NestJS backend for the Caravan platform. This project provides a robust foundation for managing insurance, payments, users, and more, with integrations for Redis, Kafka, Cloudinary, and other essential services.
This project is currently in active development. Contributions are welcome!
- 🚀 Features
- Architecture
- Hosting Cost Estimation
- 📂 Folder Structure
- 🛠️ Setup & Run
- 🧪 Scripts
- 📖 API Documentation
- 🐳 Docker Compose
- 📦 License
- 🤝 Contributing
- 🧑💻 Author
- 📬 Contact
- ✅ Modular Configuration: Centralized config management via
.envandConfigModule. - 🔐 Authentication System: Passport.js with JWT strategy for secure user authentication.
- 🐘 Database: TypeORM integration with PostgreSQL for robust data management.
- 🤖 GraphQL: Apollo Server integration for flexible and efficient API queries.
- ⚡ Optimization: DataLoader integration to efficiently batch and cache queries, preventing N+1 query issues.
- 🧠 Redis Integration:
ioredisfor caching, background job queues, and WebSocket scaling. - 📡 Microservice Ready: Kafka integration for building a distributed, event-driven architecture.
- 🌐 WebSockets: Real-time communication with Socket.io and Redis adapter for horizontal scaling.
- 📬 Mailing Module: Mailer integration for sending transactional emails.
- ☁️ Cloud Storage: Cloudinary module for seamless media uploads and management.
- 💰 SelfManaged Monetization: Payment processing module for handling payments from different providers.
- 📄 PDF Generation: Built-in service using Puppeteer to generate PDFs dynamically.
- 💳 Payment Processing: Module for handling payments.
- 🎯 Background Jobs: BullMQ with Redis backend for handling asynchronous tasks like email queues.
- 🛡️ Security: Essential security features including
Helmetfor header protection and@nestjs/throttlerfor rate limiting. - 📚 API Documentation: Auto-generated API documentation with a beautiful UI powered by Scalar.
- ❤️ Health Checks: Exposed endpoint (
/health) for service health and readiness monitoring using@nestjs/terminus. - 📦 Docker Compose Ready: Includes services for Postgres, Redis, and Kafka for a consistent development environment.
- 📑 Request Logging: Custom interceptor for logging HTTP traffic.
This project follows a modular architecture, with each feature encapsulated in its own module. This promotes separation of concerns, easier maintenance, and scalability. Moreover, the project focused on ease of integration with the provider's system, making it adaptable to various use cases. for more details about the architecture, please refer to the ARCHITECTURE.md file.
src/
├── authentication/ # Handles JWT authentication, guards, and strategies
├── cloudinary/ # Cloudinary integration for file uploads
├── common/ # Shared constants, DTOs, and utilities
├── config/ # Application configuration management
├── email/ # Email sending module and templates
├── global/ # Global filters and interceptors
├── health/ # Health check endpoint
├── insurrance_company/ # Logic for insurance companies
├── integration/ # Third-party API integrations
├── payment/ # Payment processing logic
├── pdf-generator/ # PDF generation service
├── queue/ # BullMQ message queue setup
├── search/ # Elasticsearch integration
├── signature/ # Digital signature handling
├── user/ # User management
├── user_insurrance/ # Manages user insurance policies
├── verification/ # User verification logic
├── withdraw/ # Manages withdrawals
│
├── app.module.ts # Root application module
├── main.ts # Application entry point
└── schema.gql # GraphQL schema
# Clone the repo
git clone https://github.com/Mouloud-Hasrane/caravan.git
cd backend
# Install dependencies
pnpm install
# Setup environment
cp .env.example .env
# Run the app
pnpm run start:dev| Script | Description |
|---|---|
start:dev |
Start in development mode |
start:prod |
Build and start in production |
build |
Build the application |
test |
Run unit tests |
lint |
Lint the codebase |
format |
Format the codebase |
API documentation is auto-generated by Scalar and available at:
http://localhost:3000/api-docs
The compose.yaml file includes services for:
- PostgreSQL
- Redis
- Kafka
To start all services, run:
docker-compose up -dIf you have any questions or suggestions, feel free to reach out via: mouloudhasrane@gmail.com