am-crm

Front-End Architecture & Page Specifications

Goals

Provide a coherent, role-aware Next.js App Router front-end that:

Tech Stack (Web)

Concern Choice Notes
Framework Next.js (App Router) Server Components where possible; client islands for interactivity.
Styling Tailwind CSS + Radix UI Utility-first + accessible primitives.
Data Fetch tRPC (planned) / REST placeholder Transition path: keep fetch layer abstracted.
Auth Auth.js (email magic link) Session available server-side for role gating.
State React Query (TanStack Query) Cache server data, optimistic updates for logs/forms.
Forms React Hook Form + Zod resolver Shared <Form /> wrapper with field components.
Charts (post-mvp) Chart.js or Recharts For unit metrics & attention trends.
Testing Vitest / Testing Library / Playwright (E2E) Focus on critical flows: login, log contact, add initiation.

Architectural Layers

/app               # Route segments & RSC boundaries
  (public)/        # Unauthenticated pages (marketing / sign-in)
  (auth)/          # Authenticated shell (layout with nav, role-based)
    dashboard/     # Personalized landing (role adaptive)
    mentees/       # Mentor-focused list & detail
    users/         # Admin user management (existing)
    units/         # Admin / secretary unit mgmt
    initiation/    # Acarya flows
    lessons/       # Lesson progression
    attention/     # Attention engine list
    profile/       # User self profile
    link-telegram/ # Account linking flow
    settings/      # Personal + notification prefs (post-mvp)
  api/             # Route handlers (if any; tRPC preferred)
/components        # Presentational + interactive components
/lib               # Client utils (auth, fetch wrappers, hooks)
/hooks             # Reusable data hooks (useMentees, useUnitMetrics)
/styles            # Tailwind config, globals

Shared Component Primitives

Component Purpose Notes
LayoutShell Top nav + side nav + content container Injects role-based nav sections.
RoleGuard Conditionally render children based on traits/roles Server component for early bail; client variant for conditional UI.
DataTable Generic table with columns, sorting, empty state Wraps TanStack Table.
EntityCard Quick summary (user, mentee, unit) Small consistent card style.
StatTile Metric w/ delta Unit dashboard, mentor overview.
Timeline Chronological events (contacts, lessons) Reusable for user detail view.
ContactLogForm 30s contact logging UI Inline + modal modes.
LessonProgressForm Manage lesson entries Validation: sequential constraint.
InitiationForm Capture initiation event Role restricted (acarya).
PracticeStatusWidget Display + inline update regularity Color-coded severity.
AttentionBadge Compute and display attention state Derives rule or consumes precomputed flag.
InviteUserForm Mentor invite or admin user add Extends existing create user.
TelegramLinkPanel Guides linking flow Polling state of link.
AuditTrailList (post-mvp) Show audited actions Admin only.

Primary navigation is role-aware; each persona lands on tailored dashboard slice:

Role Default Landing Key Nav Sections
Seeker /dashboard (mentor + next lesson panel) Dashboard, Lessons, Profile, Link Telegram
Mentor /mentees Mentees, Dashboard, Attention, Lessons (overview), Profile
Unit Secretary /units Units, Dashboard, Mentor Load, Attention
Acarya /initiation Initiations, Lessons, Dashboard, Attention
Admin /users Users, Units, Roles, Audit (post-mvp), Settings

A composite user with multiple roles sees merged sections.

Page / Route Specifications (MVP & Immediate Post-MVP)

Each entry lists: Purpose, Key Components, Data Dependencies, Covered User Stories (tag). If post-MVP, flagged accordingly.

1. / (redirect to /dashboard or public landing)

2. /dashboard

3. /profile

5. /mentees

6. /mentees/[id]

7. /users (already exists - refine)

8. /units

9. /initiation

10. /lessons

11. /attention (post-MVP early)

12. /contact/new (maybe modal route under mentees)

13. /roles (admin)

14. /reports/unit (secretary, post-mvp)

15. Future Modules (Placeholders /feature/* or behind feature flags)

Component-to-Story Mapping Matrix (MVP)

Story Component(s) Route(s)
Register & create minimal profile ProfileForm (public sign-in flow) / (signup), /profile
View assigned mentor & acarya contacts MentorInfoCard /profile
See received lessons & next step LessonProgressSummary, SeekerNextStepCard /dashboard, /profile
View mentee list indicators DataTable, PracticeStatusWidget, AttentionBadge /mentees
Log contact <30s ContactLogForm (quick), QuickAddContact /mentees, /contact/new, /mentees/[id]
Reminders for inactivity AttentionBadge + AttentionList /dashboard, /mentees
Invite new person InviteUserForm / QuickInvite /mentees, /users
View unit metrics StatTile, UnitSecretaryMetrics, UnitsList /dashboard, /units
Record initiation events InitiationForm /initiation
Update lesson progression LessonProgressTable, AddLessonProgressForm /lessons, /mentees/[id]
View initiated margiis w/ status InitiationEventsTable /initiation
Assign/remove traits & roles TraitAssignmentPanel, UserTraitMatrix /users, /roles
Create units & set secretary CreateUnitForm, UnitSecretaryAssignmentForm /units
Link Telegram account TelegramLinkPanel /profile, /link-telegram

Data Fetching & Caching Strategy

Access Control Patterns

Performance & UX Considerations

Styling & Design Tokens (Planned)

Testing Strategy (MVP focus)

Layer Tests
Unit Pure utils (attention calculations)
Component ContactLogForm, LessonProgressForm validation
Integration Mentor logs contact -> shows in mentee detail timeline
E2E (Playwright) Sign-in, create unit, assign secretary, link mentor->mentee, log contact

Migration Plan from Current State

  1. Introduce LayoutShell + navigation; wrap existing pages (/users, /identity evolves into /units + split responsibilities).
  2. Add /dashboard (empty scaffold) & /profile.
  3. Implement /mentees list (replace manual identity combos for mentors).
  4. Add forms for contact logs & practice status.
  5. Implement initiation & lessons pages for acarya workflows.
  6. Build attention derivation endpoint + /attention (post-MVP step once rule engine ready).

Open Questions

Future Enhancements (Non-MVP)