I recently refactored my system from a monolithic structure into a layered architecture, but I’m running into critical issues and want some honest feedback.
Context:
- Full-stack TypeScript app (React + Express + PostgreSQL)
- Previously everything was tightly coupled (routes, business logic, DB queries all mixed together)
What I changed:
- Split into service layers:
- OrderService (core order logic)
- InvoiceService (invoice generation, PDF handling)
- AnalyticsService (reporting)
- Introduced cleaner separation between routes → services → database
- Started using centralized pricing logic (instead of hardcoded values)
Current problem:
After restructuring, core functionality like "create order" is failing. The UI loads but data is either not reaching the backend or failing silently.
Some recent changes that might be related:
- Switched from req.staffId to jwtPayload.userId in certain routes
- Some routes bypass middleware and manually decode JWT
- Frontend was partially regenerated (Replit AI), which may have broken API integration
What I suspect:
- Auth mismatch between frontend token and backend expectations
- Broken contract between frontend request body and backend schema (JSONB structure)
- Possible disconnect between new service layer and existing DB logic
What I need feedback on:
- Common pitfalls when migrating from monolith → layered architecture?
- How do you prevent breaking core flows during refactor like this?
- Best way to validate whether the issue is frontend integration vs backend logic?
- Any red flags from the structure I described?
Appreciate direct and critical feedback — I’m trying to make this architecture solid, not just “clean on paper”.