Skip to content

Abdul-Rafy2005/pulseflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”„ PulseFlow

Real-Time Event-Driven Analytics Platform

Java Spring Boot React PostgreSQL Redis RabbitMQ Docker License

Applications send us events. We turn them into real-time analytics.

PulseFlow ingests activity events via REST, processes them asynchronously through RabbitMQ, persists data in PostgreSQL, caches hot statistics in Redis, and streams live updates to a React dashboard over WebSocket β€” all orchestrated with Docker Compose in a single command.

Quick Start Β· Architecture Β· API Reference Β· Contributing


πŸ“‹ Table of Contents


πŸ’‘ Why PulseFlow?

Most backend portfolio projects are simple CRUD applications with a database. PulseFlow goes further β€” it demonstrates production-grade backend engineering patterns that power systems at scale:

Concept How PulseFlow Implements It
Event-Driven Architecture Decoupled producers and consumers via RabbitMQ message broker
Asynchronous Processing POST /events returns 202 Accepted instantly β€” zero synchronous DB writes on the hot path
Caching Strategy Redis as a fast, disposable accelerator; PostgreSQL as the source of truth
Real-Time Delivery WebSocket (STOMP) pushes live updates; automatic REST polling fallback on disconnect
Failure Resilience Dead-letter queues, exponential backoff retries, failed_events table β€” no event is silently lost
Security JWT authentication for admins, API key-based auth for event ingestion, BCrypt password hashing
Containerized Infrastructure Full-stack Docker Compose with health-checked dependencies

✨ Key Features

Backend

  • ⚑ High-throughput event ingestion β€” sub-100ms response via async publish to RabbitMQ
  • πŸ‡ RabbitMQ consumer pipeline β€” idempotent processing with configurable retry policy and dead-letter queue
  • πŸ—„οΈ PostgreSQL persistence β€” durable event storage with JSONB metadata, pagination, and filtering
  • πŸš€ Redis caching layer β€” namespaced counters, sorted sets, and HyperLogLog for real-time analytics
  • πŸ” Dual authentication β€” JWT (HS256) for admin dashboard, API key (X-API-Key) for machine clients
  • πŸ“Š Analytics REST API β€” summary, daily trends, top events, top users, and real-time snapshots
  • πŸ”Œ WebSocket broadcasting β€” STOMP-over-SockJS pushes processed events and stat updates live
  • πŸ“– OpenAPI documentation β€” auto-generated Swagger UI at /swagger-ui.html
  • πŸ›‘οΈ Rate limiting β€” configurable per-key request throttling on the ingestion endpoint
  • πŸ₯ Health & monitoring β€” queue depth, consumer status, Redis health, and audit logging

Frontend

  • πŸ“ˆ Live dashboard β€” real-time counters with animated updates on every processed event
  • πŸ“‰ Interactive charts β€” daily trend line chart and top events bar chart (Recharts)
  • πŸ“‹ Event log β€” paginated, filterable event browser with detail view
  • πŸ”„ Graceful degradation β€” auto-fallback from WebSocket to REST polling with reconnect indicator
  • 🎨 Instrument-panel aesthetic β€” dark theme, JetBrains Mono typography, glassmorphism UI

πŸ— Architecture

flowchart TB
    subgraph Clients
        ClientApp["πŸ–₯️ Client Application"]
    end

    subgraph Ingestion["Ingestion Layer"]
        API["Spring Boot REST API<br/><i>Validates + publishes only</i>"]
    end

    subgraph Messaging["Message Broker"]
        RMQ["RabbitMQ<br/><i>events.queue + DLQ</i>"]
    end

    subgraph Processing["Processing Layer"]
        Consumer["Analytics Consumer<br/><i>Idempotent processing</i>"]
    end

    subgraph Storage["Storage Layer"]
        PG[("PostgreSQL<br/><i>Source of truth</i>")]
        Redis[("Redis<br/><i>Hot cache</i>")]
    end

    subgraph Delivery["Delivery Layer"]
        WS["WebSocket Broadcaster<br/><i>STOMP over SockJS</i>"]
        AnalyticsAPI["Analytics REST API"]
    end

    subgraph Frontend["Frontend"]
        Dashboard["⚑ React Dashboard"]
    end

    ClientApp -->|"POST /events<br/>X-API-Key"| API
    API -->|"publish EventMessage"| RMQ
    RMQ --> Consumer
    Consumer -->|"persist event"| PG
    Consumer -->|"update counters"| Redis
    Consumer -->|"broadcast"| WS
    AnalyticsAPI -->|"read"| PG
    AnalyticsAPI -->|"read cached stats"| Redis
    Dashboard -->|"REST + JWT"| AnalyticsAPI
    Dashboard -->|"subscribe live"| WS

    style Clients fill:#1a1a2e,stroke:#5EEAA0,color:#E8F5E9
    style Ingestion fill:#16213e,stroke:#5EEAA0,color:#E8F5E9
    style Messaging fill:#0f3460,stroke:#FF6600,color:#E8F5E9
    style Processing fill:#16213e,stroke:#5EEAA0,color:#E8F5E9
    style Storage fill:#1a1a2e,stroke:#4169E1,color:#E8F5E9
    style Delivery fill:#16213e,stroke:#61DAFB,color:#E8F5E9
    style Frontend fill:#1a1a2e,stroke:#61DAFB,color:#E8F5E9
Loading

Key Design Decisions

Decision Rationale
Ingestion is publish-only POST /events never touches Postgres or Redis synchronously β€” guarantees sub-100ms latency regardless of downstream load
Single writer principle The RabbitMQ consumer is the sole writer for event data β€” centralizes retry/failure logic and eliminates race conditions
Redis is disposable Every Redis key is reconstructible from Postgres β€” cache failures never cause data loss
WebSocket + polling fallback Dashboard never goes blank β€” automatically switches to 5s REST polling if WebSocket disconnects
Dead-letter queue Failed messages are retried with exponential backoff, then routed to DLQ + failed_events table β€” zero silent data loss

πŸ›  Tech Stack

Layer Technology Purpose
Language Java 21 LTS Modern LTS with virtual threads support
Framework Spring Boot 3.5 Web, Security, Data JPA, AMQP, WebSocket, Validation
Database PostgreSQL 16 Durable event storage with JSONB, indexing, and full-text search
Cache Redis 7 Counters, sorted sets, HyperLogLog for real-time analytics
Message Broker RabbitMQ 3.x Topic exchange, dead-letter queue, management plugin
Frontend React 19 + Vite 8 SPA dashboard with STOMP.js WebSocket client
Charting Recharts 3.9 Interactive line and bar charts
Auth Spring Security + JWT HS256 token-based authentication
API Docs springdoc-openapi 2.8 Auto-generated Swagger UI
Testing JUnit 5 + Testcontainers Integration tests with real Postgres, Redis, and RabbitMQ
Infrastructure Docker Compose Full-stack orchestration with health checks
Reverse Proxy Nginx Frontend static serving + API/WebSocket proxying

πŸš€ Quick Start

Prerequisites

One-Command Launch

# Clone the repository
git clone https://github.com/Abdul-Rafy2005/pulseflow.git
cd pulseflow

# Copy environment config
cp .env.example .env

# Start the full stack (Postgres, Redis, RabbitMQ, Backend, Frontend)
docker compose up -d --build

Access the Stack

Service URL Credentials
πŸ“Š Dashboard http://localhost:3000 Register via UI
πŸ”Œ Backend API http://localhost:8082 JWT / API Key
πŸ“– Swagger UI http://localhost:8082/swagger-ui.html β€”
πŸ‡ RabbitMQ UI http://localhost:15672 guest / guest

Send Test Events

# 1. Register an admin account
curl -X POST http://localhost:8082/auth/register \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","email":"admin@example.com","password":"password123"}'

# 2. Fire 50 sample events (requires Python + requests)
python scratch/send_events.py 50 0.5

Tip: Set BACKEND_URL and API_KEY in scratch/send_events.py if not using default values.


πŸ”§ Local Development

1. Start Infrastructure Only

docker compose up -d postgres redis rabbitmq

2. Run the Backend

cd backend
./mvnw spring-boot:run

The backend starts on port 8080 (or as configured in SERVER_PORT).

3. Run the Frontend

cd frontend
npm install
npm run dev

Dashboard dev server runs at http://localhost:5173 with API proxy to backend.


πŸ“‘ API Reference

Full interactive documentation is available at /swagger-ui.html when the backend is running. See also docs/api.md for the full endpoint reference.

Authentication

Method Endpoint Auth Description
POST /auth/register None Create an admin account
POST /auth/login None Authenticate and receive JWT
GET /auth/profile JWT Get current user profile

Event Ingestion

Method Endpoint Auth Description
POST /events API Key Ingest event β†’ returns 202 Accepted immediately
GET /events JWT Paginated & filterable event list
GET /events/{id} JWT Single event detail

Example β€” Ingest an event:

curl -X POST http://localhost:8082/events \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-api-key" \
  -d '{
    "eventType": "PAGE_VIEW",
    "userId": 42,
    "source": "my-app",
    "metadata": {"page": "/dashboard", "device": "Desktop", "country": "PK"}
  }'

Supported Event Types: LOGIN Β· LOGOUT Β· REGISTER Β· SEARCH Β· PAGE_VIEW Β· BUTTON_CLICK Β· PURCHASE Β· VIDEO_PLAY Β· LIKE Β· COMMENT Β· SHARE Β· DOWNLOAD

Analytics

Method Endpoint Auth Description
GET /analytics/summary JWT Today's aggregated totals (Redis-first)
GET /analytics/daily JWT Time-series data for the last N days
GET /analytics/top-events JWT Ranked event types by frequency
GET /analytics/top-users JWT Most active users ranked
GET /analytics/realtime JWT Live snapshot for dashboard initialization

System Monitoring

Method Endpoint Auth Description
GET /health None Liveness / readiness probe
GET /queue/status JWT Queue depth, consumer count, DLQ size
GET /redis/status JWT Connection health, key count, memory usage

WebSocket

Endpoint Protocol Topics
/ws STOMP over SockJS /topic/events (live event stream) Β· /topic/stats (live counters)

πŸ“ Project Structure

pulseflow/
β”œβ”€β”€ backend/                          # Spring Boot application
β”‚   β”œβ”€β”€ src/main/java/com/pulseflow/backend/
β”‚   β”‚   β”œβ”€β”€ auth/                     # JWT auth, registration, login, role guards
β”‚   β”‚   β”œβ”€β”€ events/                   # Event ingestion, validation, RabbitMQ publishing
β”‚   β”‚   β”œβ”€β”€ queue/                    # RabbitMQ exchange, queue, bindings, DLQ config
β”‚   β”‚   β”œβ”€β”€ analytics/                # Consumer logic, aggregation, Redis R/W, REST APIs
β”‚   β”‚   β”œβ”€β”€ dashboard/                # WebSocket config + broadcast service
β”‚   β”‚   β”œβ”€β”€ monitoring/               # Health checks, queue/Redis status, audit logs
β”‚   β”‚   β”œβ”€β”€ config/                   # Security, CORS, Swagger, exception handling
β”‚   β”‚   └── common/                   # Shared DTOs, utilities, constants
β”‚   β”œβ”€β”€ src/test/                     # Unit + integration tests (Testcontainers)
β”‚   β”œβ”€β”€ Dockerfile                    # Multi-stage build
β”‚   └── pom.xml                       # Maven dependencies
β”‚
β”œβ”€β”€ frontend/                         # React SPA (Vite)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginPage.jsx         # Authentication UI
β”‚   β”‚   β”‚   β”œβ”€β”€ HeroStrip.jsx         # Real-time stat counters
β”‚   β”‚   β”‚   β”œβ”€β”€ DailyTrendChart.jsx   # Line chart β€” events over time
β”‚   β”‚   β”‚   β”œβ”€β”€ TopEventsChart.jsx    # Bar chart β€” event type distribution
β”‚   β”‚   β”‚   β”œβ”€β”€ RecentEvents.jsx      # Live event stream feed
β”‚   β”‚   β”‚   β”œβ”€β”€ EventsLog.jsx         # Paginated event browser
β”‚   β”‚   β”‚   └── ConnectionStatus.jsx  # WebSocket status indicator
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ api.js                # REST client (auth, analytics, events)
β”‚   β”‚   β”‚   └── websocket.js          # STOMP WebSocket client + reconnection
β”‚   β”‚   β”œβ”€β”€ App.jsx                   # Main application with routing
β”‚   β”‚   └── index.css                 # Design system (dark theme, animations)
β”‚   β”œβ”€β”€ nginx.conf                    # Reverse proxy for API + WebSocket
β”‚   └── Dockerfile                    # Production build + Nginx
β”‚
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ PRD.md                        # Product Requirements Document
β”‚   β”œβ”€β”€ api.md                        # Full API specification
β”‚   └── AGENT.md                      # Development guidelines
β”‚
β”œβ”€β”€ scratch/
β”‚   └── send_events.py                # Load testing / demo event generator
β”‚
β”œβ”€β”€ docker-compose.yml                # Full-stack orchestration
β”œβ”€β”€ .env.example                      # Environment variable template
└── .gitignore

βš™οΈ Environment Variables

Copy .env.example to .env before running. Never commit .env to version control.

Variable Required Default Description
JWT_SECRET βœ… β€” HS256 signing key (β‰₯32 bytes)
EVENTS_API_KEY βœ… β€” Required X-API-Key header for event ingestion
SPRING_DATASOURCE_URL βœ… jdbc:postgresql://localhost:5432/pulseflow PostgreSQL connection string
SPRING_DATASOURCE_USERNAME βœ… pulseflow Database user
SPRING_DATASOURCE_PASSWORD βœ… pulseflow Database password
SPRING_RABBITMQ_HOST βœ… localhost RabbitMQ hostname
SPRING_DATA_REDIS_HOST βœ… localhost Redis hostname
EVENTS_RATE_LIMIT_MAX ❌ 100 Max ingestion requests per window
EVENTS_RATE_LIMIT_WINDOW_SECONDS ❌ 60 Rate limit window duration
JWT_EXPIRATION ❌ PT24H Token expiration (ISO 8601 duration)
SERVER_PORT ❌ 8080 Backend server port

πŸ§ͺ Testing

cd backend
./mvnw test
  • Unit tests β€” service layer logic, validation, DTOs
  • Integration tests β€” full ingest β†’ queue β†’ consume β†’ persist pipeline using Testcontainers (Docker required)

🚒 Deployment

Docker Compose (Included)

docker compose up -d --build

Brings up the entire stack with health-checked dependencies. Change JWT_SECRET and EVENTS_API_KEY before any non-local deployment.

Backend Standalone

Build with backend/Dockerfile and point environment variables at your managed Postgres, Redis, and RabbitMQ instances.

Frontend Standalone

Build with frontend/Dockerfile β€” serves static assets via Nginx and proxies /api and /ws to the backend service.

Production Checklist

  • Set strong, unique values for JWT_SECRET and EVENTS_API_KEY
  • Restrict RabbitMQ management UI (port 15672) access
  • Enable TLS/HTTPS termination
  • Configure log aggregation for structured JSON logs
  • Set up database backups for PostgreSQL

πŸ—Ί Roadmap

  • Multi-tenant support β€” isolated analytics per client organization
  • Anomaly detection consumer β€” flag unusual event patterns
  • Alerting system β€” Slack/email notifications on queue backlog or anomalies
  • Event replay endpoint β€” manually replay events from the dead-letter queue
  • Grafana integration β€” metrics dashboards and alerting
  • Horizontal scaling β€” Kubernetes manifests for production deployments

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is open source and available under the MIT License.


Built by Abdul Rafy

If this project helped you or you found it interesting, please consider giving it a ⭐

About

A backend platform for collecting, processing, and monitoring application events at scale, providing real-time visibility into user activity, system behavior, and operational performance through an event-driven processing pipeline.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors