# mrkat303/hiveyoung-app architecture

> Architecture diagram of the GitHub repository mrkat303/hiveyoung-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mrkat303/hiveyoung-app
- Repository: https://github.com/mrkat303/hiveyoung-app

## Overview

1. **Top-level architecture**
This is a Next.js App Router application with a fairly rich client-side UI, a small set of server API routes, and a Supabase-backed data layer. The repository is organized by product area rather than by technical layer, which makes each domain easy to identify: profile, members/teams, ecosystem/contacts/schools/universities, calendar, workflows, assistant, onboarding, settings, and login.

2. **Primary runtime boundary**
The `app/` directory is the main execution surface. Route segments such as `app/(app)/profile`, `members`, `ecosystem`, `assistant`, and `workflows` each own their page entrypoints and feature-specific UI. Shared layout behavior lives in `app/layout.tsx` and `app/(app)/layout.tsx`, while global styling is split across `app/globals.css` and feature CSS files. This suggests a mostly client-rendered interactive dashboard with route-level composition.

3. **Domain-driven UI subsystems**
Each major feature area has its own component cluster:
- **Profile**: profile editing, radar/skills, social links, sections for experience/education/certificates/volunteering.
- **Members / Teams**: team listing and team detail views.
- **Ecosystem**: contact management plus schools and universities, including detail pages and create/edit modals.
- **Assistant**: chat UI, wizard cards, previews, and artifact panels.
- **Workflows**: workflow diagram visualization.
- **Calendar**: event-focused page.
- **Onboarding / Settings / Login**: lifecycle and account configuration surfaces.
These areas are isolated enough that an architecture diagram should treat them as separate feature domains fed by shared infrastructure.

4. **Shared application shell**
The app shell is composed from reusable UI and navigation utilities in `app/(app)/_components/Shared`, including sidebar, topbar, mobile nav, notifications drawer, onboarding guard, and floating assistant entry point. These components define the cross-cutting frame around the feature pages and likely mediate global state such as notifications, routing, and access/onboarding gating.

5. **State management and client hooks**
Feature state is abstracted into React contexts and hooks rather than a centralized store. `contexts/` includes notification, profile, and toast providers. `hooks/` contains domain hooks for calendar events, contacts, kanban, profile, schools, universities, and toast. This points to a pattern where pages and modals consume data through hook-based queries/mutations, while contexts provide app-wide UI state and feedback.

6. **Supabase as the system of record**
The `supabase/schema` directory is a major architectural boundary. It contains table definitions for profiles, teams, team membership, tasks, comments, dependencies, subtasks, notifications, contacts, schools, universities, calendar events, system settings, and AI workflows. The schema also includes row-level security policies, realtime configuration, functions, and triggers, indicating that business rules are enforced both in the application and in the database.

7. **Database-driven business logic**
Several database functions and triggers encode core behavior:
- user onboarding and welcome handling
- school update notifications
- task assignment, comment, status, and subtask notifications
- task progress recalculation and timestamp updates
- permission checks such as admin/director/executive/participant and team management predicates
This means the backend architecture is not just CRUD; it pushes authorization, notifications, and derived state into PostgreSQL/Supabase.

8. **AI subsystem**
The `utils/ai` tree is a distinct subsystem with its own orchestration, agents, tools, prompts, permissions, and provider abstractions. There are specialized agents for assistant, planner, scout, editor, comms, member-scout, notion-writer, and an orchestrator layer coordinating them. This is the most service-like part of the repo and should be diagrammed as a separate intelligent workflow engine rather than embedded UI logic.

9. **AI-facing API routes**
The `app/api/ecosystem/ai` endpoints bridge the UI and the AI/data backends. They include generic AI handling plus dedicated routes for publishing to Notion, sending email, and returning ecosystem data. There is also a `app/api/radar/search` route for search-related functionality. These routes are the server boundary where browser requests are converted into tool-using AI actions or search responses.

10. **Tooling layer for AI and integrations**
`utils/ai/tools` exposes structured capabilities used by agents: DB access, ecosystem operations, editor actions, communications, Notion integration, schemas, and handlers. This makes the AI subsystem operate through controlled tools rather than direct UI coupling. The architecture likely routes model outputs through tool contracts and permission checks before mutating data or calling external services.

11. **External service boundaries**
The repo materially depends on:
- **Supabase** for auth, database, realtime, and server/client access
- **Notion** for publishing content/workflow artifacts
- **Email delivery** for notifications or outreach
- Potentially **OpenAI or another model provider** through the AI provider abstraction
These integrations are concentrated in the AI tool and API route layers, keeping the rest of the app mostly domain/UI focused.

12. **Authentication and request mediation**
`middleware.ts` and `utils/supabase/middleware.ts` indicate request-time auth/session handling at the edge or middleware layer. Combined with `utils/supabase/server.ts` and `utils/supabase/client.ts`, the app distinguishes server-side, client-side, and middleware Supabase access paths. That separation is important for the diagram because it defines how authenticated state reaches pages, APIs, and protected routes.

13. **UI composition model**
The repository uses many modal and panel components for editing entity data in place: profile modals, school/contact modals, task detail modals, team modals, and assistant artifact cards. This suggests the core UX is a single-page dashboard with nested dialogs and side panels layered over route pages, rather than full page transitions for every edit flow.

14. **What to emphasize in an architecture diagram**
The cleanest diagram would show:
- browser/UI routes in Next.js App Router
- shared shell and feature pages
- React hooks/contexts as the client state and data access layer
- Supabase/Postgres as the authoritative backend with RLS, triggers, and realtime
- a distinct AI orchestration subsystem with tools and specialized agents
- external integrations for Notion and email reached through API routes and tools
That captures the real boundaries and data flow in this repo without over-describing implementation details.

Main entry points: [`app/(app)/layout.tsx`](https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/layout.tsx) (Dashboard shell), [`hooks/useProfile.ts`](https://github.com/mrkat303/hiveyoung-app/blob/main/hooks/useProfile.ts) (Domain hooks), [`utils/ai/tools/index.ts`](https://github.com/mrkat303/hiveyoung-app/blob/main/utils/ai/tools/index.ts) (AI tools), [`utils/supabase/server.ts`](https://github.com/mrkat303/hiveyoung-app/blob/main/utils/supabase/server.ts) (Supabase client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_app["Next.js app"]
  node_node_root["App Router<br/>next.js app<br/>[layout.tsx]"]
  node_node_shell["Dashboard shell<br/>shared layout<br/>[layout.tsx]"]
  node_node_profile["Profile<br/>feature area<br/>[page.tsx]"]
  node_node_members["Members<br/>feature area<br/>[page.tsx]"]
  node_node_ecosystem["Ecosystem<br/>feature area<br/>[page.tsx]"]
  node_node_assistant["Assistant UI<br/>feature area<br/>[page.tsx]"]
  node_node_workflows["Workflows<br/>feature area<br/>[page.tsx]"]
  node_node_calendar["Calendar<br/>feature area<br/>[page.tsx]"]
  node_node_onboarding["Onboarding<br/>lifecycle page<br/>[page.tsx]"]
  node_node_settings["Settings<br/>account page<br/>[page.tsx]"]
  node_node_login["Login<br/>auth page<br/>[page.tsx]"]
  node_node_api_ai["AI API<br/>server routes<br/>[route.ts]"]
  node_node_api_data["AI data<br/>api route<br/>[route.ts]"]
  node_node_api_notion["Notion publish<br/>api route<br/>[route.ts]"]
  node_node_api_email["Email send<br/>api route<br/>[route.ts]"]
  node_node_api_search["Radar search<br/>api route<br/>[route.ts]"]
end

subgraph group_grp_ai["AI subsystem"]
  node_node_ai_orch{{"AI orchestrator<br/>agent runtime<br/>[orchestrator.ts]"}}
  node_node_ai_agents{{"Specialist agents<br/>[orchestrator.ts]"}}
  node_node_ai_tools{{"AI tools<br/>tooling<br/>[index.ts]"}}
  node_node_ai_perms{{"AI permissions<br/>policy layer<br/>[permissions.ts]"}}
end

subgraph group_grp_db["Supabase schema"]
  node_node_schema[("Database schema<br/>postgres schema<br/>[policies.sql]")]
end

subgraph group_grp_infra["Client infra"]
  node_node_supabase["Supabase client<br/>data access<br/>[server.ts]"]
  node_node_middleware["Auth middleware<br/>request mediation<br/>[middleware.ts]"]
  node_node_hooks["Domain hooks<br/>client data hooks<br/>[useProfile.ts]"]
  node_node_contexts["App contexts<br/>ui state"]
end

node_node_root -->|"wraps"| node_node_shell
node_node_root -->|"routes to"| node_node_login
node_node_shell -->|"navigates"| node_node_profile
node_node_shell -->|"navigates"| node_node_members
node_node_shell -->|"navigates"| node_node_ecosystem
node_node_shell -->|"navigates"| node_node_assistant
node_node_shell -->|"navigates"| node_node_workflows
node_node_shell -->|"navigates"| node_node_calendar
node_node_shell -->|"gates"| node_node_onboarding
node_node_shell -->|"navigates"| node_node_settings
node_node_shell -->|"consumes"| node_node_contexts
node_node_profile -->|"reads"| node_node_hooks
node_node_members -->|"reads"| node_node_hooks
node_node_ecosystem -->|"reads"| node_node_hooks
node_node_calendar -->|"reads"| node_node_hooks
node_node_api_ai -->|"invokes"| node_node_ai_orch
node_node_api_ai -->|"uses"| node_node_ai_tools
node_node_api_data -->|"serves"| node_node_ai_tools
node_node_api_notion -->|"publishes via"| node_node_ai_tools
node_node_api_email -->|"sends via"| node_node_ai_tools
node_node_api_search -->|"supports"| node_node_hooks
node_node_ai_orch -->|"coordinates"| node_node_ai_agents
node_node_ai_orch -->|"checks"| node_node_ai_perms
node_node_ai_agents -->|"calls"| node_node_ai_tools
node_node_ai_tools -->|"queries"| node_node_supabase
node_node_ai_tools -->|"targets"| node_node_schema
node_node_supabase -->|"backed by"| node_node_schema
node_node_middleware -->|"initializes"| node_node_supabase
node_node_hooks -->|"fetches from"| node_node_supabase
node_node_contexts -.->|"pairs with"| node_node_hooks
node_node_schema -.->|"feeds"| node_node_hooks

click node_node_root "https://github.com/mrkat303/hiveyoung-app/blob/main/app/layout.tsx"
click node_node_shell "https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/layout.tsx"
click node_node_profile "https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/profile/page.tsx"
click node_node_members "https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/members/page.tsx"
click node_node_ecosystem "https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/ecosystem/page.tsx"
click node_node_assistant "https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/assistant/page.tsx"
click node_node_workflows "https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/workflows/page.tsx"
click node_node_calendar "https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/calendar/page.tsx"
click node_node_onboarding "https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/onboarding/page.tsx"
click node_node_settings "https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/settings/page.tsx"
click node_node_login "https://github.com/mrkat303/hiveyoung-app/blob/main/app/login/page.tsx"
click node_node_api_ai "https://github.com/mrkat303/hiveyoung-app/blob/main/app/api/ecosystem/ai/route.ts"
click node_node_api_data "https://github.com/mrkat303/hiveyoung-app/blob/main/app/api/ecosystem/ai/data/route.ts"
click node_node_api_notion "https://github.com/mrkat303/hiveyoung-app/blob/main/app/api/ecosystem/ai/notion-publish/route.ts"
click node_node_api_email "https://github.com/mrkat303/hiveyoung-app/blob/main/app/api/ecosystem/ai/send-email/route.ts"
click node_node_api_search "https://github.com/mrkat303/hiveyoung-app/blob/main/app/api/radar/search/route.ts"
click node_node_ai_orch "https://github.com/mrkat303/hiveyoung-app/blob/main/utils/ai/orchestrator.ts"
click node_node_ai_agents "https://github.com/mrkat303/hiveyoung-app/blob/main/utils/ai/agents/orchestrator.ts"
click node_node_ai_tools "https://github.com/mrkat303/hiveyoung-app/blob/main/utils/ai/tools/index.ts"
click node_node_ai_perms "https://github.com/mrkat303/hiveyoung-app/blob/main/utils/ai/permissions.ts"
click node_node_supabase "https://github.com/mrkat303/hiveyoung-app/blob/main/utils/supabase/server.ts"
click node_node_middleware "https://github.com/mrkat303/hiveyoung-app/blob/main/middleware.ts"
click node_node_hooks "https://github.com/mrkat303/hiveyoung-app/blob/main/hooks/useProfile.ts"
click node_node_contexts "https://github.com/mrkat303/hiveyoung-app/blob/main/contexts/NotificationContext.tsx"
click node_node_schema "https://github.com/mrkat303/hiveyoung-app/blob/main/supabase/schema/policies.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_root,node_node_shell,node_node_profile,node_node_members,node_node_ecosystem,node_node_assistant,node_node_workflows,node_node_calendar,node_node_onboarding,node_node_settings,node_node_login,node_node_api_ai,node_node_api_data,node_node_api_notion,node_node_api_email,node_node_api_search toneBlue
class node_node_ai_orch,node_node_ai_agents,node_node_ai_tools,node_node_ai_perms toneAmber
class node_node_schema toneMint
class node_node_supabase,node_node_middleware,node_node_hooks,node_node_contexts toneRose
```

## Components

### Next.js app

Route-driven UI, shared shell, and API entrypoints.

- [App Router](https://github.com/mrkat303/hiveyoung-app/blob/main/app/layout.tsx): next.js app · Main browser-facing application surface built with Next.js App Router. · `app/layout.tsx`
- [Dashboard shell](https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/layout.tsx): shared layout · Authenticated app frame with sidebar, topbar, mobile nav, onboarding guard, and notifications. · `app/(app)/layout.tsx`
- [Profile](https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/profile/page.tsx): feature area · Profile editing, radar, social links, and member profile detail views. · `app/(app)/profile/page.tsx`
- [Members](https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/members/page.tsx): feature area · Team listing and team detail pages for member organization. · `app/(app)/members/page.tsx`
- [Ecosystem](https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/ecosystem/page.tsx): feature area · Contacts, schools, and universities management surfaces. · `app/(app)/ecosystem/page.tsx`
- [Assistant UI](https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/assistant/page.tsx): feature area · Chat-driven assistant experience with artifacts, previews, and wizard cards. · `app/(app)/assistant/page.tsx`
- [Workflows](https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/workflows/page.tsx): feature area · Workflow visualization and diagramming surface. · `app/(app)/workflows/page.tsx`
- [Calendar](https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/calendar/page.tsx): feature area · Event-focused calendar page. · `app/(app)/calendar/page.tsx`
- [Onboarding](https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/onboarding/page.tsx): lifecycle page · User onboarding and setup flow. · `app/(app)/onboarding/page.tsx`
- [Settings](https://github.com/mrkat303/hiveyoung-app/blob/main/app/(app)/settings/page.tsx): account page · Application and account configuration surface. · `app/(app)/settings/page.tsx`
- [Login](https://github.com/mrkat303/hiveyoung-app/blob/main/app/login/page.tsx): auth page · Authentication entry page. · `app/login/page.tsx`
- [AI API](https://github.com/mrkat303/hiveyoung-app/blob/main/app/api/ecosystem/ai/route.ts): server routes · API boundary for ecosystem AI requests and orchestration. · `app/api/ecosystem/ai/route.ts`
- [AI data](https://github.com/mrkat303/hiveyoung-app/blob/main/app/api/ecosystem/ai/data/route.ts): api route · AI-facing data endpoint for ecosystem context and retrieval. · `app/api/ecosystem/ai/data/route.ts`
- [Notion publish](https://github.com/mrkat303/hiveyoung-app/blob/main/app/api/ecosystem/ai/notion-publish/route.ts): api route · Server route for publishing AI-generated content to Notion. · `app/api/ecosystem/ai/notion-publish/route.ts`
- [Email send](https://github.com/mrkat303/hiveyoung-app/blob/main/app/api/ecosystem/ai/send-email/route.ts): api route · Server route for sending emails from AI-assisted flows. · `app/api/ecosystem/ai/send-email/route.ts`
- [Radar search](https://github.com/mrkat303/hiveyoung-app/blob/main/app/api/radar/search/route.ts): api route · Search endpoint used by radar-related UI. · `app/api/radar/search/route.ts`

### AI subsystem

Agents, tools, and request handlers for AI-assisted workflows.

- [AI orchestrator](https://github.com/mrkat303/hiveyoung-app/blob/main/utils/ai/orchestrator.ts): agent runtime · Coordinates specialized agents and execution flow. · `utils/ai/orchestrator.ts`
- [Specialist agents](https://github.com/mrkat303/hiveyoung-app/blob/main/utils/ai/agents/orchestrator.ts): agents · Assistant, planner, scout, editor, comms, member-scout, notion-writer agents. · `utils/ai/agents/orchestrator.ts`
- [AI tools](https://github.com/mrkat303/hiveyoung-app/blob/main/utils/ai/tools/index.ts): tooling · Controlled capabilities for DB, ecosystem, editor, comms, schemas, and handlers. · `utils/ai/tools/index.ts`
- [AI permissions](https://github.com/mrkat303/hiveyoung-app/blob/main/utils/ai/permissions.ts): policy layer · Permission and capability checks for AI actions. · `utils/ai/permissions.ts`

### Supabase schema

Postgres tables, functions, triggers, and policies.

- [Database schema](https://github.com/mrkat303/hiveyoung-app/blob/main/supabase/schema/policies.sql): postgres schema · Tables, policies, realtime, functions, and triggers defining system behavior. · `supabase/schema/policies.sql`

### Client infra

Auth/session mediation and shared data-access utilities.

- [Supabase client](https://github.com/mrkat303/hiveyoung-app/blob/main/utils/supabase/server.ts): data access · Browser, server, and middleware Supabase access paths. · `utils/supabase/server.ts`
- [Auth middleware](https://github.com/mrkat303/hiveyoung-app/blob/main/middleware.ts): request mediation · Edge and request-time session handling for protected routes. · `middleware.ts`
- [Domain hooks](https://github.com/mrkat303/hiveyoung-app/blob/main/hooks/useProfile.ts): client data hooks · React hooks for calendar, contacts, kanban, profile, schools, universities, and toast. · `hooks/useProfile.ts`
- [App contexts](https://github.com/mrkat303/hiveyoung-app/blob/main/contexts/NotificationContext.tsx): ui state · Notification, profile, and toast providers for shared client state. · `contexts/NotificationContext.tsx`

## Connections

- App Router → Dashboard shell: wraps · Root layout composes the authenticated application shell.
- App Router → Login: routes to · Unauthenticated access reaches the login surface.
- Dashboard shell → Profile: navigates · Shared shell frames the profile domain.
- Dashboard shell → Members: navigates · Shared shell frames the members domain.
- Dashboard shell → Ecosystem: navigates · Shared shell frames the ecosystem domain.
- Dashboard shell → Assistant UI: navigates · Shared shell frames the assistant domain.
- Dashboard shell → Workflows: navigates · Shared shell frames the workflows domain.
- Dashboard shell → Calendar: navigates · Shared shell frames the calendar domain.
- Dashboard shell → Onboarding: gates · Onboarding guard can redirect users into setup flows.
- Dashboard shell → Settings: navigates · Shared shell frames settings.
- Dashboard shell → App contexts: consumes · Shell-level UI state comes from shared contexts.
- Profile → Domain hooks: reads · Profile pages use domain hooks for data and mutations.
- Members → Domain hooks: reads · Members and team pages use shared hooks for data access.
- Ecosystem → Domain hooks: reads · Contacts and school views rely on domain hooks.
- Calendar → Domain hooks: reads · Calendar data is fetched through hook abstractions.
- AI API → AI orchestrator: invokes · AI API routes hand off work to the orchestration layer.
- AI API → AI tools: uses · API handlers expose controlled tool execution.
- AI data → AI tools: serves · Data endpoint supplies AI-compatible ecosystem context.
- Notion publish → AI tools: publishes via · Notion publishing is mediated through AI tools.
- Email send → AI tools: sends via · Email delivery is mediated through AI tools.
- Radar search → Domain hooks: supports · Search endpoint backs radar-related client behavior.
- AI orchestrator → Specialist agents: coordinates · Orchestrator delegates to specialized agents.
- AI orchestrator → AI permissions: checks · Orchestration is constrained by AI permissions.
- Specialist agents → AI tools: calls · Agents act through structured tools rather than direct access.
- AI tools → Supabase client: queries · Tools read and mutate repository data through Supabase.
- AI tools → Database schema: targets · Tools operate against schema-defined entities and functions.
- Supabase client → Database schema: backed by · Client and server access paths connect to the Supabase schema.
- Auth middleware → Supabase client: initializes · Middleware handles session/auth plumbing for Supabase.
- Domain hooks → Supabase client: fetches from · Domain hooks use Supabase for client-side data operations.
- App contexts → Domain hooks: pairs with · Shared contexts complement hook-driven data flows and feedback.
- Database schema → Domain hooks: feeds · Tables, triggers, and policies shape what the client can observe.
