A NestJS-based stock trading application with PostgreSQL database and Redis for background job processing.
- Node.js 20.19.0 (specified in package.json engines)
- Docker and Docker Compose
- PostgreSQL (if running without Docker)
- Redis (if running without Docker)
- SMTP email service (if running without Docker)
Install the required dependencies:
# Install dependencies
npm install
# Generate Prisma client
npx prisma generateA Postman collection is available in the root directory:
- File:
fusefinance.postman_collection.json - Contains pre-configured requests for all endpoints
- Includes example request bodies and environment variables
- Import into Postman to quickly start testing the API
The API is available at https://stock-trading.ryttuo.com with the following endpoints:
-
List Available Stocks
GET https://stock-trading.ryttuo.com/api/v1/stocks -
Execute Stock Purchase
POST https://stock-trading.ryttuo.com/api/v1/stocks/buy{ "price": 0.2475, "quantity": 200, "symbol": "PFE" } -
Get User Portfolios
GET https://stock-trading.ryttuo.com/api/v1/users/portfolios -
View Email Reports
https://maildev.ryttuo.comAccess the MailDev interface to view all email reports sent by the application, including daily portfolio reports and transaction notifications.
These endpoints are also included in the Postman collection for easy testing.
The application provides the following main endpoints:
-
List Available Stocks
- Endpoint:
GET /api/v1/stocks - Description: Retrieves a list of all available stocks for trading
- Response: Array of stock objects with current prices
- Endpoint:
-
Execute Stock Purchase
- Endpoint:
POST /api/v1/stocks/buy - Description: Executes a stock purchase transaction
- Request Body: Stock symbol and quantity and price
{ "price": 0.2475, "quantity": 200, "symbol": "PFE" }- Response: Transaction details and updated portfolio
- Endpoint:
-
Get User Portfolios
- Endpoint:
GET /api/v1/users/portfolios - Description: Retrieves the current user's stock portfolio
- Response: Portfolio details including owned stocks and their values
- Endpoint:
The application generates daily reports via CRON jobs:
- Schedule is configured in
.envfile - Reports are sent via email
- View sent emails in MailDev interface at
http://localhost:1080
-
Copy the example environment file:
cp .env.example .env
-
Update the
.envfile with your specific values. The file includes configurations for:- Application settings (NODE_ENV, PORT)
- Database connection (DATABASE_URL)
- Redis configuration (REDIS_HOST, REDIS_PORT)
- SMTP settings for email notifications
- Cron job settings
For production, create a
.env.prodfile with production-specific values following the same structure.
Run all services (PostgreSQL, Redis, MailDev, and the stock-trading-app) using Docker:
# Development
npm run docker:dev
# Production
npm run docker:prod
# Stop containers
npm run docker:down
# Stop containers and remove volumes
npm run docker:down:volumesRun infrastructure services (PostgreSQL, Redis, MailDev) in Docker while running the application locally:
-
Start infrastructure services:
# Start PostgreSQL, Redis, and MailDev docker compose up postgres redis maildev -
Stop the app service to run it locally:
# Stop the app service while keeping other services running docker compose stop app -
Run the application locally using one of these methods:
# Standard start npm run start # Development mode with hot-reload npm run start:dev # Debug mode to use breakpoints npm run start:debug
- Start infrastructure services as described in Option 2
- Open VS Code
- Select
💰 appconfiguration to running locally
The launch configuration is already set up in .vscode/launch.json with the following settings:
- Attaches to the Node.js process
- Enables source maps
- Configures breakpoints
- Sets up environment variables
If you prefer not to use Docker at all:
- Install PostgreSQL locally
- Install Redis locally
- Update
.envwith local connection details - Run the application:
npm run start:dev
The application includes MailDev for email testing in development:
- Access the MailDev web interface at
http://localhost:1080 - All emails sent by the application will be captured and displayed here
- You can view email content, headers, and attachments
- No emails are actually sent to real recipients in development
The application automatically handles database setup in Docker environments. For local development without Docker, follow these steps:
When using Docker, the database is automatically:
- Created and migrated using
prisma migrate deploy - Seeded with initial data using
prisma db seed
No manual migration steps are needed.
If running without Docker, you'll need to:
-
Initial Setup
# Create database and apply migrations npx prisma migrate dev -
After Schema Changes
# Generate and apply new migrations npx prisma migrate dev --name <descriptive-name>
- Always backup your database before running migrations in production
- Never run
migrate resetin production as it will delete all data - Use descriptive names for migrations (e.g.,
add-user-role) - Review generated migrations before applying them
# Unit tests
npm run test
# E2E tests
npm run test:e2e
# Test coverage
npm run test:cov- Ensure Redis is running:
docker ps | grep redis - Check Redis connection:
redis-cli ping - Verify Redis port in
.envmatches Docker port
- Ensure PostgreSQL is running:
docker ps | grep postgres - Check database connection:
psql -h localhost -U postgres -d stock_trading - Verify DATABASE_URL in
.env
- Check if port 3000 is available:
lsof -i :3000 - Check if PostgreSQL port 5432 is available:
lsof -i :5432 - Check if Redis port 6379 is available:
lsof -i :6379 - Check if MailDev port 1080 is available:
lsof -i :1080 - Change PORT in
.envif needed - Update docker compose.yml port mappings if conflicts exist
- Ensure MailDev is running:
docker ps | grep maildev - Access MailDev interface at
http://localhost:1080 - Verify SMTP settings in
.envmatch MailDev configuration - Check application logs for email sending errors
-
Start infrastructure services:
docker compose up postgres redis maildev
-
Run the application in development mode:
npm run start:dev
-
Make changes to the code
-
Tests will run automatically in watch mode
-
Use VS Code debugging for step-by-step debugging