Skip to content

About

No description, website, or topics provided.

Resources

Stars

87 stars

Watchers

0 watching

Forks

Repository files navigation

Backend Project Structure

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.


Project Structure

.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

Entry Point (main.xpto)

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:

  1. Load Configurations → Load configuration files (config.yaml and .env).
  2. Setup Static Files → Configure public files, templates, or assets (optional).
  3. Setup Database → Connect to the database, apply migrations or initial seeds.
  4. Seed Initial Data → Populate initial data required by the system.
  5. Setup Middlewares → Configure logging, authentication, CORS, and other middlewares.
  6. Setup Controllers → Register routes, endpoints, or handlers.
  7. Start Application → Start the backend server.

Advantages

  • Clear separation between source code, configurations, and scripts
  • Adaptable to any language or framework
  • Facilitates maintenance, testing, and project evolution

How to Use

  1. Clone the repository:

    git clone https://github.com/ortizdavid/backend-project-structure.git
  2. Copy .env.example to .env and config.example.yaml to config.yaml, adjusting them for your environment.

  3. Adapt the structure to your preferred language or framework.

  4. Start developing your backend by organizing code, scripts, and configurations according to the structure.

About

No description, website, or topics provided.

Resources

Stars

87 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors