MercaditoMovil Wiki
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/Views/Form1.Designer.cs
- MercaditoMovil/Controllers/LoginController.cs
- MercaditoMovil.Application/Service/AuthService.cs
- MercaditoMovil.Application/Validators/UserValidator.cs
- MercaditoMovil/Program.cs
- Mercadito.Domain/Interfaces/Interface1.cs
- MercaditoMovil.Application/Features/UserManagement/IAuthService.cs
- MercaditoMovil/Views/Form1.cs
MercaditoMovil is a Windows Forms application developed in C#. It appears to be a system for managing users, producers, and markets, likely for a local or mobile market service. The application's backend logic is separated into distinct layers for domain, application services, and infrastructure.
The data persistence mechanism is based on a set of CSV files located in the MercaditoMovil.Infrastructure/DataFiles/ directory. A Python script is provided to generate this initial dataset, including users, markets, producers, and product catalogs. The application interacts with these CSV files through a repository pattern, ensuring a clean separation between business logic and data access.
System Architecture
The project follows a layered architecture, promoting separation of concerns. The main layers are the Presentation (Windows Forms), Application, Domain, and Infrastructure.
- Presentation (MercaditoMovil): A Windows Forms application that serves as the user interface. It uses controllers to interact with the application layer.
- Application (MercaditoMovil.Application): Contains business logic, services (
AuthService), and validators (UserValidator). It orchestrates operations and depends on domain interfaces. - Domain (Mercadito.Domain): Defines the core entities (
User) and repository interfaces (IUserRepository), representing the heart of the application's model. - Infrastructure (MercaditoMovil.Infrastructure): Implements the data access logic defined by the domain interfaces. It includes a
CsvUserRepositoryfor reading from and writing to CSV files and a Python script for initial data generation.
Sources: MercaditoMovil/Program.cs, MercaditoMovil/Controllers/LoginController.cs, MercaditoMovil.Application/Service/AuthService.cs, Mercadito.Domain/Entities/User/User.cs, MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs
Architecture Dependency Flow
The following diagram illustrates the dependency flow between the different layers of the application.
This diagram shows how the UI interacts with the Application layer, which in turn uses interfaces from the Domain layer. The Infrastructure layer provides the concrete implementation for data access, reading from and writing to CSV files.
Sources: MercaditoMovil/Controllers/LoginController.cs:15, MercaditoMovil.Application/Service/AuthService.cs:16, Mercadito.Domain/Interfaces/Interface1.cs:7, MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs:12
Data Persistence
The application uses a set of CSV files as its database. These files are generated by a Python script and are accessed by the application through a repository pattern.
CSV Data Generation
A Python script, create_csvs.py, is responsible for creating the base CSV files for the application. It generates mock data for users, markets, producers, product catalogs, and producer-product relationships. The script writes all CSVs to the MercaditoMovil.Infrastructure/DataFiles/ directory.
The script generates the following primary CSV files:
users.csvmarkets.csvproducers.csvproduct_catalog.csvproducer_products.csv
Sources: MercaditoMovil.Infrastructure/Tools/Scripts/create_csvs.py:7-9, 21-27
Data Schemas
The relationships between the main data entities stored in the CSV files can be visualized as follows.
This ER diagram outlines the structure of the CSV files and their foreign key relationships. For example, each user is associated with a preferred market.
Sources: MercaditoMovil.Infrastructure/Tools/Scripts/create_csvs.py:168, 43, 252, 335, 379
CSV Repository Implementation
The CsvUserRepository class provides the concrete implementation for the IUserRepository interface. It handles reading from and writing to the users.csv file.
Key methods:
GetByUsername(string username): Performs a sequential scan of theusers.csvfile to find a user by their username. It usesTextFieldParserto correctly handle comma-delimited fields that may be enclosed in quotes.Add(User user, out string error): Appends a new user record to theusers.csvfile. It ensures the file and its header exist before writing.
// MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs:34-37
public User? GetByUsername(string username)
{
if (!File.Exists(_csvPath)) return null;
using var parser = new TextFieldParser(_csvPath, Encoding.UTF8);
The repository is designed to be robust, handling file creation, header validation, and I/O exceptions.
Sources: MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs
Core Features
User Authentication
The system provides functionality for user login and registration, managed by the AuthService.
Login Flow
The login process is initiated by the LoginController, which calls the AuthService. The service first validates the inputs, then retrieves the user from the CsvUserRepository and compares the password.
This sequence shows the collaboration between the layers during a login attempt.
Sources: MercaditoMovil/Controllers/LoginController.cs:22-27, MercaditoMovil.Application/Service/AuthService.cs:22-37, MercaditoMovil.Application/Validators/UserValidator.cs:11-20
Registration Flow
User registration also goes through the AuthService. It validates the new user's data, checks for duplicate usernames, and then uses the repository to persist the new user.
This sequence illustrates the steps for registering a new user, including validation and a check for existing users.
Sources: MercaditoMovil/Controllers/LoginController.cs:29-45, MercaditoMovil.Application/Service/AuthService.cs:42-63, MercaditoMovil.Application/Validators/UserValidator.cs:25-45
Domain Model
The Domain layer contains the core business entities and interfaces.
User Entity
The User class is a central entity in the domain. It represents an application user with all their associated properties. The constructor ensures that all string properties are non-null, defaulting to empty strings if null is passed.
| Property | Type | Description |
|---|---|---|
UserId | string | Unique identifier for the user. |
Username | string | User's login name. |
Password | string | User's password. |
FirstName | string | User's first name. |
LastName1 | string | User's first last name. |
LastName2 | string | User's second last name. |
NationalId | string | National identification number. |
Email | string | User's email address. |
Phone | string | User's phone number. |
ExactAddress | string | User's detailed address. |
Province | string | Province of residence. |
Canton | string | Canton of residence. |
District | string | District of residence. |
MarketId | string | ID of the user's preferred market. Defaults to MKT-000. |
Sources: Mercadito.Domain/Entities/User/User.cs:8-56
Repository and Service Interfaces
The design relies on interfaces to decouple the application and domain layers from the infrastructure.
This diagram shows that AuthService depends on the IUserRepository interface, not the concrete CsvUserRepository. This allows the data storage mechanism to be swapped without changing the application logic.
Sources: Mercadito.Domain/Interfaces/Interface1.cs, MercaditoMovil.Application/Features/UserManagement/IAuthService.cs, MercaditoMovil.Infrastructure/Repositories/CsvUserRepository.cs, MercaditoMovil.Application/Service/AuthService.cs
Conclusion
The MercaditoMovil project is a well-structured desktop application that uses a clean, layered architecture. Its reliance on a CSV-based data store, managed via a repository pattern and initialized with a dedicated Python script, is a key characteristic. The separation of concerns between UI, business logic, domain model, and data access makes the system maintainable and demonstrates a solid architectural foundation, even for a project with a simple persistence mechanism.