|
| 1 | +# Target Architecture Blueprint |
| 2 | + |
| 3 | +## 1. Context Diagram |
| 4 | +```mermaid |
| 5 | +flowchart LR |
| 6 | + subgraph Users |
| 7 | + Visitor[Visitor] |
| 8 | + Member[Member] |
| 9 | + Creator[Creator] |
| 10 | + Moderator[Moderator] |
| 11 | + Admin[Platform Admin] |
| 12 | + Sponsor[Sponsor / Donor] |
| 13 | + end |
| 14 | +
|
| 15 | + Visitor -->|consume content| WebApp[Next.js Web Experience] |
| 16 | + Member -->|publish / engage| WebApp |
| 17 | + Creator -->|manage projects/events| WebApp |
| 18 | + Moderator -->|review queues| WebApp |
| 19 | + Admin -->|configure policies| WebApp |
| 20 | + Sponsor -->|fund bounties/donations| WebApp |
| 21 | +
|
| 22 | + WebApp -->|RLS-secured queries| Supabase[(Supabase Postgres + Auth)] |
| 23 | + WebApp -->|Edge functions| SupaFunctions[Supabase Edge Functions] |
| 24 | + WebApp -->|Payments API| Payments[Stripe / Razorpay / UPI] |
| 25 | + WebApp -->|Video & Conferencing| Conferencing[Zoom / Google Meet] |
| 26 | + WebApp -->|Email + Webhooks| Messaging[Mailer (SMTP) + Webhooks] |
| 27 | + WebApp -->|Analytics events| Observability[Metrics & Tracing Pipeline] |
| 28 | +
|
| 29 | + Supabase -->|Auth callbacks| WebApp |
| 30 | + SupaFunctions -->|Automation| Supabase |
| 31 | + Payments -->|webhooks| WebApp |
| 32 | + Messaging -->|notifications| Users |
| 33 | +``` |
| 34 | + |
| 35 | +## 2. Container Diagram |
| 36 | +```mermaid |
| 37 | +flowchart TB |
| 38 | + subgraph Client |
| 39 | + NextClient[Next.js Client Components] |
| 40 | + end |
| 41 | + subgraph Server |
| 42 | + NextServer[Next.js Server Components & Route Handlers] |
| 43 | + FeatureFlags[Feature Flag Service] |
| 44 | + Worker[Background Workers (Jobs/Queues)] |
| 45 | + end |
| 46 | + subgraph DataPlane |
| 47 | + SupabaseDB[(Supabase Postgres)] |
| 48 | + Storage[(Supabase Storage)] |
| 49 | + Search[Index & Vector Search] |
| 50 | + end |
| 51 | + subgraph External |
| 52 | + PaymentAPI[Stripe/Razorpay/UPI] |
| 53 | + ConferencingAPI[Zoom/Google Meet] |
| 54 | + EmailAPI[SMTP Provider] |
| 55 | + ObservabilityStack[Telemetry Collector → Dashboard] |
| 56 | + end |
| 57 | +
|
| 58 | + NextClient <--> NextServer |
| 59 | + NextServer -->|SQL/RPC| SupabaseDB |
| 60 | + NextServer --> Storage |
| 61 | + NextServer -->|search queries| Search |
| 62 | + NextServer --> FeatureFlags |
| 63 | + NextServer --> EmailAPI |
| 64 | + NextServer --> ObservabilityStack |
| 65 | + NextServer -->|webhooks| Worker |
| 66 | + Worker --> SupabaseDB |
| 67 | + Worker --> ObservabilityStack |
| 68 | + Worker --> PaymentAPI |
| 69 | + Worker --> ConferencingAPI |
| 70 | + PaymentAPI --> NextServer |
| 71 | + ConferencingAPI --> NextServer |
| 72 | + EmailAPI --> Users |
| 73 | +``` |
| 74 | + |
| 75 | +## 3. Component Diagram (Core Modules) |
| 76 | +```mermaid |
| 77 | +flowchart LR |
| 78 | + subgraph Presentation |
| 79 | + AppRouter[App Router Layouts] |
| 80 | + SpaceShell[Space Shell & Navigation] |
| 81 | + ContentTemplates[Article/Discussion/Q&A/Event Templates] |
| 82 | + ReputationWidgets[XP, Badges, Leaderboards] |
| 83 | + NotificationsPanel[Notification Center] |
| 84 | + end |
| 85 | +
|
| 86 | + subgraph Domain Services |
| 87 | + SpaceService[Spaces Service] |
| 88 | + ContentService[Content Service] |
| 89 | + TaxonomyService[Tags & Search Service] |
| 90 | + ReputationService[Reputation & Privileges] |
| 91 | + ModerationService[Moderation & Safety] |
| 92 | + CommerceService[Donations/Bounties/Events] |
| 93 | + MessagingService[Comments & Direct Messages] |
| 94 | + NotificationService[Notifications & Webhooks] |
| 95 | + end |
| 96 | +
|
| 97 | + subgraph Data Access |
| 98 | + SupabaseClient[Supabase Typed Client] |
| 99 | + FeatureFlagClient[Feature Flag SDK] |
| 100 | + TelemetryClient[Telemetry SDK] |
| 101 | + end |
| 102 | +
|
| 103 | + AppRouter --> SpaceShell |
| 104 | + SpaceShell --> ContentTemplates |
| 105 | + ContentTemplates --> SpaceService |
| 106 | + ContentTemplates --> ContentService |
| 107 | + ContentTemplates --> TaxonomyService |
| 108 | + ContentTemplates --> MessagingService |
| 109 | + ReputationWidgets --> ReputationService |
| 110 | + NotificationsPanel --> NotificationService |
| 111 | +
|
| 112 | + SpaceService --> SupabaseClient |
| 113 | + ContentService --> SupabaseClient |
| 114 | + TaxonomyService --> SupabaseClient |
| 115 | + TaxonomyService --> SearchEngine[Search Index] |
| 116 | + ReputationService --> SupabaseClient |
| 117 | + ModerationService --> SupabaseClient |
| 118 | + CommerceService --> SupabaseClient |
| 119 | + CommerceService --> PaymentGateway[Payment Gateway SDK] |
| 120 | + MessagingService --> SupabaseClient |
| 121 | + NotificationService --> SupabaseClient |
| 122 | + NotificationService --> EmailAPI |
| 123 | +
|
| 124 | + SupabaseClient --> TelemetryClient |
| 125 | + FeatureFlagClient --> AppRouter |
| 126 | +``` |
| 127 | + |
| 128 | +## 4. Key Sequence Diagrams |
| 129 | +### 4.1 Article Publication with Reputation & Notifications |
| 130 | +```mermaid |
| 131 | +sequenceDiagram |
| 132 | + participant C as Creator |
| 133 | + participant UI as Next.js Client |
| 134 | + participant API as Route Handler (Content Service) |
| 135 | + participant DB as Supabase Postgres |
| 136 | + participant Rep as Reputation Service |
| 137 | + participant Notif as Notification Service |
| 138 | +
|
| 139 | + C->>UI: Draft article & click Publish |
| 140 | + UI->>API: POST /api/content (draft_id, publish_at) |
| 141 | + API->>DB: validate permissions + upsert posts, post_versions |
| 142 | + DB-->>API: success |
| 143 | + API->>Rep: record reputation_event(feature_flag="spaces_v1") |
| 144 | + Rep->>DB: insert reputation event & update aggregate |
| 145 | + API->>Notif: enqueue notifications (followers, space members) |
| 146 | + Notif->>DB: insert notification rows & webhooks |
| 147 | + Notif-->>API: queued |
| 148 | + API-->>UI: 202 Created + publish metadata |
| 149 | + UI->>C: Confirmation toast + redirect |
| 150 | +``` |
| 151 | + |
| 152 | +### 4.2 Space Moderation Workflow |
| 153 | +```mermaid |
| 154 | +sequenceDiagram |
| 155 | + participant Mod as Space Moderator |
| 156 | + participant UI as Admin Console |
| 157 | + participant API as Moderation Service |
| 158 | + participant DB as Supabase |
| 159 | + participant Audit as Audit Logger |
| 160 | +
|
| 161 | + Mod->>UI: Review reported post |
| 162 | + UI->>API: POST /api/moderation/resolve {action: "remove", flag_id} |
| 163 | + API->>DB: update report status, post visibility |
| 164 | + API->>Audit: log action with user, role, reason |
| 165 | + Audit->>DB: insert audit_logs entry |
| 166 | + API-->>UI: success response |
| 167 | + UI->>Mod: Display resolution & next steps |
| 168 | +``` |
| 169 | + |
| 170 | +## 5. Architectural Principles |
| 171 | +1. **Feature-flag first:** Every new capability (Spaces, Q&A, Events, Commerce) ships behind env-configurable flags with safe defaults. |
| 172 | +2. **Supabase as system of record:** Postgres tables capture canonical content, community, and commerce data with RLS enforcing role matrix. |
| 173 | +3. **Modular domain services:** Route handlers delegate to typed service modules to keep business logic testable and reusable across server components and workers. |
| 174 | +4. **Telemetry baked in:** Each service emits metrics and traces for the KPIs defined in `/docs/08-observability.md`. |
| 175 | +5. **Reversible migrations:** SQL migrations include down scripts and backfill jobs with resume tokens. |
| 176 | +6. **Zero-trust external integrations:** Payments, conferencing, and email providers communicate through signed webhooks and rotate secrets regularly. |
0 commit comments