Skip to content

2KRIKA Technical Documentation

Welcome to the comprehensive technical documentation for the 2KRIKA backend service - a marketplace platform connecting service providers with customers.

๐Ÿš€ Quick Start

New to 2KRIKA? Start here:

  1. Installation - Set up your development environment
  2. Configuration - Configure databases and services
  3. Running the App - Start developing
# Quick setup
git clone https://github.com/OryStack/2-krika-backend.git
cd 2-krika-backend
pnpm install
cp .env.example .env
pnpm dev:migrate
pnpm dev

๐Ÿ“š What is 2KRIKA?

2KRIKA is a marketplace platform built with Clean Architecture principles, enabling:

  • ๐Ÿ›๏ธ Service Catalog - Browse and purchase services
  • ๐Ÿ‘ค User Management - Authentication, roles, and KYC verification
  • ๐Ÿ“ฆ Order Management - Complete order lifecycle with state machines
  • ๐Ÿ’ณ Payment Processing - Integrated payment gateway (Paystack)
  • ๐Ÿ’ฐ Account System - Balance management, withdrawals, and refunds
  • ๐Ÿ’ฌ Real-time Chat - WebSocket-based messaging
  • ๐Ÿ“ง Notifications - Email and in-app notifications
  • ๐Ÿ“ File Storage - Upload management with cloud-ready abstraction

๐Ÿ—๏ธ Architecture

2KRIKA follows Clean Architecture with four distinct layers:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              Web Layer (NestJS)             โ”‚
โ”‚  Controllers, Guards, Filters, WebSockets  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚          Application Layer                  โ”‚
โ”‚      Use Cases, Validators, DTOs            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚            Domain Layer                     โ”‚
โ”‚   Entities, Value Objects, Repositories     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ†‘
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           Adapters Layer                    โ”‚
โ”‚  SQL, MongoDB, Redis, Email, Storage        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Learn more: Architecture Overview

๐Ÿ› ๏ธ Technology Stack

Backend Framework

  • NestJS - Progressive Node.js framework
  • TypeScript - Type-safe development
  • Express - HTTP server

Databases

  • PostgreSQL (via Sequelize) - Primary relational database
  • MongoDB (via Mongoose) - Chat messages
  • Redis - Caching (stats, permissions, ...)

Key Libraries

  • XState - State machine for order workflow
  • Zod - Schema validation
  • JWT - Authentication tokens
  • Decimal.js - Precise decimal arithmetic
  • Paystack - Payment gateway
  • Nodemailer - Email notifications
  • Socket.IO - WebSocket communication

View complete stack: Technology Stack

๐Ÿ“– Documentation Structure

Getting Started

Learn how to set up and run the application: - Installation - Configuration - Environment Variables - Running the App

Architecture

Understand the system design: - Overview - Clean Architecture - Project Structure - Design Principles - Technology Stack

Core Concepts

Master the fundamental patterns: - Domain Layer - Entities and business logic - Application Layer - Use cases and orchestration - Adapters Layer - External integrations - Web Layer - HTTP and WebSocket APIs - Dependency Injection - IoC container

Domain Modules

Explore business domains: - Users - Authentication, roles, KYC - Services - Catalog, categories, options - Orders - Workflow, states, events - Payments - Gateway integration - Accounts - Balance management - Transactions - Audit trail

Features

Deep dive into functionality: - Authentication - JWT tokens and guards - User Management - CRUD operations - KYC Verification - Identity validation - Service Catalog - Browse and search - Order Workflow - State machines - Payment Processing - Paystack integration - Chat System - Real-time messaging - Notifications - Email system - File Uploads - Storage abstraction

Infrastructure

Configure technical infrastructure: - Database - PostgreSQL, MongoDB setup - Caching - Redis strategies - Storage - File management - Logging - File-based logging - Email - Nodemailer configuration

Development

Best practices for developers: - Coding Standards - TypeScript, ESLint, conventions - Testing - Jest, factories, coverage - Migrations - Database schema changes - Debugging - VS Code, logs, troubleshooting - Contributing - Git workflow, PR process

Deployment

Production deployment guide: - Deployment - Docker, Docker Swarm, best practices

๐Ÿ”‘ Key Features

Clean Architecture Benefits

  • Testability - Easy unit and integration testing
  • Maintainability - Clear separation of concerns
  • Flexibility - Easy to swap implementations
  • Scalability - Independent layer scaling

Order Workflow (XState)

State-driven order management:

pending โ†’ paid โ†’ in_progress โ†’ delivered โ†’ completed
        โ†“
    cancelled

Payment Integration

  • Paystack gateway abstraction
  • Payment initialization and verification
  • Webhook handling for async updates
  • Transaction tracking

Real-time Features

  • WebSocket chat system
  • Live order status updates
  • Instant notifications

๐Ÿงช Testing

Comprehensive test coverage: - Unit Tests - Domain entities and value objects - Integration Tests - Use cases and repositories - Test Factories - Consistent test data generation - Mock Implementations - Isolated testing

# Run all tests
pnpm test

# Run with coverage
pnpm test:ci

Learn more: Testing Guide

๐Ÿšข Deployment

Production-ready with Docker:

# Build image
docker build -t 2krika-backend:latest .

# Deploy with Docker Swarm
docker stack deploy -c docker-stack.yml 2krika

Features: - Multi-stage Docker builds - Docker Swarm orchestration - Rolling updates - Health checks - Prometheus monitoring - Grafana dashboards

Learn more: Deployment Guide

๐Ÿ“Š Project Status

  • Language: TypeScript
  • Framework: NestJS
  • Architecture: Clean Architecture
  • Test Coverage: ~70%
  • Documentation: Complete

๐Ÿค Contributing

We welcome contributions! Please read our Contributing Guide to get started.

Quick Contribution Steps

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Make changes following Coding Standards
  4. Write tests for new features
  5. Ensure all tests pass: pnpm test
  6. Commit using Conventional Commits
  7. Push and create Pull Request

Support

  • Documentation - Browse this site for detailed guides
  • API Documentation - Access Swagger at /api/docs when running the app

๐Ÿ”— Resources

External Documentation


Ready to start? Head to the Installation Guide to set up your development environment!