# xarchgen
Generate Clean Architecture backend applications (FastAPI/DotNet) from PostgreSQL database schemas.
## Installation
```bash
# Install from PyPI (once published)
pip install xarchgen
# Or with uv
uv add xarchgen
# Or install from source
git clone <repository-url>
cd xarchgen-package
uv pip install -e .
```
## Quick Start
### Generate a FastAPI application
```bash
xarchgen create fastapi --database "postgresql://user:pass@localhost:5432/mydb"
```
### Generate a .NET Core application
```bash
xarchgen create dotnet --database "postgresql://user:pass@localhost:5432/mydb" --name MyApp
```
## Commands
### `xarchgen create`
Generate a new backend application from your PostgreSQL database schema.
**Arguments:**
- `framework`: Choose between `fastapi` or `dotnet`
**Options:**
- `--database`, `-d`: PostgreSQL connection string (required)
- `--output`, `-o`: Output directory (default: `./generated-app`)
- `--name`, `-n`: Application/Solution name (default: `GeneratedApp`)
- `--group-by`, `-g`: Table grouping strategy:
- `schema`: Group by database schema (default)
- `prefix`: Group by table name prefix (e.g., `user_accounts`, `user_profiles` → `User` group)
- `none`: Put all tables in a single "General" group
- `--zip`, `-z`: Generate a ZIP file instead of a directory
- `--tables`, `-t`: Include only specific tables (can be used multiple times)
- `--exclude`, `-e`: Exclude specific tables (can be used multiple times)
- `--verbose`, `-v`: Show detailed progress
**Examples:**
```bash
# Basic FastAPI generation
xarchgen create fastapi -d "postgresql://user:pass@localhost/db"
# .NET with custom name and output
xarchgen create dotnet -d "postgresql://..." -n MyProject -o ./my-project
# Group tables by prefix and create ZIP
xarchgen create fastapi -d "postgresql://..." --group-by prefix --zip
# Include only specific tables
xarchgen create fastapi -d "postgresql://..." -t users -t orders -t products
# Exclude certain tables
xarchgen create dotnet -d "postgresql://..." -e logs -e temp_data
```
### `xarchgen inspect`
Inspect your database schema without generating code.
```bash
xarchgen inspect --database "postgresql://user:pass@localhost:5432/mydb"
```
## Generated Architecture
### FastAPI Applications
```
src/
├── api/
│ ├── main.py # FastAPI app entry point
│ ├── dependencies.py # Dependency injection
│ ├── middleware/ # Custom middleware
│ └── v1/routers/ # API route handlers
├── application/
│ ├── dto/ # Data transfer objects
│ └── services/ # Business logic services
├── core/
│ ├── entities/ # Domain models
│ ├── interfaces/ # Repository contracts
│ └── exceptions/ # Custom exceptions
├── infrastructure/
│ ├── database/
│ │ ├── models/ # SQLAlchemy models
│ │ └── repositories/ # Repository implementations
│ └── config/ # Database configuration
├── common/
│ ├── logging.py # Logging configuration
│ ├── pagination.py # Pagination utilities
│ └── result.py # Result pattern
└── config/
├── settings.py # Application settings
└── main.py # Configuration entry point
```
### .NET Core Applications
```
src/
├── Core/
│ ├── Entities/ # Domain models
│ ├── Interfaces/ # Repository contracts
│ └── Common/ # Result pattern, errors
├── Application/
│ ├── Services/ # Business logic services
│ ├── Interfaces/ # Service contracts
│ ├── DTOs/ # Data transfer objects
│ ├── Validators/ # FluentValidation validators
│ └── Mappings/ # AutoMapper profiles
├── Infrastructure/
│ ├── Data/ # Repository implementations (Dapper)
│ └── Configuration/ # Database configuration
└── WebApi/
├── Controllers/ # API controllers
├── Middleware/ # Custom middleware
└── Configuration/ # App configuration
```
## Features
- **Clean Architecture**: Follows Clean Architecture principles with proper layer separation
- **Database-First**: Generates code from existing PostgreSQL database schemas
- **Table Grouping**: Organize tables into logical groups (by schema, prefix, or manual)
- **Type Safety**: Proper type mappings from PostgreSQL to target language
- **Modern Patterns**:
- Result pattern for error handling
- Repository pattern for data access
- Dependency injection
- Structured logging
- API versioning
- **Production Ready**:
- Error handling middleware
- Request correlation IDs
- Swagger/OpenAPI documentation
- Health checks
- Docker support
- **Extensible**: Easy to modify generated templates
## Connection String Formats
PostgreSQL URL format (recommended):
```
postgresql://username:password@host:port/database
```
Alternative formats:
```
postgres://username:password@host:port/database
Host=localhost;Port=5432;Database=mydb;Username=user;Password=pass
```
## Generated Application Setup
### FastAPI
```bash
cd generated-app
cp .env.example .env # Configure your database connection
uv sync # Install dependencies
uv run alembic upgrade head # Run migrations
uv run uvicorn src.api.main:app --reload # Start server
```
Access API documentation at: `http://localhost:8000/docs`
### .NET Core
```bash
cd generated-app
# Update appsettings.json with your connection string
dotnet restore # Restore dependencies
dotnet build # Build solution
dotnet run --project src/WebApi # Start server
```
Access API documentation at: `https://localhost:5001/swagger`
## Development
```bash
git clone <repository-url>
cd xarchgen-package
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e ".[dev]"
```
Run tests:
```bash
pytest
```
Format code:
```bash
black xarchgen/
ruff check xarchgen/
```
## License
MIT License - see LICENSE file for details.
## Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Run the test suite
6. Submit a pull request
## Support
- GitHub Issues: [Report bugs or request features](https://github.com/Xcdify/DotNetCoreBackendGenerator/issues)
- Documentation: [Full documentation](https://github.com/Xcdify/DotNetCoreBackendGenerator#readme)
Raw data
{
"_id": null,
"home_page": null,
"name": "xarchgen",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "code-generator, fastapi, dotnet, clean-architecture, postgresql, backend",
"author": null,
"author_email": "Xcdify <hd@xcdify.com>",
"download_url": "https://files.pythonhosted.org/packages/e3/e5/bf0e20c613faed9a4e8e2c7ed0329e31d9d86511a4682571bffe0cd05850/xarchgen-0.1.1.tar.gz",
"platform": null,
"description": "# xarchgen\n\nGenerate Clean Architecture backend applications (FastAPI/DotNet) from PostgreSQL database schemas.\n\n## Installation\n\n```bash\n# Install from PyPI (once published)\npip install xarchgen\n\n# Or with uv\nuv add xarchgen\n\n# Or install from source\ngit clone <repository-url>\ncd xarchgen-package\nuv pip install -e .\n```\n\n## Quick Start\n\n### Generate a FastAPI application\n\n```bash\nxarchgen create fastapi --database \"postgresql://user:pass@localhost:5432/mydb\"\n```\n\n### Generate a .NET Core application\n\n```bash\nxarchgen create dotnet --database \"postgresql://user:pass@localhost:5432/mydb\" --name MyApp\n```\n\n## Commands\n\n### `xarchgen create`\n\nGenerate a new backend application from your PostgreSQL database schema.\n\n**Arguments:**\n- `framework`: Choose between `fastapi` or `dotnet`\n\n**Options:**\n- `--database`, `-d`: PostgreSQL connection string (required)\n- `--output`, `-o`: Output directory (default: `./generated-app`)\n- `--name`, `-n`: Application/Solution name (default: `GeneratedApp`)\n- `--group-by`, `-g`: Table grouping strategy:\n - `schema`: Group by database schema (default)\n - `prefix`: Group by table name prefix (e.g., `user_accounts`, `user_profiles` \u2192 `User` group)\n - `none`: Put all tables in a single \"General\" group\n- `--zip`, `-z`: Generate a ZIP file instead of a directory\n- `--tables`, `-t`: Include only specific tables (can be used multiple times)\n- `--exclude`, `-e`: Exclude specific tables (can be used multiple times)\n- `--verbose`, `-v`: Show detailed progress\n\n**Examples:**\n\n```bash\n# Basic FastAPI generation\nxarchgen create fastapi -d \"postgresql://user:pass@localhost/db\"\n\n# .NET with custom name and output\nxarchgen create dotnet -d \"postgresql://...\" -n MyProject -o ./my-project\n\n# Group tables by prefix and create ZIP\nxarchgen create fastapi -d \"postgresql://...\" --group-by prefix --zip\n\n# Include only specific tables\nxarchgen create fastapi -d \"postgresql://...\" -t users -t orders -t products\n\n# Exclude certain tables\nxarchgen create dotnet -d \"postgresql://...\" -e logs -e temp_data\n```\n\n### `xarchgen inspect`\n\nInspect your database schema without generating code.\n\n```bash\nxarchgen inspect --database \"postgresql://user:pass@localhost:5432/mydb\"\n```\n\n## Generated Architecture\n\n### FastAPI Applications\n\n```\nsrc/\n\u251c\u2500\u2500 api/\n\u2502 \u251c\u2500\u2500 main.py # FastAPI app entry point\n\u2502 \u251c\u2500\u2500 dependencies.py # Dependency injection\n\u2502 \u251c\u2500\u2500 middleware/ # Custom middleware\n\u2502 \u2514\u2500\u2500 v1/routers/ # API route handlers\n\u251c\u2500\u2500 application/\n\u2502 \u251c\u2500\u2500 dto/ # Data transfer objects\n\u2502 \u2514\u2500\u2500 services/ # Business logic services\n\u251c\u2500\u2500 core/\n\u2502 \u251c\u2500\u2500 entities/ # Domain models\n\u2502 \u251c\u2500\u2500 interfaces/ # Repository contracts\n\u2502 \u2514\u2500\u2500 exceptions/ # Custom exceptions\n\u251c\u2500\u2500 infrastructure/\n\u2502 \u251c\u2500\u2500 database/\n\u2502 \u2502 \u251c\u2500\u2500 models/ # SQLAlchemy models\n\u2502 \u2502 \u2514\u2500\u2500 repositories/ # Repository implementations\n\u2502 \u2514\u2500\u2500 config/ # Database configuration\n\u251c\u2500\u2500 common/\n\u2502 \u251c\u2500\u2500 logging.py # Logging configuration\n\u2502 \u251c\u2500\u2500 pagination.py # Pagination utilities\n\u2502 \u2514\u2500\u2500 result.py # Result pattern\n\u2514\u2500\u2500 config/\n \u251c\u2500\u2500 settings.py # Application settings\n \u2514\u2500\u2500 main.py # Configuration entry point\n```\n\n### .NET Core Applications\n\n```\nsrc/\n\u251c\u2500\u2500 Core/\n\u2502 \u251c\u2500\u2500 Entities/ # Domain models\n\u2502 \u251c\u2500\u2500 Interfaces/ # Repository contracts\n\u2502 \u2514\u2500\u2500 Common/ # Result pattern, errors\n\u251c\u2500\u2500 Application/\n\u2502 \u251c\u2500\u2500 Services/ # Business logic services\n\u2502 \u251c\u2500\u2500 Interfaces/ # Service contracts\n\u2502 \u251c\u2500\u2500 DTOs/ # Data transfer objects\n\u2502 \u251c\u2500\u2500 Validators/ # FluentValidation validators\n\u2502 \u2514\u2500\u2500 Mappings/ # AutoMapper profiles\n\u251c\u2500\u2500 Infrastructure/\n\u2502 \u251c\u2500\u2500 Data/ # Repository implementations (Dapper)\n\u2502 \u2514\u2500\u2500 Configuration/ # Database configuration\n\u2514\u2500\u2500 WebApi/\n \u251c\u2500\u2500 Controllers/ # API controllers\n \u251c\u2500\u2500 Middleware/ # Custom middleware\n \u2514\u2500\u2500 Configuration/ # App configuration\n```\n\n## Features\n\n- **Clean Architecture**: Follows Clean Architecture principles with proper layer separation\n- **Database-First**: Generates code from existing PostgreSQL database schemas\n- **Table Grouping**: Organize tables into logical groups (by schema, prefix, or manual)\n- **Type Safety**: Proper type mappings from PostgreSQL to target language\n- **Modern Patterns**: \n - Result pattern for error handling\n - Repository pattern for data access\n - Dependency injection\n - Structured logging\n - API versioning\n- **Production Ready**: \n - Error handling middleware\n - Request correlation IDs\n - Swagger/OpenAPI documentation\n - Health checks\n - Docker support\n- **Extensible**: Easy to modify generated templates\n\n## Connection String Formats\n\nPostgreSQL URL format (recommended):\n```\npostgresql://username:password@host:port/database\n```\n\nAlternative formats:\n```\npostgres://username:password@host:port/database\nHost=localhost;Port=5432;Database=mydb;Username=user;Password=pass\n```\n\n## Generated Application Setup\n\n### FastAPI\n\n```bash\ncd generated-app\ncp .env.example .env # Configure your database connection\nuv sync # Install dependencies\nuv run alembic upgrade head # Run migrations\nuv run uvicorn src.api.main:app --reload # Start server\n```\n\nAccess API documentation at: `http://localhost:8000/docs`\n\n### .NET Core\n\n```bash\ncd generated-app\n# Update appsettings.json with your connection string\ndotnet restore # Restore dependencies\ndotnet build # Build solution\ndotnet run --project src/WebApi # Start server\n```\n\nAccess API documentation at: `https://localhost:5001/swagger`\n\n## Development\n\n```bash\ngit clone <repository-url>\ncd xarchgen-package\nuv venv\nsource .venv/bin/activate # On Windows: .venv\\Scripts\\activate\nuv pip install -e \".[dev]\"\n```\n\nRun tests:\n```bash\npytest\n```\n\nFormat code:\n```bash\nblack xarchgen/\nruff check xarchgen/\n```\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests\n5. Run the test suite\n6. Submit a pull request\n\n## Support\n\n- GitHub Issues: [Report bugs or request features](https://github.com/Xcdify/DotNetCoreBackendGenerator/issues)\n- Documentation: [Full documentation](https://github.com/Xcdify/DotNetCoreBackendGenerator#readme)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Generate Clean Architecture backend applications (FastAPI/DotNet) from PostgreSQL schemas",
"version": "0.1.1",
"project_urls": {
"Documentation": "https://github.com/xcdify/xarchgen#readme",
"Homepage": "https://github.com/xcdify/xarchgen",
"Issues": "https://github.com/xcdify/xarchgen/issues",
"Repository": "https://github.com/xcdify/xarchgen"
},
"split_keywords": [
"code-generator",
" fastapi",
" dotnet",
" clean-architecture",
" postgresql",
" backend"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "a563e9ee41a8907c4c647e33da4fcf2a909b2e565037df134c3ce8686a9ef048",
"md5": "cc6f8711b662d7ef7129d1cc49ef158d",
"sha256": "34cfd0da232af2085364b94bfcc20d0fcd0f0aeab4130f080296de7f5666d3b9"
},
"downloads": -1,
"filename": "xarchgen-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cc6f8711b662d7ef7129d1cc49ef158d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 95843,
"upload_time": "2025-08-15T12:57:05",
"upload_time_iso_8601": "2025-08-15T12:57:05.460357Z",
"url": "https://files.pythonhosted.org/packages/a5/63/e9ee41a8907c4c647e33da4fcf2a909b2e565037df134c3ce8686a9ef048/xarchgen-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "e3e5bf0e20c613faed9a4e8e2c7ed0329e31d9d86511a4682571bffe0cd05850",
"md5": "0d9ac945f3029f131d50d60c62251e9f",
"sha256": "33bba50586869e6a4f8acbcafaf234f2e000dbb39c035af6c505e13108e17ded"
},
"downloads": -1,
"filename": "xarchgen-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "0d9ac945f3029f131d50d60c62251e9f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 70503,
"upload_time": "2025-08-15T12:57:06",
"upload_time_iso_8601": "2025-08-15T12:57:06.527870Z",
"url": "https://files.pythonhosted.org/packages/e3/e5/bf0e20c613faed9a4e8e2c7ed0329e31d9d86511a4682571bffe0cd05850/xarchgen-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-15 12:57:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "xcdify",
"github_project": "xarchgen#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "xarchgen"
}