Skip to main content

Technical Details

This document provides a comprehensive overview of the technical architecture, implementation details, and design decisions behind the Posthoot backend.

Table of Contents

Architecture Overview

High-Level Architecture

The Posthoot backend follows a layered architecture pattern with clear separation of concerns:

Core Design Principles

  1. Separation of Concerns: Each layer has a specific responsibility
  2. Dependency Inversion: High-level modules don’t depend on low-level modules
  3. Single Responsibility: Each component has one reason to change
  4. Open/Closed Principle: Open for extension, closed for modification
  5. Fail Fast: Validate inputs early and fail gracefully

Technology Stack

Backend Framework

  • Echo v4: High-performance HTTP framework for Go
  • GORM v2: ORM for database operations
  • PostgreSQL: Primary database
  • Redis: Caching and session storage

Key Libraries

Development Tools

  • Swagger/OpenAPI: API documentation
  • Docker: Containerization
  • Make: Build automation
  • GitHub Actions: CI/CD

Database Design

Schema Overview

The database schema is designed for scalability and maintainability:

Indexing Strategy

Data Relationships

Authentication System

JWT Token Structure

Token Lifecycle

Security Measures

  1. Token Expiration: Access tokens expire in 24 hours
  2. Refresh Token Rotation: New refresh token on each refresh
  3. Token Blacklisting: Invalidated tokens stored in Redis
  4. Rate Limiting: Login attempts limited per IP
  5. Password Hashing: Bcrypt with cost factor 12

Permission System

Permission Structure

Permission Hierarchy

Wildcard Permissions

Event Bus System

Event Structure

Event Flow

Event Types

Rate Limiting

Implementation Details

The rate limiting system uses Redis for distributed rate limiting:

Rate Limit Headers

Default Limits

Security Features

Input Validation

SQL Injection Prevention

  • Parameterized Queries: All database queries use prepared statements
  • Input Sanitization: All user inputs are validated and sanitized
  • ORM Protection: GORM automatically escapes SQL values

XSS Prevention

  • Content Security Policy: Strict CSP headers
  • Input Encoding: All user inputs are properly encoded
  • Output Sanitization: HTML content is sanitized before storage

CSRF Protection

Performance Considerations

Database Optimization

  1. Connection Pooling: Configured connection pool for optimal performance
  2. Query Optimization: Use database indexes and optimized queries
  3. Caching Strategy: Redis caching for frequently accessed data
  4. Database Partitioning: Large tables partitioned by date

Caching Strategy

Background Processing

Monitoring and Observability

Logging Strategy

Metrics Collection

Health Checks

Tracing

Deployment Architecture

Production Environment

Scaling Strategy

  1. Horizontal Scaling: Multiple application instances behind load balancer
  2. Database Scaling: Read replicas for read-heavy operations
  3. Cache Scaling: Redis cluster for high availability
  4. Storage Scaling: S3-compatible storage for file storage

Disaster Recovery

  1. Database Backups: Automated daily backups with point-in-time recovery
  2. Application Backups: Configuration and code backups
  3. Monitoring: Comprehensive monitoring and alerting
  4. Failover: Automated failover procedures
This technical architecture provides a solid foundation for building a scalable, secure, and maintainable email campaign management system.