# djneill/apartment_portal architecture

> Architecture diagram of the GitHub repository djneill/apartment_portal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/djneill/apartment_portal
- Repository: https://github.com/djneill/apartment_portal

## Overview

##### Main Components
a. Client-side (Frontend):
- React Application (in the “frontend” directory)
- Key modules: Pages (AdminDashboard, TenantDashboard, etc.), components (form components, navigation, cards, modals, etc.), services (axios-based API service, auth services), hooks (global state providers)

b. Server-side (Backend API):
- .NET API (in the “apartment_portal_api” directory)
- Controllers handling various resources: Users, Guests, Issues, LeaseAgreements, Notifications, Packages, Units, Statuses, Insights, etc.
- Abstractions and Interfaces (IRepository and IUnitOfWork) to enforce the repository pattern.
- Data Access Layer: Context (“PostgresContext”), repositories, migrations for entity changes
- Domain Models for business entities (Users, Units, Issues, LeaseAgreements, etc.)
- Services like AIService and auxiliary services such as AccessCodeGenerator and EmailValidator.

c. Database:
- Although not explicitly named, the migrations and context suggest a relational database (likely PostgreSQL) managed via Entity Framework migrations.

d. External Integrations:
- SSL certificate generation for secure HTTPS connections
- Possibly external AI/ML services integrated through the AIService.

##### Relationships and Interactions
- The Frontend communicates with the Backend using RESTful API calls via axios.
- The API controllers receive requests and delegate business logic to services and repositories.
- The Repository and UnitOfWork patterns encapsulate data access operations, interacting with the database (model changes are captured via migrations).
- The business logic is distributed between Controllers, Services (such as AIService), and Models.
- There exist clear boundaries between the presentation layer (frontend), business logic (backend controllers and services), and data/storage layer (database via EF migrations).

##### Important Architectural Patterns and Technologies
- MVC (or a variant) structure for the backend with Controllers, Models, and Services/Repositories.
- Repository pattern and UnitOfWork for data access.
- Separation of concerns between API and frontend.
- Use of environment configuration (.env files in the frontend) and secure HTTPS local development (certificate generation).
- For the frontend, modern React practices leveraging hooks and component-based architecture.
- Vite is used as the development/build tool in the frontend.

- Use clear labels for each component (e.g., “TenantDashboard (React Page)”, “UserController”, “IssueRepository”, “Postgres Database”).
- Frontend → Backend (HTTP/HTTPS calls)
- Within Backend: Controller → Service → Repository → Database.
- Rectangles for frontend components,
- Rounded rectangles or containers for backend controllers/services,
- Notes for external dependencies and configuration elements (e.g., SSL certificate setup note on the environment side).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        F["React Application"]
        F_Tenant["Tenant Dashboard (React Page)"]
        F_Admin["Admin Dashboard (React Page)"]
        F_AdminOther["Other Admin Pages (Manage Lease/Tenant)"]
        F_Login["Login Page"]
        F_Home["Home Page"]
        F_APIService["API Service Bridge (axios)"]
        F_AuthService["Auth Service"]
        F_Form["Form Components"]
        F_IssuesComp["Issues Components"]
        F_GuestsComp["Guests Components"]
    end

    %% Backend API Layer
    subgraph "Backend API"
        subgraph "Controllers"
            B_Users["UsersController"]
            B_Unit["UnitController"]
            B_Lease["LeaseAgreementsController"]
            B_Issues["IssuesController"]
            B_Guest["GuestController"]
            B_Notification["NotificationController"]
        end
        subgraph "Services & Domain"
            B_AIService["AIService"]
            B_Domain["Domain Models (Users, Units, LeaseAgreements, Issues, Guests, Notifications)"]
        end
        B_Data["Data Access & Repositories (PostgresContext, Migrations)"]
    end

    %% Database Layer
    DB["Postgres Database"]

    %% Connections: Frontend to Backend (REST API Calls)
    F_APIService -->|"REST_API_Calls"| B_Users
    F_APIService -->|"REST_API_Calls"| B_Unit
    F_APIService -->|"REST_API_Calls"| B_Lease
    F_APIService -->|"REST_API_Calls"| B_Issues
    F_APIService -->|"REST_API_Calls"| B_Guest
    F_APIService -->|"REST_API_Calls"| B_Notification

    %% Internal Backend Flow
    B_Users -->|"Uses"| B_Domain
    B_Unit -->|"Uses"| B_Domain
    B_Lease -->|"Uses"| B_Domain
    B_Issues -->|"Uses"| B_Domain
    B_Guest -->|"Uses"| B_Domain
    B_Notification -->|"Uses"| B_Domain

    B_Users -->|"Data_Ops"| B_Data
    B_Unit -->|"Data_Ops"| B_Data
    B_Lease -->|"Data_Ops"| B_Data
    B_Issues -->|"Data_Ops"| B_Data
    B_Guest -->|"Data_Ops"| B_Data
    B_Notification -->|"Data_Ops"| B_Data

    B_Issues -->|"Calls"| B_AIService
    B_AIService -->|"Data_Ops"| B_Data

    B_Data -->|"Persists"| DB

    %% Frontend Internal Navigation (Grouping for illustration)
    F --> F_Tenant
    F --> F_Admin
    F --> F_AdminOther
    F --> F_Login
    F --> F_Home
    F --> F_APIService
    F --> F_AuthService
    F --> F_Form
    F --> F_IssuesComp
    F --> F_GuestsComp

    %% Styles
    classDef frontend fill:#A7D8DE,stroke:#333,stroke-width:2px;
    classDef backend fill:#FAD7A0,stroke:#333,stroke-width:2px;
    classDef database fill:#EDBB99,stroke:#333,stroke-width:2px;
    class F,F_Tenant,F_Admin,F_AdminOther,F_Login,F_Home,F_APIService,F_AuthService,F_Form,F_IssuesComp,F_GuestsComp frontend
    class B_Users,B_Unit,B_Lease,B_Issues,B_Guest,B_Notification,B_AIService,B_Domain,B_Data backend
    class DB database

    %% Click Events for Frontend Components
    click F "https://github.com/djneill/apartment_portal/tree/main/frontend/"
    click F_Tenant "https://github.com/djneill/apartment_portal/blob/main/frontend/src/pages/TenantDashboard.tsx"
    click F_Admin "https://github.com/djneill/apartment_portal/blob/main/frontend/src/pages/AdminDashboard.tsx"
    click F_AdminOther "https://github.com/djneill/apartment_portal/blob/main/frontend/src/pages/AdminManageLease.tsx"
    click F_Login "https://github.com/djneill/apartment_portal/blob/main/frontend/src/pages/shared/Login.tsx"
    click F_Home "https://github.com/djneill/apartment_portal/blob/main/frontend/src/pages/shared/Home.tsx"
    click F_APIService "https://github.com/djneill/apartment_portal/blob/main/frontend/src/services/api.ts"
    click F_AuthService "https://github.com/djneill/apartment_portal/blob/main/frontend/src/services/auth.ts"
    click F_Form "https://github.com/djneill/apartment_portal/tree/main/frontend/src/components/form/"
    click F_IssuesComp "https://github.com/djneill/apartment_portal/tree/main/frontend/src/components/issues/"
    click F_GuestsComp "https://github.com/djneill/apartment_portal/tree/main/frontend/src/components/guests/"

    %% Click Events for Backend Components
    click B_Users "https://github.com/djneill/apartment_portal/blob/main/apartment_portal_api/apartment_portal_api/Controllers/UsersController.cs"
    click B_Unit "https://github.com/djneill/apartment_portal/blob/main/apartment_portal_api/apartment_portal_api/Controllers/UnitController.cs"
    click B_Lease "https://github.com/djneill/apartment_portal/blob/main/apartment_portal_api/apartment_portal_api/Controllers/LeaseAgreementsController.cs"
    click B_Issues "https://github.com/djneill/apartment_portal/blob/main/apartment_portal_api/apartment_portal_api/Controllers/IssuesController.cs"
    click B_Guest "https://github.com/djneill/apartment_portal/blob/main/apartment_portal_api/apartment_portal_api/Controllers/GuestController.cs"
    click B_Notification "https://github.com/djneill/apartment_portal/blob/main/apartment_portal_api/apartment_portal_api/Controllers/NotificationController.cs"
    click B_AIService "https://github.com/djneill/apartment_portal/tree/main/apartment_portal_api/apartment_portal_api/Services/AIService/"
    click B_Data "https://github.com/djneill/apartment_portal/blob/main/apartment_portal_api/apartment_portal_api/Data/PostgresContext.cs"
    click B_Domain "https://github.com/djneill/apartment_portal/tree/main/apartment_portal_api/apartment_portal_api/Models/Users/"
```
