Flick Knowledge Base
Repository docs from .qoder/repowiki
Search, browse, and read the generated project wiki without leaving the repo.
Terms and Conditions Acceptance
Referenced Files in This Document
require-terms.middleware.tsuser.route.tsuser.controller.tsuser.service.tsuser.schema.tsaudit-log.table.tsaudit.service.tsrecord-audit.ts0005_snapshot.jsonTermsForm.tsxauth.controller.tsauth.service.tsonboarding-error-handler.tsx
Table of Contents
Introduction
The Terms and Conditions Acceptance System is a critical compliance mechanism designed to ensure all users acknowledge and agree to the platform's terms before accessing core platform features. This system implements a multi-layered approach combining frontend user interface controls, backend enforcement mechanisms, comprehensive audit logging, and integration with the authentication and onboarding workflows.
The system operates on the principle that user engagement with platform features requires explicit consent to terms, creating a legally and technically enforceable acceptance record. This documentation provides comprehensive coverage of the implementation, workflows, and operational procedures.
System Architecture
The Terms Acceptance System follows a distributed architecture pattern with clear separation of concerns across frontend, backend, and database layers:
graph TB
subgraph "Frontend Layer"
TF[TermsForm Component]
UE[User Experience]
end
subgraph "API Gateway"
AR[API Routes]
AM[Auth Middleware]
TM[Terms Middleware]
end
subgraph "Business Logic"
UC[User Controller]
US[User Service]
AS[Auth Service]
end
subgraph "Persistence Layer"
DB[(PostgreSQL Database)]
AL[Audit Logs Table)]
end
subgraph "Compliance Layer"
RS[Record Audit Service]
AC[Audit Context]
end
TF --> AR
UE --> AR
AR --> AM
AM --> TM
TM --> UC
UC --> US
US --> DB
US --> RS
RS --> AC
AC --> AL
AS --> DBDiagram sources
user.route.tsrequire-terms.middleware.tsuser.controller.tsuser.service.tsaudit-log.table.ts
Core Components
Frontend Terms Interface
The frontend implementation provides an intuitive user interface for terms acceptance through the TermsForm component, which presents users with platform terms and requires explicit consent before granting access to platform features.
Backend Enforcement Layer
The system implements a multi-tier enforcement mechanism through middleware components that intercept requests and validate terms acceptance status before allowing access to protected resources.
Audit and Compliance Engine
A comprehensive audit logging system captures all terms-related activities with detailed metadata for compliance reporting and legal requirements.
Section sources
TermsForm.tsxrequire-terms.middleware.tsaudit-log.table.ts
Terms Acceptance Workflow
The terms acceptance workflow follows a structured process ensuring user consent while maintaining system integrity and compliance requirements.
sequenceDiagram
participant U as User
participant F as TermsForm
participant A as API Gateway
participant C as User Controller
participant S as User Service
participant D as Database
participant L as Audit Logger
U->>F : View Terms Page
F->>U : Display Terms Content
U->>F : Accept Terms Checkbox
F->>A : Submit Acceptance Request
A->>C : POST /user/accept-terms
C->>S : acceptTerms(userId, authId)
S->>D : Update is_accepted_terms = true
S->>L : Record audit entry
L-->>S : Log stored
S-->>C : Success
C-->>A : Terms accepted successfully
A-->>F : Response
F-->>U : Access grantedDiagram sources
user.controller.tsuser.service.tsrecord-audit.ts
Workflow Phases
- Terms Presentation Phase: Users encounter the TermsForm component displaying platform terms
- Consent Collection Phase: Users explicitly check the acceptance checkbox
- Validation Phase: System validates user authentication and terms status
- Acceptance Processing Phase: Database updates reflect terms acceptance
- Audit Recording Phase: Comprehensive audit trail is generated
- Access Granting Phase: User gains access to platform features
Section sources
TermsForm.tsxuser.controller.tsuser.service.ts
Audit Logging Implementation
The audit logging system provides comprehensive tracking of all terms-related activities with detailed metadata for compliance and legal requirements.
Audit Log Schema
The audit log table structure captures essential information for compliance reporting and legal discovery:
| Field | Type | Description | Required | |-------|------|-------------|----------| | id | UUID | Primary key with random default | Yes | | occured_at | TIMESTAMP WITH TIME ZONE | Timestamp of event occurrence | Yes | | actor_id | TEXT | Identifier of acting user/system | No | | actor_type | ENUM | Role type (user, system, admin, service) | Yes | | action | TEXT | Specific action performed | Yes | | entity_type | ENUM | Type of affected entity | Yes | | entity_id | TEXT | Identifier of affected entity | No | | before | JSONB | State before change | No | | after | JSONB | State after change | No | | ip_address | INET | IP address of request origin | No | | user_agent | TEXT | Browser/device information | No | | request_id | UUID | Correlation identifier | No | | reason | TEXT | Explanation for action | No | | metadata | JSONB | Additional contextual data | No |
Audit Event Types
The system generates specific audit events for terms acceptance activities:
flowchart TD
A[Terms Acceptance Event] --> B[user:accepted:terms]
A --> C[other:action]
B --> D[Entity: User]
B --> E[Change: isAcceptedTerms false → true]
B --> F[Actor: User]
B --> G[Metadata: Device info, IP, User-Agent]
C --> H[Entity: User Profile]
C --> I[Change: Branch update]
C --> J[Actor: System/User]Diagram sources
audit-log.table.tsrecord-audit.ts
Section sources
audit-log.table.tsaudit.service.tsrecord-audit.ts
Compliance Tracking
The compliance tracking system ensures regulatory adherence through comprehensive monitoring and reporting capabilities.
Compliance Features
- Legal Discovery Support: Complete audit trails enable legal discovery processes
- Regulatory Reporting: Structured data export for compliance reporting
- Temporal Tracking: Full history of user consent and changes
- Device Fingerprinting: Comprehensive device and browser identification
- Geolocation Integration: IP-based geographic tracking capabilities
Compliance Indicators
The system maintains several key indicators for compliance monitoring:
- Consent Verification: Timestamped evidence of user acceptance
- Change Auditing: Complete modification history for sensitive fields
- Access Control: Real-time enforcement of terms requirements
- Reporting Metrics: Aggregate statistics for compliance reporting
Section sources
audit.service.tsrecord-audit.ts
Integration with Authentication System
The terms acceptance system integrates seamlessly with the authentication framework, ensuring that user consent is required before granting access to authenticated features.
Authentication Integration Points
graph LR
subgraph "Authentication Flow"
AU[Auth User] --> TA[Terms Required]
TA --> UA[User Active]
TA --> NA[Not Accepted]
end
subgraph "Middleware Chain"
AM[Auth Middleware] --> TM[Terms Middleware]
TM --> RF[Route Functions]
end
subgraph "User States"
UA --> AC[Access Granted]
NA --> TR[Terms Required]
endDiagram sources
require-terms.middleware.tsauth.controller.ts
Integration Benefits
- Seamless User Experience: Terms acceptance occurs naturally within the authentication flow
- State Consistency: User state reflects both authentication and terms acceptance
- Security Enhancement: Prevents access to authenticated features without consent
- Compliance Automation: Automatic enforcement of terms requirements
Section sources
require-terms.middleware.tsauth.controller.ts
User Onboarding Process
The terms acceptance system integrates with the broader user onboarding process, creating a comprehensive user lifecycle management approach.
Onboarding Workflow Integration
stateDiagram-v2
[*] --> Registration
Registration --> TermsReview
TermsReview --> TermsAccepted
TermsAccepted --> ProfileCompletion
ProfileCompletion --> ActiveUser
TermsReview --> TermsRejected
TermsRejected --> TermsReview
ActiveUser --> [*]Onboarding State Management
The system manages user states through distinct phases:
- Registration Phase: Initial user creation with ONBOARDING status
- Terms Review Phase: User presented with terms for acceptance
- Terms Accepted Phase: User granted basic platform access
- Profile Completion Phase: Additional user information collection
- Active User Phase: Full platform access granted
Section sources
auth.service.ts0005_snapshot.json
Terms Version Management
The system supports terms version management through database schema evolution and audit trail maintenance.
Database Schema Evolution
The user table includes explicit terms acceptance tracking through the is_accepted_terms field, enabling version-specific compliance tracking:
erDiagram
USER {
uuid id PK
text auth_id FK
text username
uuid college_id
text branch
integer karma
boolean is_accepted_terms
user_status status
}
AUDIT_LOGS {
uuid id PK
timestamp occured_at
text actor_id
text actor_type
text action
text entity_type
text entity_id
jsonb before
jsonb after
inet ip_address
text user_agent
uuid request_id
text reason
jsonb metadata
}
USER ||--o{ AUDIT_LOGS : affectsDiagram sources
0005_snapshot.jsonaudit-log.table.ts
Version Control Implementation
The system maintains version control through:
- Schema Evolution: Database migrations support terms field modifications
- Audit History: Complete change history for terms acceptance
- Backward Compatibility: Support for legacy terms versions
- Compliance Archival: Historical records for legal requirements
Section sources
0005_snapshot.jsonaudit-log.table.ts
API Endpoints
The system exposes dedicated API endpoints for terms management and acceptance workflows.
Terms Management Endpoints
| Endpoint | Method | Description | Authentication | Response | |----------|--------|-------------|----------------|----------| | /user/accept-terms | POST | Accept platform terms and conditions | Required | Success/Failure | | /user/me | GET | Get current user profile | Required | User data | | /user/me | PATCH | Update user profile | Required | Updated user data |
Request/Response Patterns
The API follows consistent patterns for terms-related operations:
Accept Terms Request
{
"headers": {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
},
"body": {}
}Accept Terms Response
{
"status": "success",
"message": "Terms accepted successfully",
"data": null
}Section sources
user.route.tsuser.controller.ts
Troubleshooting Guide
Common issues and resolution strategies for the terms acceptance system.
Terms Not Accepted Errors
Symptoms: Users receive "Terms not accepted" errors when accessing platform features
Causes:
- User has not yet accepted terms
- Authentication session expired
- Database synchronization issues
Resolutions:
- Redirect users to terms acceptance page
- Refresh authentication tokens
- Clear application cache and retry
Audit Logging Issues
Symptoms: Missing or incomplete audit records for terms acceptance
Causes:
- Network connectivity issues during logging
- Database write failures
- Context extraction errors
Resolutions:
- Implement retry mechanisms for audit logging
- Monitor database connection health
- Validate context extraction processes
Frontend Integration Problems
Symptoms: Terms acceptance form not displaying properly
Causes:
- JavaScript errors blocking form rendering
- Missing dependencies
- Authentication state inconsistencies
Resolutions:
- Check browser console for JavaScript errors
- Verify all required dependencies are loaded
- Ensure user authentication state is properly established
Section sources
require-terms.middleware.tsonboarding-error-handler.tsx
Conclusion
The Terms and Conditions Acceptance System provides a robust, compliant solution for managing user consent within the platform. Through its multi-layered architecture, comprehensive audit logging, and seamless integration with authentication and onboarding workflows, the system ensures legal compliance while maintaining excellent user experience.
Key strengths of the implementation include:
- Comprehensive Audit Trail: Complete tracking of all terms-related activities
- Real-time Enforcement: Immediate validation of terms acceptance requirements
- Scalable Architecture: Distributed design supporting high-volume operations
- Compliance Ready: Structured data capture meeting legal and regulatory requirements
- User-Friendly Interface: Intuitive terms acceptance process minimizing friction
The system's modular design enables future enhancements such as terms versioning, automated compliance reporting, and advanced analytics capabilities while maintaining backward compatibility and system stability.