FakeAPI is a simple FastAPI project that manages users, transactions, and campaigns, storing everything in a JSON file.
It also includes a pipeline to generate CSV reports, concurrency-safe file handling, and both unit and integration tests.
This project uses some classic design patterns to keep the code clean and maintainable, such as the Repository Pattern (for data access) and the Template Method Pattern (for the reporting pipeline).
- REST API for users, transactions, and campaigns
- Data stored in
app/data/data.json - Add users via
POST /user - Generate analytical CSV reports with
/generate_reports - Concurrency-safe file writes (using filelock)
- Automated tests (unit and integration)
- Clean architecture with Repository and Template Method patterns
git clone https://github.com/Bonny94ITA/FakeAPI
cd FakeAPI
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtuvicorn app.main:app --reloadSwagger UI Docs: http://127.0.0.1:8000/docs
Build the image:
docker build -t fake-api .Run the container:
docker run -p 8000:8000 fake-apiTo persist data outside the container:
docker run -p 8000:8000 -v $(pwd)/app/data:/app/app/data fakeapiGET /users— List usersPOST /user— Add a userGET /transactions— List transactionsGET /campaigns— List campaignsPOST /generate_reports— Generate CSV reports
After calling /generate_reports you’ll find:
reports/user_campaign_report.csvreports/campaign_revenue_report.csv
Run all tests:
pytestIntegration tests for concurrency:
pytest tests/integration/test_concurrent_post.py
pytest tests/integration/test_concurrent_reports.py- File writes are concurrency-safe thanks to filelock.
- Data validation is handled by Pydantic.
- The codebase uses the Repository and Template Method patterns for clarity and extensibility.
- Note: The
emailfield for users acceptsnullvalues, but if an email is provided and it is not valid, the API will return a validation error.