9.7 KiB
AGENTS_ARQUITECTURA.md
These rules complement AGENTS.md and are mandatory whenever the task changes project structure, C# architecture, database access, repositories, services, contracts, models, or application transactions.
Project folder rules
Use this base structure:
SIG.Web/
App_Code/
Infrastructure/
Sql/
Repositories/
Security/
Utilities/
Contracts/
Models/
Services/
Styles/
Scripts/
Metronic/
Site.master
Site.master.cs
Login.aspx
Login.aspx.cs
Inicio.aspx
Inicio.aspx.cs
BundleConfig.cs
Global.asax
Global.asax.cs
Web.config
Rules:
- The active application uses the ASP.NET Web Site runtime-compilation model.
- Shared C# source belongs in the exact special folder
App_Code. - Pages, master pages, controls, handlers, and
Global.asaxuseCodeFileor source compiled fromApp_Code; do not introduce newCodeBehinddependencies onSIG.Web.dll. - Keep third-party and external assemblies in
bin, but do not build or deploy a project assembly namedSIG.Web.dll. - Do not place database access directly inside
.aspx.cs,.ascx.cs, orSite.master.cs. - Database-related helpers go under
App_Code/Sqlor a clearly named SQL/data folder. - Business access goes through
ContractsandServices. - The active Web Site does not use explicit project compilation entries; C# files under
App_Codecompile automatically at runtime.
Contract rules
Contracts belong in /Contracts.
Current minimum contracts:
Contracts/IAuthContract.cs
Contracts/IUserSessionContract.cs
Contracts/IMenuContract.cs
Contracts/IMasterPageContract.cs
Suggested future contracts:
Contracts/IPermissionContract.cs
Contracts/INotificationContract.cs
Contracts/ICatalogSearchContract.cs
Contracts/IAuditContract.cs
Contracts/ICurrentCompanyContract.cs
Rules:
- Pages call contracts, not SQL classes.
- Master page calls contracts, not SQL classes.
- Login calls contracts, not SQL classes.
- Contracts must return models, DTOs, or result objects, not raw
DataTableunless migrating legacy code. - If legacy
DataTableis required, isolate it behind a contract and document why.
Repository ownership rules
Repository ownership is determined by the data domain and stored-procedure prefix, not by the page or feature that currently consumes the data.
- Procedures named
PA_Gral_*belong behind contracts and repositories underContracts/GeneralandRepositories/General. - General catalogs such as states, countries, municipalities, neighborhoods, and postal codes must not be placed in a security, registration, sales, or page-specific repository.
- A feature service such as public registration may orchestrate both its feature repository and
IGeneralCatalogRepository, but it must not move general catalog access into the feature repository. - Apply the same ownership rule to future procedure families:
PA_Sis_*belongs to security/system infrastructure,PA_Tra_*to procedures,PA_Vta_*to sales, and so on.
Database executor ownership rules
IDbExecutor,DbExecutor,StoredProcedureCommand,IDbCommand, and direct stored-procedure execution may only be used inside classes underRepositoriesor repository database infrastructure.- Services must not reference or receive
IDbExecutor, create database commands, execute readers, or call stored procedures directly. - A service that needs persisted data must depend on a repository contract. The concrete repository receives
IDbExecutorand owns parameter configuration and result mapping. - Keep the
DbExecutorimplementation underRepositories/Database; do not place it underServicesor expose it publicly throughAppServices.
Service rules
Services belong in /Services.
Current starter services may include:
Services/ContractRegistry.cs
Services/DummyAuthContract.cs
Services/UserSessionContract.cs
Services/DummyMenuContract.cs
Services/MasterPageContract.cs
Rules:
ContractRegistrymay be used as a simple manual dependency resolver for WebForms.- Do not introduce a complex dependency injection framework unless required.
- Services may depend on SQL helpers/repositories.
.aspx.csfiles should be thin and delegate work to services.- Keep dummy services separate from SQL-backed services.
- Services own application transactions when one business operation performs one or more repository mutations.
- Use
TransactionLogicinside ausingblock around the repository calls and invokeCommit()only after every required repository result succeeds. - Pages and repositories must not create, commit, roll back, or dispose application transactions.
- Repositories participate through the ambient
TransactionScope; connection strings used for transactional work must not setEnlist=false. - Select
TransactionScopeOption, isolation level, and timeout in the service according to the business operation. UseRequiresNeworSuppressonly when that behavior is intentional and documented by the call site. - Do not include slow external operations such as SMTP or HTTP calls inside a database transaction.
Model rules
Models belong in /Models.
Current starter models may include:
Models/AppUser.cs
Models/LoginResult.cs
Models/MenuItemModel.cs
Models/MasterLayoutModel.cs
Models/BreadcrumbItem.cs
Rules:
- Use models to move data between contracts and WebForms pages.
- Do not pass anonymous objects across layers.
- Do not expose SQL connection classes or
SqlDataReaderfrom services to pages. - Keep models simple and serializable when possible.
Database and SQL structure rules
All database connection structure must be centralized under App_Code/Sql or an equivalent SQL/data folder.
Current starter SQL structure:
App_Code/Sql/ConnectionNames.cs
App_Code/Sql/IConnectionStringProvider.cs
App_Code/Sql/WebConfigConnectionStringProvider.cs
App_Code/Sql/SqlConnectionFactory.cs
App_Code/Sql/SqlQueryExecutor.cs
Rules:
- Define connection names in one place.
- Read connection strings from
Web.config. - Do not hardcode connection strings in pages, master, controls, or services.
- Do not create
SqlConnectiondirectly in.aspx.cs. - Do not create
SqlCommanddirectly in.aspx.cs. - Use repositories or SQL executor classes behind contracts.
- All application database reads and writes must use stored procedures; inline SQL in C# is prohibited.
- Access to modules and catalogs is controlled by the menu and page-access layer. Reusable catalog stored procedures must not query
Sis_Usuarios, restrict execution byCveRol, or return access-denied messages for module authorization. - Keep
@CveUsuarioEjecutain catalog procedures for the required signature and auditing when applicable, not to authorize access to the module. - Do not invent or add authorization, role, user-client association, ownership, or business-prerequisite validations to any stored procedure unless the user explicitly requests that exact validation. The user prefers to add those validations manually.
- Mandatory: read and follow
AGENTS_STORED_PROCEDURES.mdfor naming, output parameters, TRY/CATCH, logging, transactions, and physical deletion. - Mandatory: read and follow
AGENTS_DATA_READER_MAPPING.mdfor object, list,DataTable, andJArrayresult mapping. - Mandatory: read and follow
AGENTS_DATABASE_ERROR_LOGGING.mdfor safe parameter logging and reproducible stored-procedure calls. - Mandatory: read and follow
AGENTS_PAGE_STRUCTURE.mdfor thePages/Modulo/location of all new WebForms pages. - Mandatory: read and follow
AGENTS_WEBFORMS_PARTIAL_POSTBACKS.mdfor the single master form, ScriptManager ownership, UpdatePanel usage, and partial-postback rules. - Mandatory: read and follow
AGENTS_JAVASCRIPT_INITIALIZATION.mdfor per-element initialization flags, global event guards, and idempotent control setup after partial postbacks. - Mandatory: read and follow
AGENTS_CATALOG_STRUCTURE.mdfor catalog titles, breadcrumbs, actions, filters, indicators, grids, quick-create modals, and detail pages. - Mandatory: read and follow
AGENTS_DOCUMENT_STORAGE.mdfor document folders, client access validation, protected file retrieval, and GIS file naming. - Keep stored procedure names centralized.
- Repositories must use
CommandType.StoredProcedureand parameterized inputs/outputs. - Never concatenate raw user input into SQL.
- The database default collation and general text columns must use
Modern_Spanish_CS_AS. - Columns named
Codigo, beginning withCodigo, or containing a real user login identifier such asNombreUsuario,UsuarioPortal, orAcum_PortalUsuariomust useModern_Spanish_CI_AS. AgenteUsuariois browser/device metadata, not a login identifier, and must use the generalModern_Spanish_CS_AScollation.- Do not use
Modern_Spanish_CS_AI.
Recommended Web.config connection string pattern:
<connectionStrings>
<add name="DefaultConnection" connectionString="..." providerName="System.Data.SqlClient" />
<add name="SecurityConnection" connectionString="..." providerName="System.Data.SqlClient" />
<add name="ReportingConnection" connectionString="..." providerName="System.Data.SqlClient" />
</connectionStrings>
Base page rules
Normal pages should inherit from a C# base page.
Preferred base class:
App_Code/Infrastructure/ClsPaginaBase.cs
If the starter currently has WebFormsPageBase.cs, either:
- rename it to
ClsPaginaBase.cs, or - keep
WebFormsPageBaseand update this AGENTS.md/project rules consistently.
Do not keep both base classes doing the same job.
Base page responsibilities:
- Validate authenticated session.
- Expose current user from
IUserSessionContract. - Provide helper methods for messages, redirects, and permissions.
- Avoid database access.
- Avoid page-specific business logic.