Skip to content
eng-muhammad-hamzaPublic

About

Microservices-based social platform with Next.js 15, NestJS core, Socket.IO realtime, FastAPI recommendation engine, and Flask admin.

Topics

Resources

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

FLUX

License: MIT Next.js React TypeScript NestJS Express FastAPI Python PostgreSQL Redis Tailwind CSS Docker Kubernetes Terraform

A microservices-based social platform with a Next.js web client, a NestJS core API, a Socket.IO realtime server, a FastAPI analytics and recommendation service, and a Flask admin panel.

Architecture

The system is split into specialized services communicating over REST, WebSockets, and Redis pub/sub.

graph TD
    Client[Client App / Web] --> Ingress[Nginx Ingress / Gateway]
    
    Ingress --> Web[Web App - Next.js 15]
    Ingress --> Core[Core Service - NestJS]
    Ingress --> Realtime[Realtime Service - Express / Socket.io]
    Ingress --> Analytics[Analytics Service - FastAPI]
    Ingress --> Admin[Admin Service - Flask]
    
    Core --> DB_PG[(PostgreSQL Core)]
    Core --> Redis[(Redis Cache / Broker)]
    Core --> S3[Object Storage / Cloudinary]
    
    Realtime --> Redis
    Realtime --> DB_PG
    
    Analytics --> DB_PG_Analytic[(PostgreSQL Analytics)]
    
    Admin --> DB_PG
    Admin --> DB_PG_Analytic
Loading

Tech Stack

Component Technology Description
Frontend Next.js 15, React 19, Tailwind CSS 4 App Router, SSR, responsive UI, dark/light themes
Auth Clerk Authentication, session management, webhooks
Core API NestJS (TypeScript) User accounts, feed generation, posts, follows, comments, search
Realtime Express + Socket.IO Direct messaging, live notification delivery, online presence
Analytics FastAPI (Python) Metric collection, hashtag trends, recommendation scoring
Admin Flask (Python) Moderation queues, audit logs, GDPR compliance
Database PostgreSQL 16 + Prisma Relational data models, migrations, seeds
Cache & Broker Redis 7 Caching, session states, pub/sub communication
Media Storage Cloudinary / S3 Image and video uploads, asset optimization
Gateway Nginx Reverse proxy, path routing, rate limiting
Observability Prometheus + Grafana + Loki Metrics dashboards, log aggregation
IaC Terraform, Kubernetes, Helm AWS topology and Kubernetes cluster resources
CI/CD GitHub Actions Workflows for build checks, linting, and tests

Quick Start

Prerequisites

  • Node.js 20+ and pnpm 9+
  • Python 3.12+
  • Docker and Docker Compose

Local Setup via Docker Compose

  1. Clone the repository:

    git clone https://github.com/eng-muhammad-hamza/next-flux.git
    cd next-flux
  2. Create the environment configuration:

    cp .env.example .env

    Fill in your Clerk credentials, database passwords, and third-party API keys in .env.

  3. Launch the container stack:

    docker compose up -d
  4. Service endpoints:

    • Web application: http://localhost:3000
    • Core API: http://localhost:4000
    • Realtime service: http://localhost:4001
    • Analytics service: http://localhost:4002
    • Admin service: http://localhost:4003

Repository Structure

next-flux/
├── apps/
│   └── web/                     # Next.js 15 web client
├── services/
│   ├── core/                    # NestJS service (users, posts, feed, notifications)
│   ├── realtime/                # Express & Socket.IO service (messaging, presence)
│   ├── analytics/               # FastAPI service (recommendation scoring, trends)
│   └── admin/                   # Flask service (moderation, audit logs, GDPR)
├── packages/
│   ├── database/                # Prisma schema, migrations, seed scripts
│   └── shared/                  # Common TypeScript interfaces and DTOs
├── gateway/                     # Nginx reverse proxy configuration
├── infrastructure/
│   ├── terraform/aws/           # AWS infrastructure (VPC, ECS, RDS, Redis, S3)
│   ├── terraform/kubernetes/    # Terraform Kubernetes provider setup
│   ├── kubernetes/              # Deployments, services, HPA, network policies
│   ├── helm/flux/               # Helm charts for staging and production
│   └── monitoring/              # Prometheus configs, Grafana dashboards, Loki
├── .github/workflows/           # CI/CD automation pipelines
├── api-collections/             # API request examples and curl commands
├── docs/                        # Architecture, API specifications, and runbooks
└── docker-compose.yml           # Local multi-service orchestration

Running Services Individually

For active service development without full containerization:

# Core service (NestJS)
cd services/core
pnpm install
pnpm run start:dev

# Realtime service (Express / Socket.IO)
cd services/realtime
pnpm install
pnpm run dev

# Analytics service (FastAPI)
cd services/analytics
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --reload --port 4002

# Admin service (Flask)
cd services/admin
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt
flask run --port 4003 --debug

# Web application (Next.js)
cd apps/web
pnpm install
pnpm run dev

Recommendation Service

The analytics microservice provides a multi-stage post recommendation pipeline:

  1. Candidate Selection & Graph Matching: Hashtag overlap via Jaccard similarity and follow-graph proximity.
  2. Engagement & Recency Decay: Time-decay scoring based on likes, comments, and reposts.
  3. Semantic Scoring: Optional LLM re-ranking through OpenRouter (OPENROUTER_API_KEY). Falls back to algorithmic score weights when the key is omitted.
  4. Caching: In-memory TTL layer for frequently queried feeds.

Run the engine tests:

pytest services/analytics/tests/test_recommendation_engine.py -v

Deployment

Kubernetes via Helm

cd infrastructure/helm
helm install flux ./flux -n flux -f flux/values-dev.yaml

AWS via Terraform

cd infrastructure/terraform/aws
terraform init
terraform apply -var-file=environments/dev.tfvars

Refer to docs/deployment-runbook.md for production deployment procedures and rollback steps.

Monitoring

  • Grafana: http://localhost:3001 (default credentials: admin / admin)
  • Prometheus: http://localhost:9090
  • Loki: http://localhost:3100

Documentation

License

This project is licensed under the MIT License.

About

Microservices-based social platform with Next.js 15, NestJS core, Socket.IO realtime, FastAPI recommendation engine, and Flask admin.

Topics

Resources

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages