omnivore/docs/architecture/api-endpoints.md
Timothy Atapagra c53bb77721 feat(api-nest): Complete NestJS authentication system with web integration
## Major Accomplishments

###  Authentication System (ARC-003) - COMPLETED
- **Full NestJS Auth Module**: Complete authentication system with JWT, OAuth, and RBAC
- **Type-Safe API Responses**: Comprehensive DTO system with Swagger documentation
- **Web Integration**: Successfully integrated web frontend with NestJS API endpoints
- **Security Hardening**: Fixed authentication vulnerabilities and implemented proper patterns

###  Database Integration (ARC-003B) - COMPLETED
- **Entity Mapping**: Complete TypeORM entities for User, Profile, Personalization, Roles
- **Migration System**: Hybrid approach using existing Postgrator system
- **Schema Compatibility**: Both Express and NestJS APIs access same database

###  Development Environment Optimization
- **Performance Boost**: 25-50x faster cold starts (30-60s → 1.2s)
- **Turbopack Integration**: Next.js 13.5+ experimental bundler enabled
- **Sentry Disabled**: Clean development logs and faster builds
- **Docker Optimization**: Streamlined development workflow

## Technical Details

### Authentication Features Implemented
- JWT token generation and validation
- Email/password login and registration
- OAuth structure (Google, Apple) - ready for testing
- Role-based access control (RBAC)
- Comprehensive error handling with typed responses
- CORS configuration for web frontend

### Web Frontend Integration
- Updated API endpoints to /api/v2 prefix
- Fixed authentication flow with proper JSON responses
- Eliminated backend redirects (anti-pattern)
- Client-side navigation based on API responses
- CORS and CSP optimizations

### Performance Improvements
- Turbopack bundler: 20-40x faster cold starts
- SWC minification: Rust-based compilation
- Filesystem caching: Persistent across restarts
- Smart code splitting: Vendor, Radix UI, Phosphor icons
- Import optimization: Tree-shaking for icon libraries

## Testing Status
-  Email/password login: Working
-  User registration: Working
-  Google OAuth: Ready for testing
-  Apple OAuth: Ready for testing
-  Email verification: Pending email service integration

## Next Phase Recommendations
1. **Vite Migration**: Consider migrating from Next.js to Vite for 50-100x performance gains
2. **GraphQL Setup**: Begin ARC-004 for GraphQL module implementation
3. **OAuth Testing**: Complete Google/Apple authentication testing
4. **Email Service**: Integrate email verification system

## Files Changed
- Complete NestJS authentication system (100+ files)
- Web frontend integration and optimization
- Docker development environment
- Performance optimizations and Sentry configuration
- Comprehensive documentation and migration tracking

This commit represents a major milestone in the Express-to-NestJS migration,
establishing a solid foundation for continued development.
2025-10-09 13:10:32 -04:00

28 lines
3.1 KiB
Markdown

# API Surface Audit
The API exposes GraphQL and a set of REST endpoints. This table highlights the primary REST groupings with recommended actions for the NestJS migration. GraphQL operations inherit the recommendations of their backing services.
| Endpoint Group | Base Path(s) | Purpose | Recommendation | Notes |
| --- | --- | --- | --- | --- |
| Authentication | `/api/auth/*`, `/api/mobile-auth/*` | OAuth (Google/Apple), passwordless email, mobile bootstrap | **Refactor** into `AuthModule` with guards & DTO validation | High complexity, critical path; needs rate limiting & unified session management |
| Articles & Library | `/api/article/*`, `/api/page/*`, `/api/shortcuts/*`, `/api/user` | Save/read articles, text-to-speech, shortcuts, user prefs | **Refactor** under `LibraryModule` & `UserModule` | Ensure parity with GraphQL mutations, consolidate validation |
| Content Services | `/api/content/*`, `/svc/pubsub/content`, `/svc/pubsub/links`, `/svc/pubsub/newsletters`, `/svc/pubsub/rss-feed` | Content ingestion via Pub/Sub style endpoints | **Refactor** into `IngestionModule`; keep HTTP shape for backward compatibility | Introduce Nest controllers + message handlers; document auth expectations |
| AI & Summaries | `/api/ai-summary`, `/api/explain`, `/api/text-to-speech` | AI summaries, explanations, TTS generation | **Keep** semantics, **refactor** implementation for DI | Coordinate with ML services; add feature flags |
| Digest & Notifications | `/api/digest/*`, `/api/notification/*`, `/api/tasks`, `/svc/pubsub/emails` | Daily/weekly digests, notifications queue, admin tasks | **Refactor** into `DigestModule` & `NotificationModule` | Add audit logging, revisit direct task execution via HTTP |
| Export | `/api/export/*` | Export library data, OPML, CSV | **Keep** shape, **refactor** for streaming & auth guard | Ensure large exports are async with queue fallback |
| Integrations | `/api/integration/*`, `/svc/pubsub/webhooks`, `/svc/pubsub/upload`, `/svc/pubsub/user` | Webhooks, uploads, automation hooks | **Refactor** under `IntegrationModule` | Replace ad-hoc handlers with typed controllers & providers |
| Following & Social | `/svc/following` | Manage follower relationships | **Refactor** into `SocialModule` | Clarify contract, ensure rate limiting |
| Health & Metrics | `/_ah/health`, `/metrics`, `/api/debug-sentry` | Health checks & metrics | **Keep** with NestJS terminus + Prometheus | Re-enable Sentry safely |
## GraphQL Schema
- GraphQL schema lives in `packages/api/src/schema` with resolvers under `resolvers/`.
- Many resolvers call services directly and wrap TypeORM queries; no separation between transport and domain.
- Recommendation: migrate schema to NestJS `@nestjs/graphql`, adopt feature modules mirroring REST modules, move business logic into providers.
## Deprecation Targets
- `/api/debug-sentry` should become an authenticated admin-only mutation or test flag.
- Legacy Pub/Sub endpoints that mimic Google Cloud Pub/Sub push format can be replaced by internal queues once NestJS listeners exist; keep compatibility until mobile/web clients shift to new flows.
Keep this audit updated as endpoints move or contracts change.