3.0 KiB

Backend Overview

The Changemaker Lite V2 backend is a dual-API architecture built with TypeScript, providing a robust foundation for campaign management, mapping, and media services.

Architecture

The backend consists of two complementary API servers:

  • Express API (Port 4000) - Main V2 features with Prisma ORM + PostgreSQL
  • Fastify Media API (Port 4100) - Video library with Drizzle ORM (shared database)

Both APIs share a common PostgreSQL 16 database but use different ORM approaches for their specific needs. The Express API handles the majority of business logic, while the Fastify API is optimized for media operations.

Key Components

Modules

Backend modules provide feature-specific functionality across authentication, campaigns, locations, media, and more. Each module follows a consistent pattern with schemas, services, and routes.

Services

Shared services provide cross-cutting concerns like email delivery, geocoding, queue management, and external API integrations.

Middleware

Middleware components handle authentication, authorization, rate limiting, validation, and error handling across all API endpoints.

Utilities

Utility modules provide common functionality for spatial calculations, logging, metrics collection, and data processing.

Technology Stack

  • Runtime: Node.js 20+ with TypeScript 5.x
  • Main Framework: Express.js (TypeScript)
  • Media Framework: Fastify (TypeScript)
  • ORMs:
    • Prisma (main API)
    • Drizzle (media API)
  • Database: PostgreSQL 16
  • Cache/Queue: Redis 7 with BullMQ
  • Validation: Zod schemas
  • Authentication: JWT with bcrypt

API Structure

api/
├── src/
│   ├── server.ts              # Express API entry point (port 4000)
│   ├── media-server.ts        # Fastify media API (port 4100)
│   ├── config/
│   │   └── env.ts             # Environment configuration
│   ├── middleware/            # Auth, RBAC, validation, rate limiting
│   ├── modules/               # Feature modules
│   ├── services/              # Shared services
│   ├── types/                 # TypeScript definitions
│   └── utils/                 # Helper utilities
├── prisma/
│   ├── schema.prisma          # Main database schema (30+ models)
│   └── migrations/            # Database migrations
└── drizzle/                   # Media API schema