How jackmisner/brewtracker works
1. Top-level shape
BrewTracker is a two-tier monorepo: a React/TypeScript frontend in frontend/ and a Flask/Python API in backend/. The frontend owns user interaction and local UI state; the backend owns authentication, calculations, persistence, AI analysis, and domain rules.
2. Frontend boundary
The frontend is organized as a classic SPA with pages/ for routes, components/ for reusable UI, services/ for API access, reducers/ and hooks/ for state orchestration, and contexts/ for cross-cutting preferences like units. This creates a clear separation between presentation, client state, and server communication.
3. Frontend data flow
User actions in pages such as recipe builder, brew sessions, beer XML, and settings call TypeScript service modules, which go through a shared HTTP client in src/services/api.ts. Those services map backend API responses into typed models under src/types/, while reducers store workflow state for multi-step features like recipe editing, BeerXML import, and session tracking.
4. Backend entry and API boundary
The backend starts from backend/app.py, which wires Flask configuration, CORS, auto-seeding, error handling, security headers, and blueprint registration. Each domain area is exposed as a Flask blueprint in backend/routes/, keeping the API surface split by feature rather than by transport mechanics.
5. Backend domain layers
The backend uses a strong “routes → services → utils/models” structure. Routes stay thin and delegate to services; services implement business rules and orchestration; utils provide reusable pure logic such as brewing math, unit conversion, sanitization, validation, crypto, and security monitoring. MongoEngine models in backend/models/ define persisted domain objects and validation.
6. Persistence and seed data
MongoDB is the main datastore, accessed through mongodb_service.py and MongoEngine models. Initial domain data comes from JSON files in backend/data/ and is loaded by seed scripts for ingredients, beer styles, and system users. That means the app bootstraps itself with reference data and special accounts before normal use.
7. Core brewing workflow
Recipe creation and editing is centered on brewing calculations: OG, FG, ABV, IBU, SRM, unit conversion, and recipe normalization. These calculations live primarily in backend/utils/brewing_calculation_core.py, recipe_api_calculator.py, and recipe_orm_calculator.py, then surface through recipe- and analytics-related routes and frontend recipe builder components.
8. AI analysis subsystem
The AI feature is not a generic LLM integration; it is a flowchart-based rules engine under backend/services/ai/. flowchart_engine.py, flowchart_nodes.py, optimization_strategies.py, and recipe_context.py execute YAML-defined workflows such as recipe optimization and unit conversion. The frontend’s AI suggestions UI consumes this output through a dedicated AI service and reducer.
9. BeerXML and ingredient matching
BeerXML import/export is a separate pipeline spanning frontend and backend. The frontend provides import/export and review screens; the backend exposes BeerXML routes and ingredient lookup/matching logic. This subsystem bridges external recipe files into BrewTracker’s internal recipe model and handles unit/ingredient normalization during import.
10. Brew session and attenuation analytics
Brew sessions are tracked as a lifecycle tied to recipes: creation, editing, fermentation notes, dry hop tracking, and gravity stabilization analysis. A separate attenuation analytics path aggregates real-world yeast performance data and feeds both the analytics page and backend analytics/attenuation services.
11. Authentication, user settings, and system users
Authentication is JWT-based, with Google OAuth support handled by backend verification services and a frontend sign-in component. User settings, account deletion, and username validation are separate flows. The “system users” concept is important architecturally because deleted-user public content can be re-attributed instead of removed, preserving community recipes while protecting privacy.
12. Security and operational boundaries
Security is a first-class backend layer: rate limiting, request validation, input sanitization, headers, monitoring, crypto utilities, and geolocation support are all in dedicated modules rather than embedded in routes. This makes the backend’s trust boundary explicit: untrusted client input enters through routes, is validated/sanitized, then reaches business logic and MongoDB.
13. Deployment and delivery
The repo includes CI for both apps via GitHub Actions, plus separate deployment workflows for backend and frontend. The backend includes Dockerfile and fly.toml, suggesting containerized deployment on Fly.io, while the frontend includes vercel.json, suggesting Vercel hosting. This reinforces that the two halves are independently built and deployed but share the same product surface.
14. Tests as architectural documentation
The test suites closely mirror the system structure: backend tests cover routes, services, utils, models, and security behavior; frontend tests cover components, reducers, services, hooks, and pages. That symmetry confirms the main boundaries are feature-oriented modules with strong separation between UI, API, domain logic, and infrastructure.
Main entry points: pages Pages · routes API routes · backend/services Domain services · src/services Feature services
Components 20
Frontend
React/TypeScript SPA for user workflows and client state.
- App shell · Bootstraps the SPA and shared layout/routing.
frontend/src/App.tsx - Pages · Top-level screens for recipes, sessions, auth, settings, and content.
frontend/src/pages - UI components · Reusable panels and workflow-specific controls for recipes, BeerXML, brew sessions, and analytics.
frontend/src/components - API client · Shared request layer used by feature services.
frontend/src/services/api.ts - Feature services · Domain-specific client services for recipes, BeerXML, brewing, analytics, AI, and user settings.
frontend/src/services - State logic · Workflow state orchestration for builders, imports, sessions, analytics, and settings.
frontend/src/reducers - Unit context · Shared preferences and global UI context such as measurement units.
frontend/src/contexts - Typed models · Shared TypeScript types for API payloads, recipes, sessions, users, and units.
frontend/src/types - Frontend tests · Mirrors UI, hooks, reducers, services, contexts, and pages.
frontend/tests
Backend
Flask/Python API for domain logic, persistence, and security.
- Flask app · Application entrypoint wiring config, CORS, headers, seeding, and blueprints.
backend/app.py - API routes · Feature-oriented HTTP endpoints for auth, recipes, BeerXML, sessions, analytics, and settings.
backend/routes - Domain services · Orchestration and rules for auth, AI, attenuation, lookup, user lifecycle, and persistence.
backend/services - AI engine · Flowchart-based recipe optimization and unit-conversion workflows driven by YAML configs.
backend/services/ai - Core utils · Brewing math, unit conversion, validation, sanitization, crypto, rate limiting, and security headers.
backend/utils - Mongo models · MongoEngine domain objects and validation rules.
backend/models/mongo_models.py - MongoDB · Primary persistent store accessed through the Mongo service and models.
backend/services/mongodb_service.py - Seed data · JSON reference sets for beer styles, ingredients, and system users.
backend/data - Seed scripts · Initial loaders that populate reference data and system accounts.
backend/seeds - Backend tests · Covers routes, services, utils, models, workflows, and security behavior.
backend/tests
Delivery
CI, deployment, and runtime packaging.
- CI/CD · GitHub Actions for backend/frontend CI and separate deployment pipelines.
.github/workflows
Connections 25
- App shell → Pages: renders · Top-level app composes routed screens.
- App shell → UI components: uses · Pages and shared layout are built from reusable components.
- Pages → Feature services: calls · Screens invoke feature services for data and actions.
- Feature services → API client: through · All network access passes through the shared API client.
- Feature services → Typed models: maps · Service responses are typed using shared models.
- State logic → Feature services: orchestrates · Reducers/hooks coordinate multi-step workflows around service calls.
- Unit context → UI components: provides · Shared preferences flow into UI components.
- Pages → State logic: uses · Route screens rely on local workflow state.
- Pages → Unit context: reads · Pages consume global preference context.
- Frontend tests → Pages: covers · Tests mirror the page and component boundaries.
- Frontend tests → Feature services: covers · Tests validate client-side service behavior.
- Flask app → API routes: registers · Flask entrypoint wires feature blueprints.
- API routes → Domain services: delegates · Routes remain thin and hand off logic to services.
- Domain services → Core utils: uses · Business logic relies on shared math, security, and validation helpers.
- Domain services → Mongo models: persists via · Services read and write MongoEngine models.
- Mongo models → MongoDB: stored in · Domain models are backed by MongoDB.
- Seed scripts → Seed data: loads · Bootstrap scripts populate the reference datasets.
- Domain services → AI engine: includes · AI workflows are a specialized service subsystem.
- API routes → AI engine: exposes · AI endpoints publish workflow results to clients.
- API routes → Mongo models: reads/writes · Endpoints interact with persisted domain objects through services.
- Backend tests → API routes: covers · Tests validate API behavior and boundaries.
- Backend tests → Domain services: covers · Tests validate business rules and orchestration.
- Backend tests → Core utils: covers · Tests validate calculations and security helpers.
- CI/CD → Flask app: builds/deploys · Backend workflow handles packaging and deployment.
- CI/CD → App shell: builds/deploys · Frontend workflow handles build and hosting deployment.