Microservices running through containers using a Django backend.
Explanation video: Watch here
Super User:
- Username:
admin - Password:
123456
Normal User:
- Username:
peter - Password:
spiderman
- Ensure you have Docker installed.
- Use
docker-compose upat the root of the project directory. - Access the application at http://127.0.0.1:8000/api/schema/swagger-ui/.
- Ensure you have Python 3 installed.
- Create a virtual environment and activate it:
python3 -m venv virtualenv source virtualenv/bin/activate - Install dependencies:
pip install -r requirements.txt
- Run unit tests for each service:
./stock_service/manage.py test ./api_service/manage.py test
- Access the Swagger UI at http://127.0.0.1:8000/api/schema/swagger-ui/.
- Generate a token at
/api/tokenusing any of the credentials listed above. - Insert the token at the "Authorize" button at the top of the Swagger UI.
- Use the following endpoints:
/stock: Query stock information./history: View your query history./stats: Check the most queried stocks (requires superuser access).
Your access token lasts 5 minutes. Use the refresh token at /api/token/refresh to get a new one.
- PostgreSQL is used due to its popularity. If the
/stockendpoint is expected to be called much more frequently than/historyand/stats, consider using a NoSQL database for faster writes. - Logging to the console is fine for debugging, but in production, use robust monitoring tools.
- User credentials and access tokens should never be hardcoded. This is for illustration purposes only. Use a
.envfile for storing secrets. - Use
autopep8for code style compliance. - I used
pikainstead ofceleryfor simplicity. - I used
drf-spectacularinstead ofdrf-yasgdue to better support for OpenAPI 3.0 and more frequent updates.
