Architecture Overview
TamborraData follows a clean, layered architecture with strict separation of concerns. The application is organized into distinct layers, each with a single responsibility, making it maintainable, testable, and scalable.Architecture Diagram
Layered Architecture
The application is organized into five distinct layers:1. Presentation Layer
1. Presentation Layer
Location:
app/(frontend)/Responsibilities:- Rendering UI components
- Client-side interactivity
- Data fetching with React Query
- Server Components for SEO and performance
- Next.js 16 App Router
- React Server Components
- TanStack React Query
- TailwindCSS
2. API Layer
2. API Layer
Location: Example:
app/(backend)/api/Responsibilities:- HTTP request handling
- Request/response validation
- Error handling
- Query parameter parsing
app/(backend)/api/statistics/route.ts:73. Business Layer
3. Business Layer
Location:
app/(backend)/api/*/services/Responsibilities:- Business logic implementation
- Data transformation and formatting
- Orchestrating repository calls
- Error handling and logging
app/(backend)/api/statistics/services/statistics.service.ts:7Services contain NO database queries, only business logic.4. Data Layer
4. Data Layer
Location:
app/(backend)/api/*/repositories/Responsibilities:- Database queries
- Data access abstraction
- SQL/ORM operations
- Connection management
app/(backend)/api/statistics/repositories/statistics.repo.ts:6Repositories contain ONLY data access code, no business logic.5. Database Layer
5. Database Layer
Location: Supabase PostgreSQLResponsibilities:
- Data persistence
- Row Level Security (RLS)
- Constraints and indexes
- Triggers and functions
app/(backend)/core/db/supabaseClient.ts:6Request Flow Example
Here’s how a typical request flows through the layers:Design Principles
Separation of Concerns
Each layer has a single, well-defined responsibility. UI code doesn’t touch databases, repositories don’t handle HTTP.
Dependency Direction
Dependencies flow downward only. Upper layers depend on lower layers, never the reverse.
Abstraction
Each layer abstracts implementation details. Services don’t know if data comes from PostgreSQL, MongoDB, or REST API.
Testability
Each layer can be tested independently by mocking the layer below it.
Benefits of This Architecture
Maintainability
Maintainability
- Clear organization makes code easy to find
- Changes in one layer don’t affect others
- New features follow established patterns
- Code reviews are more focused
Testability
Testability
- Mock repositories for service tests
- Mock services for API route tests
- Integration tests at layer boundaries
- Unit tests within each layer
Scalability
Scalability
- Easy to add new features
- Repositories can be optimized independently
- Services can be extracted to microservices if needed
- Caching can be added at any layer
Security
Security
- Database security enforced by RLS
- Input validation at API layer
- Business rules in service layer
- No SQL injection risk with proper abstraction
Project Structure
The codebase is organized by feature, not by file type:Feature-based organization makes it easy to:
- Find all code related to a feature
- Delete or refactor features without affecting others
- Understand the scope of changes
- Reduce merge conflicts
Code Organization Rules
Comparison with Alternatives
| Approach | TamborraData | Monolithic | Microservices |
|---|---|---|---|
| Complexity | ✅ Moderate | ✅ Low | ❌ High |
| Maintainability | ✅ High | ❌ Low | ⚠️ Medium |
| Performance | ✅ Fast | ✅ Fast | ⚠️ Network overhead |
| Testability | ✅ Easy | ❌ Hard | ✅ Easy |
| Scalability | ✅ Good | ❌ Limited | ✅ Excellent |
| Team Size | ✅ Small-Medium | ✅ Small | ❌ Large |
Why layered monolith? TamborraData uses a modular monolith approach that provides most benefits of microservices without the operational complexity. This is ideal for small-to-medium applications with a small team.
Next Steps
Explore each layer in detail:Frontend
Server Components, React Query, and UI patterns
Backend
API Routes, Services, and Repository pattern
Database
PostgreSQL schema, RLS policies, and Supabase