How mutaz-alqaimary/bayan works
1. System shape
- Bayan is a Next.js 16 App Router application for Arabic literacy and reading-fluency tracking.
- The repo is organized around locale-prefixed routes and feature modules, with Supabase as the persistent backend.
2. Route topology
- app/[locale]/(auth) contains the public authentication flow: login, register, forgot password, and reset password.
- app/[locale]/(app) contains the authenticated product areas: dashboard, students, teachers, passages, vocabulary, reading sessions, analytics, reports, and settings.
- The root locale shell lives in app/[locale]/layout.tsx, with localized not-found/error boundaries and route-level loading/error states per section.
3. Localization and RTL/LTR boundary
- The app is built for Arabic-first usage with both ar and en.
- Locale negotiation and redirects are handled at the edge/proxy layer in proxy.ts, using next-intl.
- The i18n boundary is enforced through i18n/navigation.ts, i18n/request.ts, and the translation bundles in messages/.
- This is a core architectural boundary because it affects routing, metadata, text direction, and UI composition.
4. Authenticated app shell
- Shared logged-in chrome is assembled from components/layout/ and wrapped by app-level providers in components/providers/.
- The shell includes sidebar/topbar/mobile navigation, theme toggle, locale switcher, user menu, and skip-link/accessibility affordances.
- The shared shell is what gives the product its persistent navigation and responsive behavior across all authenticated sections.
5. Feature-module architecture
- Business functionality is split into domain folders under features/: auth, dashboard, reading, students, teachers, analytics, reporting, and settings.
- Each feature typically owns its own:
- route-facing page component(s),
- UI components,
- data/query helpers,
- schemas/types,
- server actions where needed.
- This is the main modular boundary in the repo: routes are thin, features hold the business logic and presentation for each domain.
6. Data flow to and from Supabase
- Supabase is the system of record, configured through lib/supabase/ and the SQL contract in supabase/schema.sql.
- The codebase distinguishes between:
- browser/client access via the public Supabase client,
- server-side access via server helpers,
- privileged admin access via the service-role client.
- Feature-level actions.ts and queries.ts files are the main path for reading and mutating data, keeping persistence concerns outside the route layer.
7. Auth and session handling
- Authentication is implemented as a dedicated feature plus a callback route at app/api/auth/callback/route.ts.
- features/auth/ contains forms, guards, schema validation, role logic, and auth-related queries/actions.
- This subsystem bridges the browser login forms, Supabase auth/session state, and the protected app routes.
8. Student, reading, and instructional workflows
- features/students/ manages student records plus identity alignment and import/export flows.
- features/reading/ manages passages and vocabulary content, while features/reading/sessions/ handles reading-session execution, review, fluency computation, and session history.
- These modules form the operational core of the platform: content is prepared, sessions are run, then outcomes are stored and later reused for analytics and reporting.
9. Analytics and reporting pipeline
- features/analytics/ aggregates session and reading data into KPIs, cohort trends, student summaries, and charts.
- features/reporting/ turns those same data models into printable/report documents for student or cohort views.
- The architecture here is read-optimized: query/transform code sits apart from visual components so metrics can be reused across dashboard, analytics, and reporting surfaces.
10. Dashboard as a role-sensitive overview layer
- features/dashboard/ provides different summaries for admin, teacher, and student roles.
- The dashboard is not a separate backend; it is a presentation layer over the same domain data, with role-aware variants and reusable stat tiles, sparklines, and activity summaries.
11. Shared UI and design system
- components/ui/ contains the reusable UI primitives used across all features, alongside toast, table, dialog, drawer, select, tabs, and form controls.
- Styling is Tailwind CSS v4 with design tokens in app/globals.css, plus theme management in lib/theme.ts and components/theme-init-script.tsx.
- This layer is the visual foundation beneath the feature modules and helps keep the app consistent across locales and themes.
12. Cross-cutting libraries and runtime concerns
- lib/ holds reusable infrastructure: formatting, route constants, validation helpers, fonts, motion, errors, site URL handling, and avatar/collation utilities.
- instrumentation.ts and test scaffolding under test/ support runtime observability and verification.
- The repo also includes SEO and platform surfaces such as app/robots.ts and app/sitemap.ts.
13. Testing and quality boundaries
- Tests are colocated with features for domain logic, schema validation, and UI behavior, with additional integration and smoke coverage under test/.
- This suggests a design where architecture is validated at the module boundary: parsing, aggregation, auth roles, reporting metadata, import classification, and fluency calculations are all treated as distinct units.
14. Documentation and governance
- The docs/phases/ and docs/project/ folders track the intended architecture and rollout history.
- The .claude/rules/ and supporting docs indicate the repository has strong conventions around schema, RTL/i18n, accessibility, and design-system consistency.
- For a diagram, treat these as governance artifacts around the codebase rather than runtime subsystems.
Main entry points: client.ts Supabase stack · button.tsx UI system · layout.tsx Locale shell · actions.ts Auth feature
Components 20
App routes
Locale-scoped App Router surfaces for public auth and authenticated product areas.
- Locale shell · Root locale-aware App Router shell, with per-locale not-found and route boundaries.
app/[locale]/layout.tsx - Auth routes · Public login, register, forgot-password, and reset-password routes.
app/[locale]/(auth)/login/page.tsx - Product routes · Authenticated sections for dashboard, students, teachers, passages, vocabulary, sessions, analytics, reports, and settings.
app/[locale]/(app)/dashboard/page.tsx - Auth callback · Supabase auth callback endpoint that completes session handling.
app/api/auth/callback/route.ts
Feature modules
Domain modules that hold business logic, UI, queries, actions, and schemas.
- Auth feature · Forms, guards, roles, schemas, queries, and actions for authentication and session state.
features/auth/actions.ts - Dashboard · Role-sensitive dashboard summaries and shared KPI/insight components.
features/dashboard/components/admin-dashboard.tsx - Students · Student records, roster management, identity alignment, and import/export workflows.
features/students/actions.ts - Teachers · Teacher management with promotion and demotion flows.
features/teachers/actions.ts - Reading content · Passages and vocabulary content management for instructional workflows.
features/reading/actions.ts - Reading sessions · Session execution, review, fluency computation, and history.
features/reading/sessions/actions.ts - Analytics · Aggregation and visualization of cohort, student, and reading metrics.
features/analytics/aggregate.ts - Reporting · Printable report generation over shared student and cohort data.
features/reporting/queries.ts - Settings · User profile and app settings forms, actions, and schemas.
features/settings/actions.ts
Infrastructure
Shared runtime services for localization, Supabase, UI shell, and cross-cutting utilities.
- Locale proxy · Locale negotiation and redirect boundary using next-intl.
proxy.ts - I18n core · Localized navigation and request resolution plus translation bundles.
i18n/navigation.ts - App shell · Shared authenticated chrome and responsive navigation wrapper.
components/layout/app-shell.tsx - Providers · Theme, motion, and app-wide context providers.
components/providers/app-providers.tsx - UI system · Reusable UI primitives and toasts used across features.
components/ui/button.tsx - Supabase stack · Client, server, admin, and proxy helpers for Supabase access plus schema contract.
lib/supabase/client.ts - Shared libs · Cross-cutting utilities for formatting, routes, validation, errors, theme, fonts, and observability.
lib/routes.ts
Connections 23
- Locale proxy → I18n core: negotiates locale · Edge layer redirects and resolves locale-prefixed routes.
- I18n core → Locale shell: feeds routing · Localized routing and request config drive the app shell.
- Locale shell → Auth routes: wraps · Locale layout contains the public auth section.
- Locale shell → Product routes: wraps · Locale layout contains the authenticated product area.
- Locale shell → Auth callback: supports auth · Locale/session flow is completed through the auth callback route.
- Product routes → App shell: renders chrome · Authenticated routes are displayed inside the shared shell.
- App shell → Providers: uses · Shell is composed under app-wide providers.
- App shell → UI system: composes · Shell uses shared UI primitives for navigation and controls.
- Auth routes → Auth feature: uses · Auth pages are thin route surfaces over the auth module.
- Auth callback → Supabase stack: completes session · Callback exchanges auth state through Supabase helpers.
- Auth feature → Supabase stack: auth data · Authentication queries and actions use Supabase clients.
- Auth feature → Shared libs: validates and guards · Roles, schema messages, and guards depend on shared utilities.
- Dashboard → Supabase stack: reads metrics · Dashboard summaries are built from domain data queried through Supabase.
- Students → Supabase stack: manages roster · Student CRUD, identity, and import/export flows persist through Supabase.
- Reading content → Supabase stack: manages content · Passages and vocabulary are stored and queried via Supabase.
- Reading sessions → Supabase stack: stores sessions · Reading sessions and fluency outcomes are persisted in Supabase.
- Analytics → Supabase stack: aggregates data · Analytics queries pull from session and reading records.
- Reporting → Supabase stack: builds reports · Reporting reads the same operational data for printable outputs.
- Settings → Supabase stack: updates profile · Settings actions and queries persist user configuration through Supabase.
- Dashboard → UI system: charts and cards · Dashboard views are built from shared UI primitives.
- Analytics → UI system: visualizes · Analytics components rely on shared charts, tabs, tables, and feedback states.
- Reporting → UI system: prints and layouts · Reporting uses shared controls and document layout primitives.
- Students → UI system: tables and dialogs · Student workflows are implemented with shared tables, drawers, and forms.