A comprehensive stock trading web application built with React, Spring Boot, and MongoDB. This application allows users to browse, buy, and sell stocks with real-time portfolio management.
- User Authentication: Secure user registration and login with JWT tokens
- Stock Browsing: View all available stocks with real-time price information
- Stock Search: Search stocks by symbol or company name
- Trading: Buy and sell stocks with real-time balance updates
- Portfolio Management: Track holdings, gains/losses, and transaction history
- Responsive Design: Mobile-friendly interface
- Dockerized: Easy deployment with Docker Compose
- Spring Boot 3.2.0 - Java web framework
- Spring Security - Authentication and authorization
- Spring Data MongoDB - Database integration
- JWT - Token-based authentication
- Maven - Dependency management
- React 18 - Frontend framework
- React Router - Client-side routing
- Axios - HTTP client
- Modern CSS - Responsive styling
- MongoDB 7.0 - Document database
- Docker - Containerization
- Docker Compose - Multi-container orchestration
Stock-view/
├── backend/ # Spring Boot backend
│ ├── src/main/java/com/stocktrading/
│ │ ├── controller/ # REST controllers
│ │ ├── model/ # Data models
│ │ ├── repository/ # Data repositories
│ │ ├── security/ # Security configuration
│ │ ├── dto/ # Data transfer objects
│ │ └── config/ # Configuration classes
│ ├── src/main/resources/
│ │ ├── application.yml # Application configuration
│ │ └── init-mongo.js # MongoDB initialization script
│ ├── Dockerfile
│ └── pom.xml
├── frontend/ # React frontend
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── pages/ # Page components
│ │ ├── services/ # API services
│ │ ├── contexts/ # React contexts
│ │ └── App.js # Main app component
│ ├── public/
│ ├── Dockerfile
│ └── package.json
└── docker-compose.yml
- Docker and Docker Compose
- Java 17+ (for local development)
- Node.js 16+ (for local development)
-
Clone the repository
git clone <repository-url> cd Stock-view
-
Build and run with Docker Compose
docker-compose up --build
-
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8080/api
- MongoDB: localhost:27017
-
Navigate to the backend directory
cd backend -
Build the application
mvn clean package
-
Run the application
java -jar target/stock-trading-backend-1.0.0.jar
-
Navigate to the frontend directory
cd frontend -
Install dependencies
npm install
-
Start the development server
npm start
- Install and run MongoDB locally
- The application will automatically create the database and sample data
POST /api/auth/signin- User loginPOST /api/auth/signup- User registration
GET /api/stocks- Get all stocksGET /api/stocks/{symbol}- Get stock by symbolGET /api/stocks/search?query={query}- Search stocksGET /api/stocks/sector/{sector}- Get stocks by sector
POST /api/trading/buy- Buy stocksPOST /api/trading/sell- Sell stocks
GET /api/portfolio- Get user portfolioGET /api/portfolio/transactions- Get transaction historyGET /api/portfolio/balance- Get user balance
The application comes with pre-loaded sample stocks:
- AAPL - Apple Inc.
- GOOGL - Alphabet Inc.
- MSFT - Microsoft Corporation
- TSLA - Tesla Inc.
- AMZN - Amazon.com Inc.
Each user starts with a $10,000 balance for trading.
The backend can be configured via application.yml:
- Database connection settings
- JWT secret and expiration
- CORS settings
- Server port
Environment variables for the frontend:
REACT_APP_API_URL- Backend API URL (default: http://localhost:8080/api)
- MongoDB: Database server with persistent volume
- Backend: Spring Boot application
- Frontend: React application served by Node.js
mongodb_data: Persistent MongoDB data storage
stock-network: Internal network for service communication
- JWT-based authentication
- Password encryption with BCrypt
- CORS configuration for cross-origin requests
- Protected routes for authenticated users only
- Uses Spring Boot 3.2.0 with Java 17
- MongoDB integration with Spring Data
- JWT token authentication
- RESTful API design
- Comprehensive error handling
- React 18 with modern hooks
- Context API for state management
- Responsive design with CSS Grid/Flexbox
- Protected routes with authentication
- Real-time balance updates
# Build and start all services
docker-compose up --build
# Run in detached mode
docker-compose up -d
# Stop all services
docker-compose down
# Remove volumes (reset database)
docker-compose down -v- Deploy MongoDB instance
- Build and deploy Spring Boot backend
- Build and deploy React frontend
- Configure environment variables
- Port conflicts: Ensure ports 3000, 8080, and 27017 are available
- Database connection: Check MongoDB is running and accessible
- CORS issues: Verify CORS configuration in backend
- Authentication: Ensure JWT secret is properly configured
# View logs for all services
docker-compose logs
# View logs for specific service
docker-compose logs backend
docker-compose logs frontend
docker-compose logs mongodb- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
For support and questions, please open an issue in the repository.