Loading repository data…
Loading repository data…
rishabh30 / repository
A boilerplate for a real-time user activity monitoring system built with Python, Kafka, and PostgreSQL. This project provides RESTful APIs for user management and tracks user activities through Kafka, processing and logging them into a database. Ideal for developers looking to implement scalable, real-time activity tracking in their applications.
A boilerplate for a real-time user activity monitoring system built with Python, Kafka, and PostgreSQL. This project provides RESTful APIs for user management and tracks user activities through Kafka, processing and logging them into a PostgreSQL database. Ideal for developers looking to implement scalable, real-time activity tracking in their applications.
User Management:
Activity Tracking:
activity_tracking topic and logs them into the databaseThe system consists of the following components:
activity_tracking Kafka topic, processes the data, and inserts it into the activity table.user and activity, for storing user information and their activities respectively.Create a New User
POST /user/v1/create{
"name": "John Doe",
"mobile": "1234567890",
"email": "john.doe@example.com"
}
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"message": "User created successfully"
}
Get Users List
GET /user/v1/list[
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "John Doe",
"mobile": "1234567890",
"email": "john.doe@example.com",
"created_at": "2024-09-01T12:34:56Z",
"updated_at": "2024-09-01T12:34:56Z"
},
{
"id": "7d5b9d0a-1f2e-4c8b-9bd7-3e3f69573b90",
"name": "Jane Smith",
"mobile": "9876543210",
"email": "jane.smith@example.com",
"created_at": "2024-09-02T08:15:30Z",
"updated_at": "2024-09-02T08:15:30Z"
}
]
Insert Activity
POST /activity/v1/insert{
"name": "User Login",
"description": "User logged in successfully"
}
Insert Activity (via Kafka)
activity_tracking topic, processes incoming messages, and logs the activity into the activity table.{
"name": "User Login",
"description": "User logged in successfully"
}
activity table with the provided name and description.user Table| Column | Type | Description |
|---|---|---|
id | UUID | Primary Key, Unique Identifier for the user |
name | String | Name of the user, cannot be null |
mobile | String | Mobile number of the user, can be null |
email | String | Email of the user, must be unique, can be null |
created_at | DateTime | Timestamp of when the user was created |
updated_at | DateTime | Timestamp of the last update to the user record |
activity Table| Column | Type | Description |
|---|---|---|
id | UUID | Primary Key, Unique Identifier for the activity |
name | String | Name of the activity, cannot be null |
description | String | Description of the activity, can be null |
created_at | DateTime | Timestamp of when the activity was created |
updated_at | DateTime | Timestamp of the last update to the activity record |
Clone the repository:
git clone https://github.com/rishabh30/kafka-activity-tracker.git
cd kafka-activity-tracker
Install dependencies: pip install -r requirements.txt
Set up the database: - Start a PostgreSQL database with the following environment variables:
Configure Kafka:
Configure environment variables:
Start the API Server:
You can also produce messages to the activity_tracking Kafka topic to simulate activity insertion.