# juanzorrilla95/peopleflow architecture

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

- Interactive diagram: https://gitdiagram.com/juanzorrilla95/peopleflow
- Repository: https://github.com/juanzorrilla95/peopleflow

## Overview

1. **Repository shape**
   - This is a small, single-service backend: one FastAPI application with three source modules.
   - The architecture is intentionally simple and layered: HTTP API entrypoint, data models/schemas, and MongoDB access.

2. **System boundary**
   - The core boundary is an internal REST API for PeopleFlow employee management.
   - External dependency is a local MongoDB instance (`mongodb://localhost:27017`), which stores all employee records and supports aggregation for reporting.

3. **Entry point and runtime**
   - `main.py` is the application bootstrap and HTTP routing surface.
   - The service is run with Uvicorn, exposing the FastAPI app on `127.0.0.1:8000`.
   - Swagger/OpenAPI docs are available through FastAPI’s built-in documentation.

4. **API layer responsibilities**
   - The API exposes CRUD endpoints for employees:
     - create
     - list with filters and pagination
     - get by ID
     - update by ID
     - delete by ID
   - It also exposes a dedicated reporting endpoint for average salary.

5. **Data model and validation**
   - `models.py` holds the Pydantic schemas used to validate incoming payloads and shape responses.
   - This is the primary input validation boundary before data is written to MongoDB.
   - The README indicates `fecha_ingreso` is normalized to a `datetime` value before persistence.

6. **Persistence layer**
   - `database.py` centralizes MongoDB connectivity and collection access.
   - All persistent employee data lives in MongoDB rather than in-memory state or a relational schema.
   - The architecture depends on MongoDB’s document model, which fits flexible employee records.

7. **Request-to-data flow**
   - A client sends an HTTP request to FastAPI.
   - FastAPI validates and parses the payload using Pydantic models.
   - The application layer applies rules such as email uniqueness and date normalization.
   - The MongoDB layer performs the insert, read, update, delete, or aggregation operation.
   - The response is returned as JSON through FastAPI.

8. **List/search behavior**
   - The listing endpoint supports filtering by role/position (`puesto`) and pagination (`page`, `limit`).
   - This means the API is not just a raw collection dump; it applies query shaping at the application/database boundary.

9. **Reporting flow**
   - `GET /employees/average-salary` is a read-only analytics endpoint.
   - The average salary is computed in MongoDB using aggregation rather than loading all documents into application memory.
   - This is a clear separation between operational CRUD traffic and reporting logic.

10. **Business rules enforced in the app**
   - Email uniqueness is validated at the application level.
   - Date normalization happens before persistence to match MongoDB’s supported types.
   - These are lightweight business constraints handled in the service layer, not by a separate domain service.

11. **Technology stack impact**
   - Python 3.10+, FastAPI, Pydantic, Uvicorn, and MongoDB are the only technologies that materially shape the architecture.
   - The service is synchronous/simple enough to be deployed as a single process without extra infrastructure.

12. **What is not present**
   - There is no evidence of authentication, background jobs, message queues, caching, or multiple services.
   - No separate frontend exists in this repository; it is purely the backend API and persistence boundary.

13. **How to diagram it**
   - Draw a single FastAPI service box containing routing/validation logic.
   - Inside that box, separate the API layer (`main.py`) from schema validation (`models.py`) and DB access (`database.py`).
   - Connect the service to a MongoDB datastore.
   - Show two main traffic paths: CRUD employee operations and salary aggregation/reporting.

Main entry points: [`main.py`](https://github.com/juanzorrilla95/peopleflow/blob/master/main.py) (HTTP API), [`database.py`](https://github.com/juanzorrilla95/peopleflow/blob/master/database.py) (Mongo access), [`models.py`](https://github.com/juanzorrilla95/peopleflow/blob/master/models.py) (Schemas)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_service["FastAPI service"]
  node_main["HTTP API<br/>FastAPI app<br/>[main.py]"]
  node_crud["Employee CRUD<br/>endpoint set"]
  node_report["Salary report<br/>analytics endpoint"]
  node_models["Schemas<br/>Pydantic models<br/>[models.py]"]
  node_database["Mongo access<br/>DB module<br/>[database.py]"]
end

subgraph group_data["Persistence"]
  node_mongo[("MongoDB<br/>document store")]
end

node_main -->|"routes"| node_crud
node_main -->|"routes"| node_report
node_crud -->|"validates"| node_models
node_crud -->|"uses"| node_database
node_report -->|"aggregates"| node_database
node_database -->|"reads/writes"| node_mongo
node_main -->|"shapes"| node_models

click node_main "https://github.com/juanzorrilla95/peopleflow/blob/master/main.py"
click node_models "https://github.com/juanzorrilla95/peopleflow/blob/master/models.py"
click node_database "https://github.com/juanzorrilla95/peopleflow/blob/master/database.py"

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_main,node_crud,node_report,node_models,node_database toneBlue
class node_mongo toneAmber
```

## Components

### FastAPI service

Single-process REST API for employee management

- [HTTP API](https://github.com/juanzorrilla95/peopleflow/blob/master/main.py): FastAPI app · Application bootstrap and routing surface; exposes employee CRUD and reporting endpoints · `main.py`
- **Employee CRUD**: endpoint set · Create, list, get, update, and delete employees; applies filtering and pagination
- **Salary report**: analytics endpoint · Read-only average-salary endpoint backed by MongoDB aggregation
- [Schemas](https://github.com/juanzorrilla95/peopleflow/blob/master/models.py): Pydantic models · Request/response validation and payload shaping for employee data · `models.py`
- [Mongo access](https://github.com/juanzorrilla95/peopleflow/blob/master/database.py): DB module · Central MongoDB connection and collection access for employee records · `database.py`

### Persistence

MongoDB-backed employee storage and reporting

- **MongoDB**: document store · Local MongoDB instance holding all employee documents

## Connections

- HTTP API → Employee CRUD: routes · Main app exposes employee lifecycle endpoints
- HTTP API → Salary report: routes · Main app exposes the reporting endpoint
- Employee CRUD → Schemas: validates · CRUD requests are parsed and validated with Pydantic schemas
- Employee CRUD → Mongo access: uses · CRUD operations persist and query through the MongoDB layer
- Salary report → Mongo access: aggregates · Average salary is computed through the database layer
- Mongo access → MongoDB: reads/writes · All employee data is stored in MongoDB
- HTTP API → Schemas: shapes · HTTP payloads and responses are shaped by application schemas
