Skip to content

Prypiatos/E3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Energy Monitoring System

Real-time energy meter data streaming using Kafka, Go backend, and WebSockets.

Prerequisites

  • Go 1.18 or later
  • Docker and Docker Compose
  • Python 3.7 or later
  • A terminal/command prompt

Quick Start

1. Clone and Set Up Environment

# Clone the repository (if not already cloned)
git clone git@github.com:Prypiatos/E3.git
cd E3

2. Configure Environment Variables

# Copy the test environment file
cp .env-test .env

# Or manually create .env in the project root with these variables:
# BOOTSTRAP_SERVERS=localhost:9092
# TOPIC_NAME=energy-readings
# CONSUMER_GROUP_ID=energy-consumer-group

3. Start Kafka (Docker)

cd apps/backend
docker compose up -d

This starts Kafka broker on localhost:9092

Wait 10-15 seconds for Kafka to fully initialize before proceeding.

4. Build and Start Backend

In a new terminal:

cd apps/backend

# Install Go dependencies
go mod tidy

# Build the backend server
go build -o build/main main.go

# Run the backend server
./build/main

The server will start on http://localhost:8080 and begin listening for Kafka messages.

5. Build and Start Data Producer (in a new terminal)

cd apps/backend

# Build the producer
go build -o build/producer cmd/producer.go

# Run the producer to send test data
./build/producer

The producer will send energy meter readings to Kafka every second.

6. Start Frontend (in a new terminal)

cd apps/frontend

# Start an HTTP server
python -m http.server 8000

The frontend will be available at http://localhost:8000.

7. View the Application

  1. Open your browser and go to http://localhost:8000
  2. Open Developer Tools (F12 or Ctrl+Shift+I)
  3. Go to the Console tab
  4. You should see energy readings streaming in real-time as JSON objects

Stopping the Application

Stop Backend and Producer

Press Ctrl+C in the terminals running the backend and producer.

Stop Frontend

Press Ctrl+C in the terminal running the HTTP server.

Stop Kafka

cd apps/backend
docker compose down

Architecture

  • Backend (apps/backend/main.go): WebSocket server consuming from Kafka
  • Producer (apps/backend/cmd/json_producer.go): Generates test energy meter data
  • Frontend (apps/frontend/index.html): Connects to backend WebSocket and displays data
  • Kafka: Message broker for energy readings

Port Reference

  • Backend WebSocket: localhost:8080/ws
  • Frontend HTTP: localhost:8000
  • Kafka Broker: localhost:9092

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors