# rauladse/construction_map architecture

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

- Interactive diagram: https://gitdiagram.com/rauladse/construction_map
- Repository: https://github.com/rauladse/construction_map

## Overview

##### Project Type and Purpose
- This is a full-stack web application for managing construction projects by viewing and overlaying construction maps, creating pinpoint events, and managing project data.
- The backend is built with Python (FastAPI) and uses PostgreSQL as its database. The frontend, built in React, is in development.
- Key features include user authentication, project management, map overlays, event management, and data export.

##### Analyzing the File Structure
- The project is clearly separated into multiple areas:
- “backend/”: Contains the FastAPI backend code.
- The “app/” folder holds core application code with subdirectories for:
▪ api (endpoints and versioning, e.g., api/v1/ with endpoints for maps, events, authentication, etc.)
▪ core (application configuration and security settings)
▪ db (database configuration and connection details)
▪ models (SQLAlchemy models for various entities like event, map, project, user)
▪ schemas (Pydantic schemas for request/response validation)
▪ services (business logic for managing authentication, events, maps, projects)
- “backend/migrations/”: For Alembic database migration scripts.
- “backend/tests/”: Contains tests to verify backend functionality.
- “frontend/”: Although still coming online, this contains the React code for the user interface with organized components, pages, assets, and styles.
- Additional scripts and configuration files (e.g., run_server.py, start_servers.sh, webpack.config.js) hint at deployment and build processes.

##### Key Components
a. Backend Components:
- FastAPI Application: Represent the core API that handles incoming HTTP requests. Show that it uses dependency injection (e.g., using routes, endpoint files, and versioning under “api/v1”).
- API Endpoints: Each specific endpoint (maps, events, auth, etc.) under “app/api/v1/endpoints” (and similarly under “backend/app/api/v1/endpoints”) should be represented as part of the API layer.
- Data Layer:
- Database Access: Illustrate the “db” folder and indicate that it uses SQLAlchemy for database interactions.
- Models & Schemas: Capture the models (database structure) and Pydantic schemas (data validation) that define the data structure.
- Core Application Settings: Include components for configuration and security (from “core/config.py” and “core/security.py”).
- Migrations: Mention the Alembic migration system that ties into the database changes.

b. Frontend Components:
- React Application: Even though it is “coming soon,” show that the frontend is structured into components, pages (such as LoginPage, MapViewer, ProjectList), services (authService, eventService, mapService), and assets.
- User Interface: Represent consistent elements like navigation, modal dialogs for event creation, map viewing, notifications, and project management.

c. Auxiliary Scripts & Deployment:
- Deployment/utility scripts (e.g., start_servers.sh, stop_servers.sh) which indicate how the system is started and managed.
- External dependencies like Leaflet/OpenLayers for map visualization.
- Environment and configuration files (e.g., .env file for sensitive settings).

##### Relationships and Interactions
- Users make HTTP requests from the frontend to the FastAPI backend.
- The API layer processes these requests, invoking services to handle business logic.
- Services interact with the database layer (SQLAlchemy models and PostgreSQL) to retrieve or update data.
- Authentication/authorization modules validate user credentials.
- The map endpoints and services interface with map visualization libraries (Leaflet/OpenLayers) though these are likely integrated in the future frontend portion.

- Versioning in your API (e.g., v1 endpoints) and note that there is clear modular separation.

##### Architectural Patterns and Design Principles
- The Backend employs a layered (or “onion”) architecture with clear separations for API routing, business logic, and data access.
- RESTful design of API endpoints.
- Usage of dependency injection (e.g., through FastAPI deps) and modular design for separating concerns.
- If applicable, mention that the future integration of the React frontend with the backend hints at a modern full-stack decoupled architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Backend Components
    subgraph "Backend Components"
        BE_FastAPI["FastAPI Application"]:::backend
        subgraph "API Layer"
            BE_API["v1 API Endpoints"]:::backend
        end
        BE_Services["Business Logic Services"]:::backend
        subgraph "Data Layer"
            BE_DB["Database Configuration"]:::backend
            BE_Models["SQLAlchemy Models"]:::backend
            BE_Schemas["Pydantic Schemas"]:::backend
        end
        BE_Core["Core Settings & Security"]:::backend
        BE_Migrations["Migrations (Alembic)"]:::backend
    end

    %% Frontend Component
    subgraph "Frontend Components"
        FE["React Application"]:::frontend
    end

    %% Deployment & Utility Scripts
    subgraph "Deployment & Utilities"
        Deploy_Start["start_servers.sh"]:::deploy
        Deploy_Stop["stop_servers.sh"]:::deploy
        Deploy_Run["run_server.py"]:::deploy
    end

    %% External Dependency
    ExternalDB["PostgreSQL Database"]:::database

    %% Connections
    FE -->|"HTTP_requests"| BE_FastAPI
    BE_FastAPI -->|"routes"| BE_API
    BE_API -->|"calls"| BE_Services
    BE_Services -->|"uses"| BE_DB
    BE_DB -->|"maps"| BE_Models
    BE_DB -->|"validates"| BE_Schemas
    BE_FastAPI -->|"configures"| BE_Core
    BE_DB -->|"connects"| ExternalDB
    BE_Migrations -->|"apply_schema"| ExternalDB
    Deploy_Start -->|"triggers_backend"| BE_FastAPI
    Deploy_Run -->|"triggers_frontend"| FE

    %% Click Events
    click BE_FastAPI "https://github.com/rauladse/construction_map/blob/master/backend/app/main.py"
    click BE_API "https://github.com/rauladse/construction_map/tree/master/backend/app/api/v1/endpoints/"
    click BE_Services "https://github.com/rauladse/construction_map/tree/master/backend/app/services/"
    click BE_DB "https://github.com/rauladse/construction_map/blob/master/backend/app/db/database.py"
    click BE_Models "https://github.com/rauladse/construction_map/tree/master/backend/app/models/"
    click BE_Schemas "https://github.com/rauladse/construction_map/tree/master/backend/app/schemas/"
    click BE_Core "https://github.com/rauladse/construction_map/tree/master/backend/app/core/"
    click BE_Migrations "https://github.com/rauladse/construction_map/tree/master/backend/migrations/"
    click FE "https://github.com/rauladse/construction_map/tree/master/frontend/src/"
    click Deploy_Start "https://github.com/rauladse/construction_map/blob/master/start_servers.sh"
    click Deploy_Stop "https://github.com/rauladse/construction_map/blob/master/stop_servers.sh"
    click Deploy_Run "https://github.com/rauladse/construction_map/blob/master/run_server.py"

    %% Styles
    classDef backend fill:#AED6F1,stroke:#21618C,stroke-width:2px;
    classDef frontend fill:#ABEBC6,stroke:#1E8449,stroke-width:2px;
    classDef deploy fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef database fill:#F5CBA7,stroke:#D35400,stroke-width:2px;
```
