Overview
Relevant source files
The following files were used as context for generating this wiki page:- MercaditoMovil.Infrastructure/Tools/Scripts/create_csvs.py
- MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs
- Mercadito.Domain/Entities/User/User.cs
- MercaditoMovil/Controllers/LoginController.cs
- MercaditoMovil.Application/Service/AuthService.cs
- MercaditoMovil.Application/Validators/UserValidator.cs
- Mercadito.Domain/Interfaces/Interface1.cs
- MercaditoMovil.Application/Features/UserManagement/IAuthService.cs
- MercaditoMovil/Program.cs
- MercaditoMovil/Views/Form1.cs
- MercaditoMovil/Views/Form1.Designer.cs
MercaditoMovil is a desktop application for Windows, built using the .NET WinForms framework. The project follows a layered architecture that separates domain logic, application services, and data infrastructure. Its primary data persistence strategy relies on a set of CSV files, which are initially populated by a Python script. The core functionality implemented so far centers on user authentication, including user registration and login.
The system is designed to be extensible, with interfaces defining the contracts for services and repositories, allowing for different implementations to be swapped in. For example, while it currently uses a CSV-based user repository, the IUserRepository interface allows for a future transition to a database system without altering the application's core logic.
Sources: MercaditoMovil/Program.cs, MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs, Mercadito.Domain/Interfaces/Interface1.cs
Project Architecture
The project is structured into several layers, promoting separation of concerns. The main layers are Presentation (WinForms UI), Application, Domain, and Infrastructure.
The diagram below illustrates the high-level architecture and dependencies between the layers.
This diagram shows the flow from the UI down to the data files, with dependencies pointing downwards. The Application layer depends on interfaces defined in the Domain layer, and the Infrastructure layer provides concrete implementations for those interfaces.
Sources: MercaditoMovil/Controllers/LoginController.cs, MercaditoMovil.Application/Service/AuthService.cs, Mercadito.Domain/Interfaces/Interface1.cs, MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs, MercaditoMovil.Infrastructure/Tools/Scripts/create_csvs.py
Data Management
The application's data is stored in CSV files located under the MercaditoMovil.Infrastructure/DataFiles/ directory. A Python script is provided to generate the initial dataset.
Sources: MercaditoMovil.Infrastructure/Tools/Scripts/create_csvs.py:15-17
Data Generation
A Python script, create_csvs.py, is responsible for creating and populating the CSV files with sample data. This script has no external dependencies and generates data for users, markets, producers, and products.
The script generates the following files:
| File Path | Purpose |
|---|---|
DataFiles/GeoLocations/locations.csv | Optional input for geographic data (Province, Canton, District). |
DataFiles/Markets/markets.csv | Contains a predefined list of farmer's markets. |
DataFiles/People/users.csv | Stores user account information. |
DataFiles/Producers/producers.csv | Stores information about product producers (individuals and companies). |
DataFiles/Catalogs/product_catalog.csv | A master list of all possible products. |
DataFiles/Commerce/producer_products.csv | Links producers to products from the catalog, including price and stock. |
Sources: MercaditoMovil.Infrastructure/Tools/Scripts/create_csvs.py:19-25, 41-44, 430-542
Data Schemas
The CSV files serve as the database. The relationships can be visualized in the following ER diagram.
This diagram outlines the primary entities and their relationships as defined by the CSV headers and foreign key-like IDs (MarketId, ProducerId, etc.).
Sources: MercaditoMovil.Infrastructure/Tools/Scripts/create_csvs.py:148-150, 233-234, 360-361, 390-394
Data Access Layer
Data access is abstracted through repository interfaces. The CsvUserRepository is the concrete implementation for user data, reading from and writing to users.csv.
Key implementation details:
- It uses
Microsoft.VisualBasic.FileIO.TextFieldParserto correctly handle comma-separated values that may be enclosed in quotes. - The
GetByUsernamemethod performs a sequential scan of the CSV file, which may have performance implications for large datasets. - The
Addmethod appends a new user record to the end of the file, creating the file and its header if they do not exist. - Passwords are read and stored in plain text.
Sources: MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs:12, 32, 42, 75
User Authentication
User authentication is a core feature, handled by a set of collaborating components across the application layers.
Components
| Class/Interface | Layer | Responsibility |
|---|---|---|
LoginController | Presentation | Bridges the UI with the application layer. Invokes AuthService. |
IAuthService | Application | Defines the contract for login and registration operations. |
AuthService | Application | Implements the core authentication logic, orchestrating validation and repository access. |
UserValidator | Application | Provides static methods to validate input for login and registration. |
IUserRepository | Domain | Defines the contract for user data persistence. |
CsvUserRepository | Infrastructure | Implements IUserRepository using a CSV file as the data store. |
User | Domain | Represents the user entity. |
Sources: MercaditoMovil/Controllers/LoginController.cs, MercaditoMovil.Application/Features/UserManagement/IAuthService.cs, MercaditoMovil.Application/Service/AuthService.cs, MercaditoMovil.Application/Validators/UserValidator.cs, Mercadito.Domain/Interfaces/Interface1.cs, MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs, Mercadito.Domain/Entities/User/User.cs
Login Flow
The following sequence diagram illustrates the process when a user attempts to log in.
The flow starts at the UI, goes through the controller to the service, which first validates the input, then queries the repository, and finally compares the password.
Sources: MercaditoMovil/Controllers/LoginController.cs:22-27, MercaditoMovil.Application/Service/AuthService.cs:23-37, MercaditoMovil.Application/Validators/UserValidator.cs:11-20, MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs:32-60
Registration Flow
The registration process follows a similar pattern, with additional checks for duplicate usernames.
The service validates the new user data, checks for an existing user with the same username, and then instructs the repository to add the new user.
Sources: MercaditoMovil/Controllers/LoginController.cs:29-47, MercaditoMovil.Application/Service/AuthService.cs:42-63, MercaditoMovil.Application/Validators/UserValidator.cs:25-45, MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs:65-108
Domain Model
The core of the domain is centered around the User entity and its interaction with the authentication system.
User Entity
The User class is a simple data-holding entity with read-only properties. Its constructor ensures that all string properties are non-null, defaulting to empty strings if null is passed.
This diagram shows the public properties of the User class.
Sources: Mercadito.Domain/Entities/User/User.cs:7-49
Authentication Service Class Diagram
The relationship between the authentication components can be visualized as follows:
This diagram illustrates the dependency injection pattern, where LoginController uses AuthService, and AuthService depends on the IUserRepository interface, which is implemented by CsvUserRepository.
Sources: MercaditoMovil/Controllers/LoginController.cs:15, MercaditoMovil.Application/Service/AuthService.cs:12,17, MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs:12