# uniestetic/conectando-ph architecture

> Architecture diagram of the GitHub repository uniestetic/conectando-ph, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/uniestetic/conectando-ph
- Repository: https://github.com/uniestetic/conectando-ph

## Overview

1. This is a Next.js App Router application in TypeScript, organized around route segments in `app/`. The repo is structured more like a role-based product shell than a single feature app: `admin`, `residentes`, and `porteria` are separate user-facing domains, with `auth/login` as the entry point.

2. The main architectural boundary is between route/page components and the service layer. Pages and UI components live under `app/...`, while domain data access is centralized under `app/services/*` and `app/utils/apiClient.ts`. That makes the app mostly a frontend orchestration layer over backend APIs.

3. Authentication is handled through NextAuth. The auth endpoint lives at `app/api/auth/[...nextauth]`, with shared auth configuration in `auth.config.ts`. Login/logout UI is under `app/auth/login`, and `middleware.ts` likely protects role-based routes and redirects unauthenticated users.

4. Role-based navigation is a key design axis. The app has distinct areas for administrators, residents, and security/front-desk staff:
   - `app/admin/*` for management CRUD
   - `app/residentes/*` for resident self-service
   - `app/porteria/*` for gate/security workflows
   This is the clearest architectural partition in the repo.

5. The admin subsystem covers master data and operational back-office features: copropiedades, unidades, usuarios, roles, asambleas, comunicados, documentos, formación, pqrs, porteria, and visitantes. Most of these routes have create/edit subpages, indicating a CRUD-heavy domain model with reusable forms and listing screens.

6. Property context is an important cross-cutting concept. Components such as `PropertySelector`, `HeaderPropertySelector`, `PropertyManager`, and the hook `usePropertySelector` suggest the app operates across multiple properties/copropiedades and needs the current property to scope data and UI behavior.

7. The assembly / meeting room is the most specialized subsystem. Under `app/residentes/room` there is a dedicated `AssemblyInterface` plus cards for agenda, attendance, messages, users online, shared files, request-to-speak, video, and recording controls. This is a real-time collaboration area rather than a standard form-based screen.

8. Real-time collaboration is backed by LiveKit and socket-style messaging. `app/services/livekit.service.ts`, `app/actions/livekit.ts`, `app/services/socket.service.tsx`, and hooks like `useVotes` and `useVotingQuestions` indicate the assembly room coordinates media, chat/events, voting, and participant state through realtime channels.

9. File and document handling is also first-class. There is an upload API route at `app/api/uploads/route.ts`, static/public storage under `public/uploads`, and document-oriented sections in admin and resident areas. This suggests the app moves documents and media between user actions, backend APIs, and uploaded asset storage.

10. The service layer is domain-based and maps closely to business entities: assemblies, agenda, attendances, announcements, votes, voting questions, users, roles, units, unit assignments, PHs/copropiedades, and Q&A entries. This layer is the main integration boundary to backend data sources and keeps page components relatively thin.

11. Shared presentation is split between `app/components` and `app/ui`. `app/components` holds app-specific reusable widgets like selectors, cards, headers, modals, and toggles; `app/ui` contains more atomic design-system-style primitives, global styles, fonts, and generic skeleton/loading components.

12. Types are centralized in `app/types`, with one declaration file per domain. That implies the app relies on explicit domain models rather than inferred API shapes, which is useful for drawing the data model side of the architecture diagram.

13. Infrastructure-wise, this is a browser-facing Next.js frontend with server-side route handlers/actions where needed, role-aware routing, backend API integration, realtime services for assemblies, and asset uploads. It does not appear to be a standalone backend; instead it sits as the presentation and interaction layer over external application services.

Main entry points: [`app/admin/page.tsx`](https://github.com/uniestetic/conectando-ph/blob/master/app/admin/page.tsx) (Admin area), [`app/page.tsx`](https://github.com/uniestetic/conectando-ph/blob/master/app/page.tsx) (Next.js app), [`app/services/auth.service.ts`](https://github.com/uniestetic/conectando-ph/blob/master/app/services/auth.service.ts) (Service layer), [`app/residentes/page.tsx`](https://github.com/uniestetic/conectando-ph/blob/master/app/residentes/page.tsx) (Residents area)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_app["App shell"]
  node_node_root["Next.js app<br/>app router frontend<br/>[page.tsx]"]
  node_node_auth["Auth flow<br/>nextauth + login<br/>[page.tsx]"]
  node_node_middleware{{"Route guard<br/>middleware<br/>[middleware.ts]"}}
end

subgraph group_grp_domains["Role domains"]
  node_node_admin["Admin area<br/>back-office routes<br/>[page.tsx]"]
  node_node_admin_props["Properties<br/>copropiedades + unidades<br/>[page.tsx]"]
  node_node_admin_users["Users & roles<br/>identity management<br/>[page.tsx]"]
  node_node_admin_assembly["Assemblies<br/>meeting admin<br/>[page.tsx]"]
  node_node_admin_content["Content ops<br/>documents + notices<br/>[page.tsx]"]
  node_node_residents["Residents area<br/>self-service routes<br/>[page.tsx]"]
  node_node_room{{"Assembly room<br/>realtime collaboration<br/>[page.tsx]"}}
  node_node_gate["Porteria area<br/>security workflows<br/>[page.tsx]"]
end

subgraph group_grp_platform["Platform layer"]
  node_node_property["Property context<br/>selector + state"]
  node_node_shell["Shared UI<br/>reusable components<br/>[Providers.tsx]"]
  node_node_services["Service layer<br/>domain APIs<br/>[auth.service.ts]"]
  node_node_realtime{{"Realtime layer<br/>livekit + sockets<br/>[livekit.service.ts]"}}
  node_node_uploads["Uploads<br/>file handling<br/>[route.ts]"]
  node_node_types["Domain types<br/>typed models<br/>[definitions.ts]"]
  node_node_utils["API client<br/>http helper<br/>[apiClient.ts]"]
end

node_node_root -->|"entry"| node_node_auth
node_node_root -->|"routes"| node_node_admin
node_node_root -->|"routes"| node_node_residents
node_node_root -->|"routes"| node_node_gate
node_node_middleware -->|"protects"| node_node_admin
node_node_middleware -->|"protects"| node_node_residents
node_node_middleware -->|"protects"| node_node_gate
node_node_auth -->|"auth api"| node_node_services
node_node_admin -->|"manages"| node_node_admin_props
node_node_admin -->|"manages"| node_node_admin_users
node_node_admin -->|"manages"| node_node_admin_assembly
node_node_admin -->|"manages"| node_node_admin_content
node_node_residents -->|"hosts"| node_node_room
node_node_residents -->|"scoped by"| node_node_property
node_node_gate -->|"scoped by"| node_node_property
node_node_shell -->|"uses"| node_node_property
node_node_shell -->|"composes"| node_node_root
node_node_services -->|"uses"| node_node_utils
node_node_services -->|"typed by"| node_node_types
node_node_room -->|"coordinates"| node_node_realtime
node_node_room -->|"loads data"| node_node_services
node_node_uploads -->|"supports"| node_node_services
node_node_admin_content -->|"stores"| node_node_uploads

click node_node_root "https://github.com/uniestetic/conectando-ph/blob/master/app/page.tsx"
click node_node_auth "https://github.com/uniestetic/conectando-ph/blob/master/app/auth/login/page.tsx"
click node_node_middleware "https://github.com/uniestetic/conectando-ph/blob/master/middleware.ts"
click node_node_admin "https://github.com/uniestetic/conectando-ph/blob/master/app/admin/page.tsx"
click node_node_admin_props "https://github.com/uniestetic/conectando-ph/blob/master/app/admin/copropiedades/page.tsx"
click node_node_admin_users "https://github.com/uniestetic/conectando-ph/blob/master/app/admin/usuarios/page.tsx"
click node_node_admin_assembly "https://github.com/uniestetic/conectando-ph/blob/master/app/admin/asambleas/page.tsx"
click node_node_admin_content "https://github.com/uniestetic/conectando-ph/blob/master/app/admin/comunicados/page.tsx"
click node_node_residents "https://github.com/uniestetic/conectando-ph/blob/master/app/residentes/page.tsx"
click node_node_room "https://github.com/uniestetic/conectando-ph/blob/master/app/residentes/room/page.tsx"
click node_node_gate "https://github.com/uniestetic/conectando-ph/blob/master/app/porteria/page.tsx"
click node_node_property "https://github.com/uniestetic/conectando-ph/blob/master/app/components/PropertySelector.tsx"
click node_node_shell "https://github.com/uniestetic/conectando-ph/blob/master/app/components/Providers.tsx"
click node_node_services "https://github.com/uniestetic/conectando-ph/blob/master/app/services/auth.service.ts"
click node_node_realtime "https://github.com/uniestetic/conectando-ph/blob/master/app/services/livekit.service.ts"
click node_node_uploads "https://github.com/uniestetic/conectando-ph/blob/master/app/api/uploads/route.ts"
click node_node_types "https://github.com/uniestetic/conectando-ph/blob/master/app/types/definitions.ts"
click node_node_utils "https://github.com/uniestetic/conectando-ph/blob/master/app/utils/apiClient.ts"

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_auth,node_node_middleware toneBlue
class node_node_admin,node_node_admin_props,node_node_admin_users,node_node_admin_assembly,node_node_admin_content,node_node_residents,node_node_room,node_node_gate toneAmber
class node_node_property,node_node_shell,node_node_services,node_node_realtime,node_node_uploads,node_node_types,node_node_utils toneMint
```

## Components

### App shell

Next.js routing, auth entrypoints, and shared frontend composition.

- [Next.js app](https://github.com/uniestetic/conectando-ph/blob/master/app/page.tsx): app router frontend · Top-level browser-facing application shell and route composition. · `app/page.tsx`
- [Auth flow](https://github.com/uniestetic/conectando-ph/blob/master/app/auth/login/page.tsx): nextauth + login · Login/logout entry point and NextAuth endpoint/configuration. · `app/auth/login/page.tsx`
- [Route guard](https://github.com/uniestetic/conectando-ph/blob/master/middleware.ts): middleware · Protects routes and handles redirects for unauthenticated or mismatched roles. · `middleware.ts`

### Role domains

User-facing areas separated by role and workflow.

- [Admin area](https://github.com/uniestetic/conectando-ph/blob/master/app/admin/page.tsx): back-office routes · CRUD-heavy management shell for properties, users, assemblies, documents, and operations. · `app/admin/page.tsx`
- [Properties](https://github.com/uniestetic/conectando-ph/blob/master/app/admin/copropiedades/page.tsx): copropiedades + unidades · Property and unit management with create/edit flows and property-scoped data. · `app/admin/copropiedades/page.tsx`
- [Users & roles](https://github.com/uniestetic/conectando-ph/blob/master/app/admin/usuarios/page.tsx): identity management · Administrative management of users, roles, and assignments. · `app/admin/usuarios/page.tsx`
- [Assemblies](https://github.com/uniestetic/conectando-ph/blob/master/app/admin/asambleas/page.tsx): meeting admin · Assembly setup, agenda building, and voting-question configuration. · `app/admin/asambleas/page.tsx`
- [Content ops](https://github.com/uniestetic/conectando-ph/blob/master/app/admin/comunicados/page.tsx): documents + notices · Back-office sections for communicados, documentos, formacion, pqrs, porteria, and visitantes. · `app/admin/comunicados/page.tsx`
- [Residents area](https://github.com/uniestetic/conectando-ph/blob/master/app/residentes/page.tsx): self-service routes · Resident-facing portal for documents, notices, visitor access, PQRS, and the assembly room. · `app/residentes/page.tsx`
- [Assembly room](https://github.com/uniestetic/conectando-ph/blob/master/app/residentes/room/page.tsx): realtime collaboration · Specialized live meeting interface with agenda, attendance, chat, voting, media, and recording controls. · `app/residentes/room/page.tsx`
- [Porteria area](https://github.com/uniestetic/conectando-ph/blob/master/app/porteria/page.tsx): security workflows · Front-desk and gate workflows for visitors, citofonia, casillero, and notices. · `app/porteria/page.tsx`

### Platform layer

Shared services, realtime integrations, and domain types.

- [Property context](https://github.com/uniestetic/conectando-ph/blob/master/app/components/PropertySelector.tsx): selector + state · Shared property selection and header management that scopes the current copropiedad across the app. · `app/components/PropertySelector.tsx`
- [Shared UI](https://github.com/uniestetic/conectando-ph/blob/master/app/components/Providers.tsx): reusable components · App-specific widgets, headers, modals, and general presentation primitives. · `app/components/Providers.tsx`
- [Service layer](https://github.com/uniestetic/conectando-ph/blob/master/app/services/auth.service.ts): domain APIs · Centralized data-access layer for assemblies, users, roles, units, properties, votes, and auth. · `app/services/auth.service.ts`
- [Realtime layer](https://github.com/uniestetic/conectando-ph/blob/master/app/services/livekit.service.ts): livekit + sockets · LiveKit and socket-based coordination for live assembly media and participant events. · `app/services/livekit.service.ts`
- [Uploads](https://github.com/uniestetic/conectando-ph/blob/master/app/api/uploads/route.ts): file handling · Upload route and public asset storage for documents, images, and media. · `app/api/uploads/route.ts`
- [Domain types](https://github.com/uniestetic/conectando-ph/blob/master/app/types/definitions.ts): typed models · Centralized TypeScript declarations for entities such as assemblies, users, roles, votes, and properties. · `app/types/definitions.ts`
- [API client](https://github.com/uniestetic/conectando-ph/blob/master/app/utils/apiClient.ts): http helper · Shared client utilities used by the service layer to reach backend APIs. · `app/utils/apiClient.ts`

## Connections

- Next.js app → Auth flow: entry · Authentication is the main public entry path.
- Next.js app → Admin area: routes · Top-level role-based admin branch.
- Next.js app → Residents area: routes · Top-level resident branch.
- Next.js app → Porteria area: routes · Top-level porteria branch.
- Route guard → Admin area: protects · Guards admin routes and redirects as needed.
- Route guard → Residents area: protects · Guards resident routes and redirects as needed.
- Route guard → Porteria area: protects · Guards security/front-desk routes and redirects as needed.
- Auth flow → Service layer: auth api · Login/session handling relies on the service layer.
- Admin area → Properties: manages · Property and unit CRUD lives under the admin shell.
- Admin area → Users & roles: manages · User and role administration lives under the admin shell.
- Admin area → Assemblies: manages · Assembly setup and voting configuration.
- Admin area → Content ops: manages · Operational content and support sections.
- Residents area → Assembly room: hosts · The assembly room is the most specialized resident experience.
- Residents area → Property context: scoped by · Resident views depend on the selected property.
- Porteria area → Property context: scoped by · Gate workflows are also property-scoped.
- Shared UI → Property context: uses · Shared UI includes property selectors and header controls.
- Shared UI → Next.js app: composes · Reusable widgets support the main app shell and pages.
- Service layer → API client: uses · Services centralize API access through the shared client.
- Service layer → Domain types: typed by · Domain models are defined centrally in TypeScript declarations.
- Assembly room → Realtime layer: coordinates · Live assembly interaction depends on realtime media and events.
- Assembly room → Service layer: loads data · Room state, agenda, votes, and attendance flow through services.
- Uploads → Service layer: supports · Upload handling complements document and media workflows.
- Content ops → Uploads: stores · Documents and assets move through upload handling.
