├── .env ├── Makefile ├── .env.example ├── .gitignore ├── config.yaml ├── docker ├── Dockerfile └── .dockerignore ├── scripts ├── db-dump.sh ├── add-deps.sh ├── db-restore.sh ├── generate-certs.sh └── run-migrations.sh ├── config.example.yaml ├── docs ├── architecture │ └── README.md ├── api-collections │ ├── Postman.json │ └── Insomnia.yaml └── business-rules │ └── README.md ├── public └── templates │ └── index.html ├── observability ├── grafana │ └── grafana.yaml └── prometheus │ └── pronetheus.yaml ├── main.xpto └── README.md /.env: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/db-dump.sh: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config.example.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docker/.dockerignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/add-deps.sh: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/db-restore.sh: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/architecture/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/templates/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/generate-certs.sh: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/run-migrations.sh: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/api-collections/Postman.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/business-rules/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/api-collections/Insomnia.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /observability/grafana/grafana.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /observability/prometheus/pronetheus.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /main.xpto: -------------------------------------------------------------------------------- 1 | // Load Configurations 2 | 3 | 4 | // Setup Static Files (Optional) 5 | 6 | 7 | // Setup Database 8 | 9 | 10 | // Seeed Initial Data 11 | 12 | 13 | // Setup Middlewares 14 | 15 | 16 | // Setup Controllers 17 | 18 | 19 | // Start Application -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Backend Project Structure 2 | 3 | This repository provides a **generic backend structure**, independent of language or framework. 4 | The goal is to provide a **well-organized starting point**, making backend projects easier to evolve and maintain. 5 | 6 | --- 7 | 8 | ## Project Structure 9 | 10 | ``` 11 | .env # Environment variables file (real) 12 | .env.example # Example of environment variables file 13 | config.example.yaml # Configuration template for reference 14 | config.yaml # Real configuration file used by the project 15 | main.xpto # Main entry point file 16 | database/ # Migrations, seeds, and scripts 17 | ├── mongo/ 18 | │ ├── dump/ # MongoDB dumps 19 | │ ├── indexes/ # Index creation scripts 20 | │ ├── pipelines/ # Aggregation pipelines 21 | │ └── views/ # MongoDB views 22 | └── sql/ 23 | ├── queries/ # SQL queries 24 | └── views/ # SQL views 25 | docker/ # Docker and Docker Compose configuration files 26 | docs/ # Project documentation 27 | ├── api-collections/ # API collections (e.g., Postman, Insomnia) 28 | ├── architecture/ # Architecture diagrams and documentation 29 | └── business-rules/ # Business rules 30 | generic/ # Generic organization guide (src/core, src/common) 31 | observability/ # Monitoring and metrics 32 | ├── grafana/ 33 | │ ├── dashboards/ # Configured dashboards 34 | │ └── provisioning/ # Provisioning configurations 35 | └── prometheus/ # Prometheus configurations 36 | public/ # Public files 37 | ├── img/ # Project images 38 | ├── static/ # Static files 39 | └── templates/ 40 | ├── email/ # Email templates 41 | └── reports/ # Report templates 42 | scripts/ # Helper scripts (build, deploy, jobs) 43 | src/ # Application source code 44 | ├── common/ # Shared code 45 | │ ├── caching/ # Cache and Redis 46 | │ ├── config/ # Configurations 47 | │ ├── exceptions/ # Error handling 48 | │ ├── helpers/ # Helper functions 49 | │ ├── messaging/ 50 | │ │ ├── mail/ # Email sending 51 | │ │ ├── nats/ # Messaging via NATS 52 | │ │ └── rabbitmq/ # Messaging via RabbitMQ 53 | │ └── middlewares/ # Shared middlewares 54 | └── core/ # Main application logic 55 | ├── controllers/ # Controllers / Handlers 56 | ├── dtos/ # Data Transfer Objects 57 | ├── filters/ # Filters and validations 58 | ├── models/ # Models / Entities 59 | ├── repositories/ # Repositories / DAOs 60 | ├── seed/ # Seeds / initial data 61 | └── shared/ # Shared code inside core 62 | ├── controllers/ 63 | ├── models/ 64 | └── repositories/ 65 | tests/ # Automated tests 66 | ``` 67 | 68 | --- 69 | 70 | ### Entry Point (`main.xpto`) 71 | 72 | The main backend file serves as a **startup guide** containing the basic steps every backend needs: 73 | 74 | ```text 75 | // Load Configurations 76 | // Setup Static Files (Optional) 77 | // Setup Database 78 | // Seed Initial Data 79 | // Setup Middlewares 80 | // Setup Controllers 81 | // Start Application 82 | ``` 83 | 84 | **Step Description:** 85 | 86 | 1. **Load Configurations** → Load configuration files (`config.yaml` and `.env`). 87 | 2. **Setup Static Files** → Configure public files, templates, or assets (optional). 88 | 3. **Setup Database** → Connect to the database, apply migrations or initial seeds. 89 | 4. **Seed Initial Data** → Populate initial data required by the system. 90 | 5. **Setup Middlewares** → Configure logging, authentication, CORS, and other middlewares. 91 | 6. **Setup Controllers** → Register routes, endpoints, or handlers. 92 | 7. **Start Application** → Start the backend server. 93 | 94 | --- 95 | 96 | ### Advantages 97 | 98 | * Clear separation between **source code**, **configurations**, and **scripts** 99 | * Adaptable to **any language or framework** 100 | * Facilitates **maintenance**, **testing**, and **project evolution** 101 | 102 | --- 103 | 104 | ### How to Use 105 | 106 | 1. Clone the repository: 107 | 108 | ```bash 109 | git clone https://github.com/ortizdavid/backend-project-structure.git 110 | ``` 111 | 2. Copy `.env.example` to `.env` and `config.example.yaml` to `config.yaml`, adjusting them for your environment. 112 | 3. Adapt the structure to your preferred language or framework. 113 | 4. Start developing your backend by organizing code, scripts, and configurations according to the structure. 114 | 115 | --------------------------------------------------------------------------------