Architecture Overview
This document provides a high-level overview of the Aaperture application architecture.
Project Structure
aaperture/
├── backend/ # NestJS backend API
├── frontend/ # React frontend application
├── infra/ # Infrastructure (Docker, Liquibase, Caddy)
├── openapi/ # OpenAPI specification
└── docs/ # Documentation
Technology Stack
Backend
- Framework: NestJS (Node.js 22)
- Language: TypeScript
- Database: PostgreSQL with Kysely (type-safe query builder)
- Migrations: Liquibase
- Authentication: JWT + Google OAuth
- File Storage: Cloudflare R2 (S3-compatible)
- WebSocket: Socket.IO
- Validation: Zod
- Cache: Redis (ioredis) for performance and rate limiting
- Rate Limiting: Custom guard with Redis backend
Frontend
- Framework: React 18
- Language: TypeScript
- Routing: TanStack Router
- State Management: Zustand
- Forms: TanStack Form
- API Client: TanStack Query
- Styling: Tailwind CSS
- UI Components: Custom components (shadcn/ui style)
- Internationalization: react-i18next
- WebSocket: Socket.IO Client
- PWA: Progressive Web App with Service Worker (vite-plugin-pwa)
- Push Notifications: Browser push notifications support
Architecture Principles
Clean Architecture & Domain Driven Design
- Domain Layer: Business logic and entities
- Application Layer: Use cases and services
- Infrastructure Layer: Database, external services, APIs
- Presentation Layer: Controllers, DTOs, validation
Key Patterns
- Repository Pattern: Data access abstraction
- Service Layer: Business logic encapsulation
- DTO Pattern: Data transfer objects for API boundaries
- Guard Pattern: Authentication and authorization
- Module Pattern: Feature-based organization
Module Organization
Backend Modules
Core Modules
- auth: Authentication, JWT, Google OAuth, user guards
- users: User management, profile, company information
- db: Database service with Kysely (with configurable timeouts)
- storage: File upload/download to Cloudflare R2
- websocket: Real-time communication
- cache: Redis cache service for performance
- rate-limiting: API rate limiting with Redis backend
- export: Data export service (CSV, Excel, JSON)
- common/timeout: Centralized timeout configuration and management (see TIMEOUT_MANAGEMENT.md)
Business Modules
- duplicates: Duplicate management and registration
- sessions: Session management (weddings, photo sessions)
- contacts: Contact management with location
- client-messages: Client portal messaging with real-time notifications (WebSocket + email)
- tags: Tagging system for sessions and contacts
- notifications: User notification system (in-app + push notifications)
- extraction: OCR and LLM-based data extraction
Frontend Modules
Core
- auth: Authentication context and hooks
- client: API client hooks (TanStack Query)
- components: Reusable UI components
- pages: Page components
- router: Routing configuration
- store: Zustand state management
- i18n: Internationalization
Data Flow
Authentication Flow
- User logs in via Google OAuth
- Backend validates and creates/updates user
- JWT token generated and returned
- Frontend stores token and user data
- Token included in all API requests
- Backend validates token and user status (ACTIVE)
API Request Flow
- Frontend: TanStack Query hook calls API client
- API Client: Adds JWT token to request
- Backend: JWT Guard validates token
- Backend: ActiveUserGuard checks user status
- Backend: Service executes business logic
- Backend: Returns response
- Frontend: TanStack Query updates cache
WebSocket Flow
- Frontend: Connects to WebSocket with JWT token
- Backend: Validates token and establishes connection
- Backend: Emits events to specific users or all users
- Frontend: Receives events and updates UI