How juanzorrilla95/peopleflow works
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 HTTP API · database.py Mongo access · models.py Schemas
Components 6
FastAPI service
Single-process REST API for employee management
- HTTP API · Application bootstrap and routing surface; exposes employee CRUD and reporting endpoints
main.py - Employee CRUD · Create, list, get, update, and delete employees; applies filtering and pagination
- Salary report · Read-only average-salary endpoint backed by MongoDB aggregation
- Schemas · Request/response validation and payload shaping for employee data
models.py - Mongo access · Central MongoDB connection and collection access for employee records
database.py
Persistence
MongoDB-backed employee storage and reporting
- MongoDB · Local MongoDB instance holding all employee documents
Connections 7
- 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