# iath-dev/realestateproject architecture

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

- Interactive diagram: https://gitdiagram.com/iath-dev/realestateproject
- Repository: https://github.com/iath-dev/realestateproject

## Overview

##### Project type and purpose
- This is a full-stack application (“Million Real Estate”) comprising:
- Backend: .NET 8/9 C# API that reads/writes property data in MongoDB.
- Frontend: ReactJS (Vite) SPA served behind Nginx.
- Database: MongoDB (with optional Mongo Express UI).
- End-to-end tests via Cypress and unit tests via NUnit.
- Purpose: Expose property listings (with filters) via a REST API and render them in a responsive web UI.

##### File structure
- Top-level:
- docker-compose.yml & Makefile orchestrate containers (frontend, backend, mongo, mongo-express).
- backend/: “Clean Architecture” with three layers:
– RealEstate.API (Controllers, Program.cs, appsettings.json, Dockerfile)
– RealEstate.Core (DTOs, Entities, Interfaces, Mappings)
– RealEstate.Infrastructure (MongoDbContext, Repositories, Services)
– tests/ for Controllers and Services.
- frontend/: Vite-powered React app, preconfigured with Dockerfile, Nginx config, Cypress e2e tests, global store (Zustand or similar) and hooks.
- Build & deploy artifacts: Dockerfiles in each service, docker-compose.yml, Makefile targets (start, test, stop, clean).

##### README for additional insights
- Confirms tech stack: .NET + MongoDB + React/Next.js.
- Workflow: make start → builds images, runs containers, opens UI at localhost:3000.
- API endpoints documented via Swagger at localhost:8080.
- Emphasis on clean architecture, modular code, unit tests, performance.

a. Main components
1. User’s Browser (HTTP client)
2. Frontend Container (React SPA + Nginx)
3. Backend Container (ASP.NET Core Web API)
4. MongoDB Container (Data store)
5. Mongo Express Container (Optional DB UI)

b. Relationships & data flows
- Browser ←→ (HTTPS) ←→ Nginx → serves React assets
- React app → (HTTP/REST) → API Controllers in .NET
- Controllers → (calls) → Core Services → (calls) → Repositories → MongoDbContext → MongoDB
- Seed scripts populate MongoDB at startup (backend/data/seed/*.js)
- Cypress tests hit the frontend, mock fixtures for component/e2e tests.
- NUnit tests invoke service layer and controller endpoints directly.

c. Architectural patterns & principles
- Clean (Onion) Architecture: API layer → Core (domain + DTOs) → Infrastructure (DB and external concerns)
- Dependency Injection (services, repositories injected into controllers)
- Repository Pattern (GenericRepository + specialized repos)
- AutoMapper for DTO ↔ Entity mapping (MappingProfile)
- Containerization (Docker) & orchestration (docker-compose)
- Test-driven quality: NUnit + Cypress

d. Key technologies, frameworks, libraries
- Backend: .NET 8/9, C#, ASP.NET Core Web API, MongoDB.Driver, AutoMapper, Swashbuckle (Swagger), NUnit
- Frontend: React (with TSX), Vite, Zustand (store), Axios/fetch wrappers in src/api/services.ts, Cypress for e2e
- Infrastructure: Docker, docker-compose, Nginx
- Dev tools: Makefile, VSCode settings, ESLint/Prettier

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    Browser["User's Browser"]:::external

    %% Frontend Container
    subgraph "Frontend Container"
        Nginx["Nginx"]:::frontend
        ReactApp["React SPA"]:::frontend
        subgraph "React App Modules"
            HTTPClient["HTTP Client (Axios/fetch)"]:::frontend
            StateMgmt["State Management (Zustand/hooks)"]:::frontend
            UIComponents["UI Components"]:::frontend
        end
    end

    %% Backend Container
    subgraph "Backend Container"
        subgraph "API Controllers"
            PropsController["PropertiesController"]:::backend
            OwnersController["OwnersController"]:::backend
        end
        subgraph "Core Services"
            PropertySvc["PropertyService"]:::backend
            OwnerSvc["OwnerService"]:::backend
        end
        subgraph "Repositories"
            GenericRepo["GenericRepository"]:::backend
            PropRepo["PropertyRepository"]:::backend
            OwnerRepo["OwnerRepository"]:::backend
            ImageRepo["PropertyImageRepository"]:::backend
            TraceRepo["PropertyTraceRepository"]:::backend
        end
        MongoContext["MongoDbContext"]:::backend
        subgraph "AutoMapper"
            MappingProfile["MappingProfile"]:::backend
        end
        Swagger["Swagger/OpenAPI"]:::backend
    end

    %% Database and UI
    subgraph "Database & Admin"
        MongoDB["MongoDB"]:::data
        SeedScripts["Database Seeding"]:::data
        MongoExpress["Mongo Express UI"]:::data
    end

    %% Testing
    CypressTests["Cypress E2E Tests"]:::test
    NUnitTests["NUnit Unit Tests"]:::test

    %% Connections
    Browser -->|HTTPS| Nginx
    Nginx -->|serves assets| ReactApp
    ReactApp -->|REST API calls| PropsController
    ReactApp --> StateMgmt
    ReactApp --> HTTPClient
    ReactApp --> UIComponents

    PropsController -->|calls| PropertySvc
    OwnersController -->|calls| OwnerSvc
    PropertySvc -->|uses| PropRepo
    PropertySvc -->|uses| GenericRepo
    OwnerSvc -->|uses| OwnerRepo
    PropRepo -->|queries| MongoContext
    OwnerRepo -->|queries| MongoContext
    ImageRepo -->|queries| MongoContext
    TraceRepo -->|queries| MongoContext
    MongoContext -->|connects| MongoDB
    SeedScripts -->|initializes| MongoDB
    MongoExpress -->|admin UI| MongoDB

    CypressTests -->|runs on| ReactApp
    NUnitTests -->|tests| PropertySvc
    NUnitTests -->|tests| PropsController

    %% Click Events - Frontend Container
    click Nginx "https://github.com/iath-dev/realestateproject/blob/main/frontend/nginx.conf"
    click ReactApp "https://github.com/iath-dev/realestateproject/tree/main/frontend/Dockerfile"
    click Nginx "https://github.com/iath-dev/realestateproject/blob/main/docker-compose.yml"

    %% Click Events - Backend Container
    click PropsController "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.API/Controllers/PropertiesController.cs"
    click OwnersController "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.API/Controllers/OwnersController.cs"
    click PropertySvc "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.Infrastructure/Services/PropertyService.cs"
    click OwnerSvc "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.Infrastructure/Services/OwnerService.cs"
    click GenericRepo "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.Infrastructure/Repositories/GenericRepository.cs"
    click PropRepo "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.Infrastructure/Repositories/PropertyRepository.cs"
    click OwnerRepo "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.Infrastructure/Repositories/OwnerRepository.cs"
    click ImageRepo "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.Infrastructure/Repositories/PropertyImageRepository.cs"
    click TraceRepo "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.Infrastructure/Repositories/PropertyTraceRepository.cs"
    click MongoContext "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.Infrastructure/Data/MongoDbContext.cs"
    click MappingProfile "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.Core/Mappings/MappingProfile.cs"
    click Swagger "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.API/appsettings.json"
    click Swagger "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.API/Properties/launchSettings.json"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/api/services.ts"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/api/index.ts"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/api/types/index.ts"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/store/index.ts"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/store/usePropertyStore.ts"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/hooks/useProperties.ts"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/hooks/usePropertyDetails.ts"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/components/common/PropertiesGrid.tsx"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/components/common/PropertyDialog/PropertyDialog.tsx"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/components/common/PropertyFilters.tsx"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/pages/HomePage.tsx"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/components/layout/MainLayout.tsx"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/src/main.tsx"
    click CypressTests "https://github.com/iath-dev/realestateproject/blob/main/frontend/cypress/e2e/home-page.cy.ts"
    click CypressTests "https://github.com/iath-dev/realestateproject/blob/main/frontend/cypress/e2e/components/properties-grid.cy.ts"
    click NUnitTests "https://github.com/iath-dev/realestateproject/blob/main/backend/tests/RealEstate.Tests/Controllers/PropertiesControllerTests.cs"
    click NUnitTests "https://github.com/iath-dev/realestateproject/blob/main/backend/tests/RealEstate.Tests/Services/PropertyServiceTests.cs"
    click SeedScripts "https://github.com/iath-dev/realestateproject/blob/main/backend/data/seed/01-init-database.js"
    click SeedScripts "https://github.com/iath-dev/realestateproject/blob/main/backend/data/seed/02-sample-properties.js"
    click SeedScripts "https://github.com/iath-dev/realestateproject/blob/main/backend/data/seed/03-indexes.js"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/frontend/nginx.conf"
    click ReactApp "https://github.com/iath-dev/realestateproject/blob/main/docker-compose.yml"
    click PropsController "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.API/Program.cs"
    click ReactApp "https://github.com/iath-dev/realestateproject/tree/main/frontend/Dockerfile"
    click PropsController "https://github.com/iath-dev/realestateproject/blob/main/backend/src/RealEstate.API/RealEstate.API.csproj"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,stroke-width:1px
    classDef backend fill:#DFF0D8,stroke:#228B22,stroke-width:1px
    classDef data fill:#FFE4B5,stroke:#FF8C00,stroke-width:1px
    classDef test fill:#F5D0A9,stroke:#C65D00,stroke-width:1px
    classDef external fill:#E2E2E2,stroke:#888,stroke-width:1px,font-style:italic
```
