{"id":19356246,"url":"https://github.com/yeboahd24/fido-transaction-api","last_synced_at":"2026-04-09T21:05:02.347Z","repository":{"id":262012033,"uuid":"885979401","full_name":"yeboahd24/fido-transaction-api","owner":"yeboahd24","description":"Fido Backend Engineer Assignment","archived":false,"fork":false,"pushed_at":"2024-11-11T06:55:47.000Z","size":91,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-06T17:47:29.724Z","etag":null,"topics":["docker","docker-compose","dockerfile","fastapi","jwt","jwt-authentication","python3"],"latest_commit_sha":null,"homepage":"https://documenter.getpostman.com/view/14925315/2sAY52cf3d","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yeboahd24.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-09T21:39:33.000Z","updated_at":"2024-11-11T06:55:51.000Z","dependencies_parsed_at":"2025-01-06T17:45:19.857Z","dependency_job_id":"6b1795a8-2bb5-4e20-8d13-f3e84f83d4ad","html_url":"https://github.com/yeboahd24/fido-transaction-api","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"bd9a9fcef7e38f8ab42d8c02eb270febe8251a20"},"previous_names":["yeboahd24/fido-transaction-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeboahd24%2Ffido-transaction-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeboahd24%2Ffido-transaction-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeboahd24%2Ffido-transaction-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeboahd24%2Ffido-transaction-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yeboahd24","download_url":"https://codeload.github.com/yeboahd24/fido-transaction-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240468792,"owners_count":19806249,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","dockerfile","fastapi","jwt","jwt-authentication","python3"],"created_at":"2024-11-10T07:03:41.760Z","updated_at":"2026-04-09T21:05:02.311Z","avatar_url":"https://github.com/yeboahd24.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fido Transaction API\n\nThis is a simple API for managing transactions in a database. It uses FastAPI and PostgreSQL as the database and Redis as the cache. \n\n\nNB: All requests are authenticated using JWT tokens. The API is secured by default. You must register and login to get your token for the subsequence requests.\n\nWhenever you get a 401 error, you must login again to get a new token.\n\n```json\n{\n    \"detail\": \"Could not validate credentials\"\n}\n```\n```\n```\n\n## Prerequisites\n\n- Python 3.12 or higher\n- PostgreSQL 16 or higher\n- Redis\n\n## Installation\n\n1. Clone the repository:\n\n```bash\ngit clone https://github.com/yeboahd24/fido-transaction-api.git\n```\n\n2. Install the required dependencies:\n\n```bash\npip install -r requirements.txt\n```\n\n3. Create a `.env` file in the root directory and add the following environment variables:\n\n```bash\nDB_USER=postgres\nDB_PASSWORD=postgres\nDB_NAME=postgres\nDB_HOST=localhost\nDB_PORT=5432\nREDIS_HOST=localhost\nREDIS_PORT=6379\nENCRYPTION_KEY=your_encryption_key\nJWT_SECRET_KEY=your_jwt_secret_key\nJWT_ALGORITHM=HS256\n```\n\nReplace `your_encryption_key`, `your_jwt_secret_key`, and `your_jwt_algorithm` with your own values.\n\n4. Run the application:\n\n```bash\nuvicorn app.main:app --reload\n```\n\n## Usage\n\nNB: The documentation for this project is also hosted on [Postman](https://documenter.getpostman.com/view/14925315/2sAY52cf3d)\n\n### Registering a user\n\nTo register a new user, send a POST request to the `/auth/register` endpoint with the following JSON payload:\n\n```json\n{\n  \"username\": \"your_username\",\n  \"email\": \"your_email\",\n  \"password\": \"your_password\"\n}\n```\n\n### Logging in\n\nTo log in a user, send a POST request to the `/auth/login` endpoint with the following JSON payload:\n\n```json\n{\n  \"username\": \"your_username\",\n  \"password\": \"your_password\"\n}\n```\n\nThe response will contain the access token and other relevant information.\n\n### Creating a transaction\n\nTo create a new transaction, send a POST request to the `/transactions` endpoint with the following JSON payload:\n\n```json\n{\n  \"full_name\": \"John Doe\",\n  \"transaction_date\": \"2023-01-01\",\n  \"transaction_amount\": 100.0,\n  \"transaction_type\": \"credit\"\n}\n```\n\nThe response will contain the transaction details, including the ID, full name, transaction date, transaction amount, and transaction type.\n\n### Updating a transaction\n\nTo update a transaction, send a PUT request to the `/transactions/{transaction_id}` endpoint with the following JSON payload:\n\n```json\n{\n  \"full_name\": \"Jane Doe\",\n  \"transaction_date\": \"2023-02-01\",\n  \"transaction_amount\": 200.0,\n  \"transaction_type\": \"debit\"\n}\n```\n\nThe response will contain the updated transaction details, including the ID, full name, transaction date, transaction amount, and transaction type.\n\n### Deleting a transaction\n\nTo delete a transaction, send a DELETE request to the `/transactions/{transaction_id}` endpoint.\n\nThe response will contain a success message.\n\n### Getting user analytics\n\nTo get user analytics, send a GET request to the `/analytics` endpoint.\n\nThe response will contain the user's analytics data, including the full name, total transactions, total credit, total debit, average transaction value, and the busiest day.\n\nNB: The analytics data is cached in Redis for improved performance\nAlso analytics can be filtered by date, `GET /analytics/?transaction_date=2024-11-10`\n\n## Docker\n\nTo run the application using Docker, follow these steps:\n\n1. Build the Docker image:\n\n```bash\ndocker-compose build\n```\n\n2. Run the Docker container:\n\n```bash\ndocker-compose up -d\n```\nYou can run the tests with Docker Compose using the command:\n```bash\ndocker-compose up --abort-on-container-exit --exit-code-from test test\n```\n\n## Design Decision\n\n### Context and scope\n\nThis project is a Transaction API built using FastAPI and PostgreSQL,\nwith Redis for caching. The API provides functionality for user authentication,\ntransaction management, and analytics.\nThe system is designed to handle user registration, login, and\nsecure access to transaction-related operations.\nThe API is containerized using Docker for easy deployment and scalability.\n\n\n### Goals and non-goals\n\n#### Goals:\n\n1. Provide secure user authentication using JWT tokens\n\n2. Allow CRUD operations for transactions\n\n3. Offer user analytics based on transaction data\n\n3. Implement caching for improved performance\n\n4. Ensure data encryption for sensitive information\n\n5. Support containerized deployment\n\n#### Non-goals:\n\n1. Implement real-time transaction processing\n\n2. Provide multi-factor authentication\n\n3. Support multiple database backends\n\n4. Implement a front-end interface\n\n\n## Design\n\n#### System-context-diagram\n\n![Sequence diagram](images/sequence.svg)\n\n\n## APIs\n\nThe API exposes the following main endpoints:\n\n### Authentication:\n\n`POST /auth/register`: Register a new user\n\n`POST /auth/login`: Log in a user and receive a JWT token\n\n### Transactions:\n\n`POST /transactions`: Create a new transaction\n\n`PUT /transactions/{transaction_id}`: Update an existing transaction\n\n`DELETE /transactions/{transaction_id}`: Delete a transaction\n\n### Analytics:\n\n`GET /analytics`: Retrieve user analytics data\n\n\n## Data storage\n\n### PostgreSQL:\n\n`Users table`: Stores user information (id, username, email, hashed_password)\n\n`Transactions table`: Stores transaction data (id, user_id, full_name, transaction_date, transaction_amount, transaction_type)\n\n### Redis:\n\nused for caching analytics data with a key format of \"analytics:{user_id}\"\n\n\n## Code and pseudo-code\n\nThe main components of the system are:\n\n1. `AuthService`: Handles user registration and login\n\n2. `TokenService`: Manages JWT token creation and verification\n\n3. `TransactionService`: Manages CRUD operations for transactions\n\n4. `AnalyticsService`: Processes and caches user analytics data\n\n5. `AuthenticateUserMiddleware`: Ensures secure access to protected endpoints\n\n### Key implementation details:\n\n1. Password hashing is used for secure storage of user passwords\n\n2. JWT tokens are used for authentication, with configurable expiration times\n\n3. Redis is used to cache analytics data for improved performance\n\n4. Database queries are performed asynchronously using the databases library\n\n5. Error handling and logging are implemented throughout the application\n\n\n### Degree of constraint\n\nThis project has a moderate degree of constraint. The solution space is defined by the chosen technologies (FastAPI, PostgreSQL, Redis) and the requirements for secure authentication and transaction management. However, there is flexibility in how these components are integrated and how specific features are implemented.\n\n\n### Alternatives considered\n\nUsing SQLAlchemy ORM instead of raw SQL queries:\n\n    Pro: More Pythonic approach to database operations\n\n    Con: Potential performance overhead for simple queries\n\n    Decision: Stick with raw SQL for better performance and control\n\nImplementing WebSocket for real-time updates:\n\n    Pro: Would allow for real-time transaction notifications\n\n    Con: Increases complexity and may not be necessary for the current use case\n\n    Decision: Not implemented to keep the API focused on core functionality\n\nUsing a NoSQL database like MongoDB:\n\n    Pro: More flexible schema for evolving data structures\n\n    Con: Less suitable for structured financial data and complex queries\n\n    Decision: Stick with PostgreSQL for ACID compliance and robust querying capabilities\n\nImplementing rate limiting:\n\n    Pro: Would protect against potential abuse of the API\n\n    Con: Adds complexity and may not be necessary for a small-scale application\n\n    Decision: Consider implementing in the future if needed\n\nUsing OAuth2 for authentication:\n\n    Pro: Allows for third-party authentication providers\n\n    Con: More complex to implement and may be overkill for the current requirements\n\n    Decision: Stick with custom JWT implementation for simplicity and control\n\nThe chosen design provides a good balance between functionality, security, and performance, while leaving room for future enhancements as needed.\n\n\n## Contributing\n\nContributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeboahd24%2Ffido-transaction-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyeboahd24%2Ffido-transaction-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeboahd24%2Ffido-transaction-api/lists"}