Skip to content

Commit e0d23ef

Browse files
Merge branch 'main' into copilot/add-social-media-integration
2 parents 3b0ec0b + 2774830 commit e0d23ef

17 files changed

+2012
-0
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,7 @@ CONTAINER_MODE=http
100100
WITH_HORIZON=false
101101
WITH_SCHEDULER=true
102102
RUNNING_MIGRATIONS_AND_SEEDERS=false
103+
104+
# Google Cloud Vision API for Handwriting Recognition
105+
# Get your API key from: https://console.cloud.google.com/apis/credentials
106+
GOOGLE_VISION_API_KEY=

ARCHITECTURE_DIAGRAM.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Transcription Feature Architecture
2+
3+
```
4+
┌─────────────────────────────────────────────────────────────────────┐
5+
│ USER INTERFACE │
6+
│ /transcriptions route → DocumentTranscriptionComponent (Livewire) │
7+
└────────────────────┬────────────────────────────────────────────────┘
8+
9+
10+
┌─────────────────────────────────────────────────────────────────────┐
11+
│ LIVEWIRE COMPONENT │
12+
│ • File upload with validation │
13+
│ • Document selection │
14+
│ • Transcription display │
15+
│ • Edit/correction interface │
16+
│ • Statistics dashboard │
17+
└────────────────────┬────────────────────────────────────────────────┘
18+
19+
20+
┌─────────────────────────────────────────────────────────────────────┐
21+
│ SERVICE LAYER │
22+
│ HandwritingRecognitionService │
23+
│ │
24+
│ processDocument() → Upload & process new documents │
25+
│ performOCR() → Google Vision API / Fallback │
26+
│ applyCorrection() → Save user corrections │
27+
│ learnFromCorrection() → Track patterns for ML │
28+
│ getTeamStats() → Optimized statistics query │
29+
└────────┬────────────────────────────────────────────┬───────────────┘
30+
│ │
31+
▼ ▼
32+
┌──────────────────────┐ ┌──────────────────────┐
33+
│ EXTERNAL APIs │ │ FILE STORAGE │
34+
│ │ │ │
35+
│ Google Cloud Vision │ │ Laravel Storage │
36+
│ API (OCR) │ │ (public disk) │
37+
└──────────────────────┘ └──────────────────────┘
38+
39+
40+
┌─────────────────────────────────────────────────────────────────────┐
41+
│ MODEL LAYER │
42+
│ │
43+
│ DocumentTranscription TranscriptionCorrection │
44+
│ ├─ id ├─ id │
45+
│ ├─ team_id (FK) ├─ document_transcription_id │
46+
│ ├─ user_id (FK) ├─ user_id (FK) │
47+
│ ├─ original_filename ├─ original_text │
48+
│ ├─ document_path ├─ corrected_text │
49+
│ ├─ raw_transcription ├─ position_start │
50+
│ ├─ corrected_transcription ├─ position_end │
51+
│ ├─ metadata (JSON) ├─ correction_metadata │
52+
│ ├─ status └─ timestamps │
53+
│ ├─ processed_at │
54+
│ └─ timestamps + soft deletes │
55+
└─────────────────────────────────────────────────────────────────────┘
56+
57+
58+
┌─────────────────────────────────────────────────────────────────────┐
59+
│ DATABASE LAYER │
60+
│ │
61+
│ document_transcriptions table transcription_corrections table │
62+
│ ├─ Indexes on team_id ├─ Indexes on document_id │
63+
│ ├─ Indexes on user_id ├─ Indexes on user_id │
64+
│ ├─ Indexes on status └─ Foreign key constraints │
65+
│ └─ Foreign key constraints │
66+
└─────────────────────────────────────────────────────────────────────┘
67+
```
68+
69+
## Data Flow
70+
71+
### 1. Upload Flow
72+
```
73+
User uploads image
74+
→ Livewire validates file
75+
→ Service stores to disk
76+
→ Service calls Google Vision API
77+
→ Service saves transcription to DB
78+
→ UI updates with result
79+
```
80+
81+
### 2. Correction Flow
82+
```
83+
User selects transcription
84+
→ UI shows document + text side-by-side
85+
→ User edits text
86+
→ Service saves correction to DB
87+
→ Service updates transcription
88+
→ Service logs pattern for learning
89+
→ UI shows success message
90+
```
91+
92+
### 3. Statistics Flow
93+
```
94+
UI requests stats
95+
→ Service executes single optimized query
96+
→ Returns aggregated data:
97+
• Total transcriptions
98+
• Completed count
99+
• Pending count
100+
• Failed count
101+
• Average confidence
102+
• Total corrections
103+
→ UI displays in dashboard cards
104+
```
105+
106+
## Key Design Decisions
107+
108+
### 1. Team-Scoped Access
109+
- All transcriptions belong to a team
110+
- Users only see their team's documents
111+
- Enforced at service and component level
112+
113+
### 2. Dual Transcription Storage
114+
- `raw_transcription`: Original AI output
115+
- `corrected_transcription`: User-edited version
116+
- Allows tracking improvements and reverting if needed
117+
118+
### 3. Metadata as JSON
119+
- Flexible storage for AI confidence scores
120+
- Processing time tracking
121+
- Language detection
122+
- Future extensibility without migrations
123+
124+
### 4. Learning System
125+
- Every correction tracked separately
126+
- Position information stored
127+
- Metadata for pattern analysis
128+
- Foundation for future ML training
129+
130+
### 5. Performance Optimization
131+
- Single SQL query for all statistics
132+
- Proper database indexing
133+
- Conditional aggregation in SQL
134+
- JSON field extraction optimization
135+
136+
### 6. Graceful Degradation
137+
- Fallback OCR when API unavailable
138+
- Clear error messaging
139+
- Pending/processing/failed states
140+
- Soft deletes for data recovery
141+
142+
## Testing Strategy
143+
144+
### Unit Tests (8 tests)
145+
- Service method validation
146+
- Model helper methods
147+
- Statistics calculation
148+
- Correction application
149+
150+
### Feature Tests (11 tests)
151+
- Component lifecycle
152+
- File upload validation
153+
- User interactions
154+
- Team isolation
155+
- Statistics display
156+
157+
### Integration Points
158+
- Google Cloud Vision API (mocked in tests)
159+
- File storage (faked in tests)
160+
- Database transactions
161+
- Livewire interactions
162+
163+
## Security Measures
164+
165+
1. **Authentication**: Required for all routes
166+
2. **Authorization**: Team-based access control
167+
3. **Validation**: File type and size limits
168+
4. **Sanitization**: SQL injection prevention
169+
5. **Encryption**: API keys in environment
170+
6. **Audit Trail**: User tracking on all operations
171+
172+
## Scalability Considerations
173+
174+
- Queue-ready architecture (async processing)
175+
- Batch processing capability
176+
- Indexed database tables
177+
- Optimized queries
178+
- Cloud storage support
179+
- Horizontal scaling ready

0 commit comments

Comments
 (0)