EMTB Source Tree Organization
Overviewβ
The EMTB Tax Claim Management System follows a monorepo architecture with independent applications for API and frontend, organized for optimal development workflow and role-based access control implementation.
Root Directory Structureβ
emtb/
βββ .bmad-core/ # AI agent configurations and templates
βββ .claude/ # Claude Code configurations
βββ .cursor/ # Cursor IDE configurations
βββ .github/ # GitHub Actions workflows and templates
β βββ workflows/ # CI/CD pipeline definitions
β βββ ISSUE_TEMPLATE/ # Issue and PR templates
βββ .git/ # Git repository data
βββ apps/ # Application packages (main development)
β βββ api/ # NestJS backend application
β βββ frontend/ # Next.js frontend application
βββ docs/ # Project documentation
β βββ architecture/ # Technical architecture documents
β βββ prd.md # Product Requirements Document
β βββ architecture.md # Main architecture specification
βββ web-bundles/ # Generated bundle assets
βββ README.md # Project overview and setup
βββ RENDER_DEPLOYMENT.md # Render.com deployment guide
βββ RENDER_TROUBLESHOOTING.md # Infrastructure troubleshooting
βββ render.yaml # Render.com service definitions
Backend Application Structure (apps/api/)β
Core Organizationβ
apps/api/
βββ src/
β βββ main.ts # Application entry point
β βββ app.module.ts # Root application module
β βββ app.controller.ts # Health check and root endpoints
β βββ app.service.ts # Root application services
β β
β βββ prisma/ # Database connection and configuration
β β βββ prisma.module.ts # Prisma module definition
β β βββ prisma.service.ts # Database service with connection pooling
β β
β βββ client/ # Client management domain
β β βββ client.module.ts # Client module with dependencies
β β βββ client.controller.ts # REST endpoints for client operations
β β βββ client.service.ts # Business logic for client management
β β βββ client.service.spec.ts # Unit tests for client service
β β βββ client.controller.spec.ts # Controller unit tests
β β βββ dto/ # Data Transfer Objects
β β βββ create-client.dto.ts
β β βββ update-client.dto.ts
β β
β βββ site/ # Site management domain
β β βββ site.module.ts # Site module definition
β β βββ [similar structure to client/]
β β
β βββ reclamation/ # Tax claim management domain
β β βββ reclamation.module.ts
β β βββ [similar structure to client/]
β β
β βββ facture/ # Invoice management domain
β β βββ facture.module.ts
β β
β βββ user/ # User management domain
β β βββ user.module.ts
β β
β βββ apporteur-affaire/ # Partner/referrer management
β β βββ apporteur-affaire.module.ts
β β
β βββ facture-partenaire/ # Partner invoice management
β β βββ facture-partenaire.module.ts
β β
β βββ cadastre/ # Property/cadastral data management
β β βββ cadastre.module.ts
β β βββ cadastre.controller.ts
β β βββ cadastre.service.ts
β β βββ dto/
β β βββ create-cadastre.dto.ts
β β βββ update-cadastre.dto.ts
β β
β βββ import/ # Data import functionality
β β βββ import.module.ts # Import service module
β β βββ import.service.ts # Data import logic
β β βββ import.service.spec.ts # Import testing
β β
β βββ cli/ # Command-line interface
β β βββ cli.module.ts # CLI module definition
β β βββ import.command.ts # Import command implementation
β β
β βββ scripts/ # Utility and maintenance scripts
β β βββ fix-json-data.ts # Data cleanup scripts
β β βββ fix-json-data.spec.ts
β β βββ validate-import-data.ts # Data validation scripts
β β βββ validate-import-data.spec.ts
β β
β βββ cli.ts # CLI entry point
β
βββ test/ # End-to-end and integration tests
β βββ jest-e2e.json # E2E testing configuration
β
βββ prisma/ # Database schema and migrations
β βββ schema.prisma # Database schema definition
β βββ migrations/ # Database migration files
β
βββ package.json # Backend dependencies and scripts
βββ tsconfig.json # TypeScript configuration
Domain Module Patternβ
Each domain (client, site, reclamation, etc.) follows a consistent structure:
domain/
βββ domain.module.ts # NestJS module with providers and exports
βββ domain.controller.ts # HTTP endpoints with Swagger documentation
βββ domain.service.ts # Business logic and Prisma integration
βββ domain.controller.spec.ts # Controller unit tests
βββ domain.service.spec.ts # Service unit tests
βββ dto/ # Data Transfer Objects
βββ create-domain.dto.ts # Creation DTOs with validation
βββ update-domain.dto.ts # Update DTOs (usually extends CreateDto)
Frontend Application Structure (apps/frontend/)β
Core Organizationβ
apps/frontend/
βββ app/ # Next.js 14 App Router structure
β βββ layout.tsx # Root layout with providers
β βββ page.tsx # Home page component
β βββ loading.tsx # Loading UI component
β βββ error.tsx # Error boundary component
β βββ not-found.tsx # 404 page component
β β
β βββ api/ # API routes (Next.js API routes)
β β βββ auth/ # Auth0 API routes
β β
β βββ protected/ # Authenticated routes
β β βββ layout.tsx # Protected area layout
β β βββ dashboard/ # Dashboard pages
β β βββ clients/ # Client management pages
β β βββ reclamations/ # Tax claim pages
β β βββ reports/ # Reporting pages
β β
β βββ auth/ # Authentication pages
β βββ login/
β βββ logout/
β βββ callback/
β
βββ components/ # Reusable UI components
β βββ shared/ # Generic shared components
β β βββ List.tsx # Generic data list component
β β βββ ConfirmationDialog.tsx # Confirmation modals
β β βββ LoadingSpinner.tsx # Loading indicators
β β
β βββ layout/ # Layout-specific components
β β βββ Header.tsx # Application header
β β βββ Sidebar.tsx # Navigation sidebar
β β βββ Footer.tsx # Application footer
β β
β βββ forms/ # Form components
β βββ FormField.tsx # Generic form field wrapper
β βββ ValidationMessage.tsx # Form validation display
β
βββ domains/ # Domain-specific components and logic
β βββ clients/ # Client management domain
β β βββ components/ # Client-specific components
β β β βββ ClientsList.tsx # Client listing component
β β β βββ ClientShortDetails.tsx # Client summary
β β β βββ forms/ # Client form components
β β β βββ ClientForm.tsx
β β β βββ ContactForm.tsx
β β β βββ PartnerForm.tsx
β β β βββ PartnerSelectList.tsx
β β β βββ MandatForm.tsx
β β β βββ ConventionForm.tsx
β β β βββ GeneralInformationForm.tsx
β β β
β β βββ hooks/ # Client-specific hooks
β β βββ queries/ # React Query hooks
β β βββ clients.ts # Client data fetching hooks
β β
β βββ reclamations/ # Tax claim management domain
β βββ sites/ # Site management domain
β βββ reports/ # Reporting domain
β
βββ contexts/ # React Context providers
β βββ AuthProvider.tsx # Auth0 context wrapper
β βββ ThemeProvider.tsx # MUI theme context
β βββ SnackbarProvider.tsx # Global notification context
β
βββ hooks/ # Shared custom hooks
β βββ useAuth.ts # Authentication state hook
β βββ useLocalStorage.ts # Local storage utilities
β βββ useDebounce.ts # Debouncing utilities
β
βββ shared/ # Shared utilities and services
β βββ services/ # API service layer
β β βββ client.ts # Client API service
β β βββ reclamation.ts # Tax claim API service
β β βββ api.ts # Base API client
β β
β βββ query-keys.ts # React Query key definitions
β βββ constants.ts # Application constants
β βββ utils.ts # Utility functions
β
βββ types/ # TypeScript type definitions
β βββ next-auth.d.ts # Next-auth type extensions
β βββ strapi.dts.ts # Generated API types
β βββ shared.ts # Shared type definitions
β βββ theme.ts # MUI theme types
β βββ sidebar.ts # Navigation types
β βββ autocomplete-option.ts # Form component types
β βββ images.d.ts # Image asset types
β βββ emotion.d.ts # Emotion CSS types
β
βββ theme/ # MUI theme configuration
β βββ index.ts # Theme provider and configuration
β βββ components/ # Component-specific theme overrides
β
βββ utils/ # Utility functions and helpers
β βββ constants.ts # Global constants
β βββ formatters.ts # Data formatting utilities
β βββ validators.ts # Form validation utilities
β
βββ vendor/ # Third-party assets and configurations
β βββ mui/ # Material-UI specific customizations
β
βββ middleware.ts # Next.js middleware (authentication)
βββ constants.js # Legacy constants (to be migrated)
βββ next.config.js # Next.js configuration
βββ tailwind.config.js # Tailwind CSS configuration
βββ postcss.config.js # PostCSS configuration
βββ tsconfig.json # TypeScript configuration
βββ jest.config.ts # Jest testing configuration
βββ jest.setup.ts # Jest setup and global mocks
βββ package.json # Frontend dependencies and scripts
Key Architectural Patternsβ
Backend Patternsβ
- Module-based Organization: Each business domain has its own NestJS module
- Controller-Service Pattern: Clear separation between HTTP handling and business logic
- DTO Pattern: Validation and type safety with class-validator decorators
- Repository Pattern: Prisma service acts as repository layer
- CLI Integration: Command pattern for data management operations
Frontend Patternsβ
- Domain-driven Organization: Components organized by business domain
- Atomic Design: Shared components, domain-specific components, page layouts
- Custom Hook Pattern: React Query integration with domain-specific hooks
- Service Layer Pattern: Centralized API communication layer
- Provider Pattern: Context-based state management
RBAC Implementation Structure (Planned)β
Backend RBAC Structureβ
src/
βββ auth/ # RBAC authentication and authorization
β βββ guards/ # Role-based route guards
β βββ decorators/ # Role requirement decorators
β βββ services/ # Authentication services
β βββ middleware/ # Tenant context middleware
β
βββ tenant/ # Multi-tenant data isolation
β βββ services/ # Tenant context management
β βββ middleware/ # Prisma middleware for filtering
β
βββ audit/ # Security audit logging
βββ services/ # Audit log services
βββ models/ # Audit data models
Frontend RBAC Structureβ
src/
βββ contexts/
β βββ RoleContext.tsx # Role-based state management
β
βββ components/
β βββ rbac/ # Role-aware UI components
β βββ ProtectedRoute.tsx # Route protection
β βββ RoleBasedRender.tsx # Conditional rendering
β
βββ hooks/
βββ useRole.ts # Role state management
βββ usePermissions.ts # Permission checking
File Naming Conventionsβ
Backend (NestJS/TypeScript)β
- Modules:
domain.module.ts(kebab-case for domain, PascalCase for class) - Controllers:
domain.controller.ts(REST endpoint handlers) - Services:
domain.service.ts(business logic) - DTOs:
create-domain.dto.ts,update-domain.dto.ts(kebab-case files) - Tests:
*.spec.ts(same name as tested file)
Frontend (Next.js/React/TypeScript)β
- Components:
ComponentName.tsx(PascalCase) - Pages:
page.tsx,layout.tsx(Next.js App Router convention) - Hooks:
useHookName.ts(camelCase with 'use' prefix) - Services:
serviceName.ts(camelCase) - Types:
typeName.tsordomain.types.ts(camelCase)
Import Path Conventionsβ
Backend Importsβ
// Relative imports within same module
import { CreateClientDto } from './dto/create-client.dto';
// Absolute imports for cross-module
import { PrismaService } from '../prisma/prisma.service';
Frontend Importsβ
// Absolute imports using path mapping (tsconfig.json)
import { ClientService } from '$shared/services/client';
import { useAuth } from '$hooks/useAuth';
import FormField from '$components/forms/FormField';
// Domain-specific imports
import { ClientForm } from '$domains/clients/components/forms/ClientForm';
Build and Development Organizationβ
Package Scriptsβ
- Development:
npm run dev(both apps),npm run dev:api,npm run dev:frontend - Building:
npm run build(both apps),npm run build:api,npm run build:frontend - Testing:
npm run test,npm run test:unit,npm run test:e2e - Linting:
npm run lint(both apps with --fix) - Type Checking:
npm run type:check(TypeScript validation)
Deployment Structureβ
- Production Build: Separate Docker containers for API and frontend
- Environment Variables: App-specific .env files
- Database Migrations: Handled via Prisma migrate in deployment pipeline
This source tree organization supports the RBAC enhancement by providing clear separation of concerns, consistent patterns, and scalable architecture for multi-tenant security implementation.