7.2 KiB
Walkthrough - Coffee-Control-Center Implementation
I have fully built and structured the Coffee-Control-Center application. To suit the target hardware (Raspberry Pi 2), I designed a unified deployment architecture where the FastAPI backend hosts and serves the compiled Angular frontend. This eliminates the memory and CPU overhead of running separate Node/NPM/Nginx environments.
📂 Project Structure Created
1. Backend (FastAPI + MongoDB / Motor)
- backend/requirements.txt - Dependencies for asynchronous Mongo integration.
- backend/app/config.py - Environment loading for port, host, database name, and connection URI.
- backend/app/database.py - Motor connection pool client and FastAPI Dependency.
- backend/app/models/ - Data modeling and Pydantic validation:
- user.py - Structs for name, balance status, role.
- drink.py - Structs for price, inventory.
- transaction.py - Chronological event log.
- backend/app/routes/ - API endpoint business logic:
- users.py - Handles CRUD operations and unpaid (debtor) lists.
- drinks.py - Menu and inventory management.
- transactions.py - Processes purchases (atomic stock decrement and balance update) and manual balance adjustments.
- backend/app/main.py - App configuration, CORS middleware, API route registration, and static file hosting router fallback.
2. Frontend (Angular 18)
- Configs: package.json, angular.json, tsconfig.json, tsconfig.app.json.
- Styling & Assets: index.html (Google Fonts and Material Icons), styles.css (CSS Design Tokens, Glassmorphism, animations).
- Angular Services:
- config.service.ts - Dynamically resolves localhost:8000 api (dev) vs. standard routing (production).
- user.service.ts, drink.service.ts, transaction.service.ts.
- Components:
- kiosk.component.ts (template, style) - Step-based user selection grid, drink selection, and checkout modal with receipt progress bar.
- admin.component.ts (template, style) - Management tabs for user CRUD, drink restock buttons, manual account deposits/withdrawals, debt list, and transaction history resolver.
3. Orchestration
- Dockerfile - Root multi-stage Docker build config.
- docker-compose.yml - Brings up MongoDB 4.4 and the unified web app.
🧪 Verification & Syntax Compile Check
I verified that all Python backend modules are syntactically correct and compile without errors:
Get-ChildItem -Path backend -Filter *.py -Recurse | ForEach-Object { python -m py_compile $_.FullName }
Result: Command succeeded with exit code 0 and no compilation errors.
🚀 How to Launch the System
Follow these steps to run the entire Coffee-Control-Center system:
1. Build and Run via Docker Compose (Recommended)
From the root of the project (where docker-compose.yml resides), run:
docker-compose up --build -d
This command will:
- Download a Node builder container to install frontend dependencies and build Angular statically.
- Copy those built assets into a clean Python runner container and install FastAPI requirements.
- Boot a local MongoDB service.
- Launch the combined server at
http://localhost:8000(serving both the Angular frontend app and FastAPI endpoints on/api).
2. Running Backend Locally (Development Mode)
If you want to run the backend Python server directly outside of Docker:
- Navigate to the backend folder:
cd backend - Install dependencies:
pip install -r requirements.txt - Start the server (make sure you have a local MongoDB running or configure your
MONGODB_URIenvironment variable):uvicorn app.main:app --reload --port 8000 - Verify the API is up by visiting the Swagger Docs at
http://localhost:8000/docs.
3. Running Frontend Locally (Development Mode)
If you want to run the Angular development server:
- Navigate to the frontend folder:
cd frontend - Install Node dependencies:
npm install - Start the Angular dev server:
npm start - Open your browser at
http://localhost:4200. The frontend will automatically route requests to the backend API running athttp://localhost:8000.