This repository provides a generic backend structure, independent of language or framework. The goal is to provide a well-organized starting point, making backend projects easier to evolve and maintain.
.env # Environment variables file (real)
.env.example # Example of environment variables file
config.example.yaml # Configuration template for reference
config.yaml # Real configuration file used by the project
main.xpto # Main entry point file
database/ # Migrations, seeds, and scripts
├── mongo/
│ ├── dump/ # MongoDB dumps
│ ├── indexes/ # Index creation scripts
│ ├── pipelines/ # Aggregation pipelines
│ └── views/ # MongoDB views
└── sql/
├── queries/ # SQL queries
└── views/ # SQL views
docker/ # Docker and Docker Compose configuration files
docs/ # Project documentation
├── api-collections/ # API collections (e.g., Postman, Insomnia)
├── architecture/ # Architecture diagrams and documentation
└── business-rules/ # Business rules
generic/ # Generic organization guide (src/core, src/common)
observability/ # Monitoring and metrics
├── grafana/
│ ├── dashboards/ # Configured dashboards
│ └── provisioning/ # Provisioning configurations
└── prometheus/ # Prometheus configurations
public/ # Public files
├── img/ # Project images
├── static/ # Static files
└── templates/
├── email/ # Email templates
└── reports/ # Report templates
scripts/ # Helper scripts (build, deploy, jobs)
src/ # Application source code
├── common/ # Shared code
│ ├── caching/ # Cache and Redis
│ ├── config/ # Configurations
│ ├── exceptions/ # Error handling
│ ├── helpers/ # Helper functions
│ ├── messaging/
│ │ ├── mail/ # Email sending
│ │ ├── nats/ # Messaging via NATS
│ │ └── rabbitmq/ # Messaging via RabbitMQ
│ └── middlewares/ # Shared middlewares
└── core/ # Main application logic
├── controllers/ # Controllers / Handlers
├── dtos/ # Data Transfer Objects
├── filters/ # Filters and validations
├── models/ # Models / Entities
├── repositories/ # Repositories / DAOs
├── seed/ # Seeds / initial data
└── shared/ # Shared code inside core
├── controllers/
├── models/
└── repositories/
tests/ # Automated tests
The main backend file serves as a startup guide containing the basic steps every backend needs:
// Load Configurations
// Setup Static Files (Optional)
// Setup Database
// Seed Initial Data
// Setup Middlewares
// Setup Controllers
// Start Application
Step Description:
- Load Configurations → Load configuration files (
config.yamland.env). - Setup Static Files → Configure public files, templates, or assets (optional).
- Setup Database → Connect to the database, apply migrations or initial seeds.
- Seed Initial Data → Populate initial data required by the system.
- Setup Middlewares → Configure logging, authentication, CORS, and other middlewares.
- Setup Controllers → Register routes, endpoints, or handlers.
- Start Application → Start the backend server.
- Clear separation between source code, configurations, and scripts
- Adaptable to any language or framework
- Facilitates maintenance, testing, and project evolution
-
Clone the repository:
git clone https://github.com/ortizdavid/backend-project-structure.git
-
Copy
.env.exampleto.envandconfig.example.yamltoconfig.yaml, adjusting them for your environment. -
Adapt the structure to your preferred language or framework.
-
Start developing your backend by organizing code, scripts, and configurations according to the structure.