A microservice for managing stock transactions and portfolios.
- Transaction management
- Portfolio tracking
- Message processing with Apache Kafka
- Temporal workflows
- Python 3.8+
- PostgreSQL
- Apache Kafka
- Temporal
- Clone the repository:
git clone https://github.com/yourusername/stock-service.git
cd stock-service- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up the database:
# Create a PostgreSQL database named 'stock_service'
createdb stock_service- Configure environment variables:
# Copy example .env file
cp .env.example .env
# Edit .env file with your settings- Start Kafka:
# Start Zookeeper
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties
# Start Kafka
kafka-server-start /usr/local/etc/kafka/server.properties- Start Temporal:
temporal server start-dev- Start the API server:
uvicorn src.entrypoints.api:app --reload- Start the message consumer:
python -m src.entrypoints.consumer- Start the workflow worker:
python -m src.entrypoints.workflowThe service is configured using environment variables. You can set them in the .env file:
DB_HOST: PostgreSQL host (default: localhost)DB_PORT: PostgreSQL port (default: 5432)DB_NAME: Database name (default: stock_service)DB_USER: Database user (default: postgres)DB_PASSWORD: Database password (default: postgres)
KAFKA_BOOTSTRAP_SERVERS: Kafka bootstrap servers (default: localhost:9092)KAFKA_CONSUMER_GROUP: Consumer group ID (default: stock_service)KAFKA_TRANSACTIONS_TOPIC: Topic for transaction messages (default: transactions)
TEMPORAL_HOST: Temporal server host (default: localhost:7233)TEMPORAL_TASK_QUEUE: Task queue name (default: transactions)
Once the service is running, you can access:
- Swagger UI: http://localhost:8000/api/docs
- ReDoc: http://localhost:8000/api/redoc
src/
├── domain/ # Domain models and interfaces
├── usecases/ # Application use cases
├── infrastructure/ # Implementation details
│ ├── config/ # Configuration
│ ├── messaging/ # Kafka messaging
│ ├── repositories/# Repository implementations
│ └── workflow/ # Temporal workflows
└── entrypoints/ # API and worker entrypoints
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.